8000 switch `Collection::make()` for `new Collection()` (#53733) · tibbsa/laravel-framework@2176406 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2176406

Browse files
authored
switch Collection::make() for new Collection() (laravel#53733)
`make()` is essentially just a static alias to the constructor. it performs no logic. removing the middleman to simplify the call stack.
1 parent 7b56029 commit 2176406

File tree

24 files changed

+36
-36
lines changed

24 files changed

+36
-36
lines changed

src/Illuminate/Broadcasting/Broadcasters/PusherBroadcaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function broadcast(array $channels, $event, array $payload = [])
154154

155155
$parameters = $socket !== null ? ['socket_id' => $socket] : [];
156156

157-
$channels = Collection::make($this->formatChannels($channels));
157+
$channels = new Collection($this->formatChannels($channels));
158158

159159
try {
160160
$channels->chunk(100)->each(function ($channels) use ($event, $payload, $parameters) {

src/Illuminate/Collections/Arr.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ public static function join($array, $glue, $finalGlue = '')
489489
*/
490490
public static function keyBy($array, $keyBy)
491491
{
492-
return Collection::make($array)->keyBy($keyBy)->all();
492+
return (new Collection($array))->keyBy($keyBy)->all();
493493
}
494494

495495
/**
@@ -816,7 +816,7 @@ public static function shuffle($array)
816816
*/
817817
public static function sort($array, $callback = null)
818818
{
819-
return Collection::make($array)->sortBy($callback)->all();
819+
return (new Collection($array))->sortBy($callback)->all();
820820
}
821821

822822
/**
@@ -828,7 +828,7 @@ public static function sort($array, $callback = null)
828828
*/
829829
public static function sortDesc($array, $callback = null)
830830
{
831-
return Collection::make($array)->sortByDesc($callback)->all();
831+
return (new Collection($array))->sortByDesc($callback)->all();
832832
}
833833

834834
/**

src/Illuminate/Collections/LazyCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ public function zip($items)
17521752
$iterables = func_get_args();
17531753

17541754
return new static(function () use ($iterables) {
1755-
$iterators = Collection::make($iterables)->map(function ($iterable) {
1755+
$iterators = (new 10000 Collection($iterables))->map(function ($iterable) {
17561756
return $this->makeIterator($iterable);
17571757
})->prepend($this->getIterator());
17581758

src/Illuminate/Collections/Traits/EnumeratesValues.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public function pipeInto($class)
794794
*/
795795
public function pipeThrough($callbacks)
796796
{
797-
return Collection::make($callbacks)->reduce(
797+
return (new Collection($callbacks))->reduce(
798798
fn ($carry, $callback) => $callback($carry),
799799
$this,
800800
);

src/Illuminate/Database/Concerns/BuildsQueries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function chunk($count, callable $callback)
8080
*/
8181
public function chunkMap(callable $callback, $count = 1000)
8282
{
83-
$collection = Collection::make();
83+
$collection = new Collection;
8484

8585
$this->chunk($count, function ($items) use ($collection, $callback) {
8686
$items->each(function ($item) use ($collection, $callback) {

src/Illuminate/Database/Console/Migrations/StatusCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function handle()
9999
*/
100100
protected function getStatusFor(array $ran, array $batches)
101101
{
102-
return Collection::make($this->getAllMigrationFiles())
102+
return (new Collection($this->getAllMigrationFiles()))
103103
->map(function ($migration) use ($ran, $batches) {
104104
$migrationName = $this->migrator->getMigrationName($migration);
105105

src/Illuminate/Database/Eloquent/Relations/MorphTo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function __construct(Builder $query, Model $parent, $foreignKey, $ownerKe
9696
#[\Override]
9797
public function addEagerConstraints(array $models)
9898
{
99-
$this->buildDictionary($this->models = Collection::make($models));
99+
$this->buildDictionary($this->models = new Collection($models));
100100
}
101101

102102
/**

src/Illuminate/Database/Migrations/Migrator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function run($paths = [], array $options = [])
134134
*/
135135
protected function pendingMigrations($files, $ran)
136136
{
137-
return Collection::make($files)
137+
return (new Collection($files))
138138
->reject(fn ($file) => in_array($this->getMigrationName($file), $ran))
139139
->values()
140140
->all();
@@ -536,7 +536,7 @@ protected function getMigrationClass(string $migrationName): string
536536
*/
537537
public function getMigrationFiles($paths)
538538
{
539-
return Collection::make($paths)
539+
return (new Collection($paths))
540540
->flatMap(fn ($path) => str_ends_with($path, '.php') ? [$path] : $this->files->glob($path.'/*_*.php'))
541541
->filter()
542542
->values()

src/Illuminate/Database/Query/Builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2872,7 17AE +2872,7 @@ public function reorder($column = null, $direction = 'asc')
28722872
*/
28732873
protected function removeExistingOrdersFor($column)
28742874
{
2875-
return Collection::make($this->orders)
2875+
return (new Collection($this->orders))
28762876
->reject(function ($order) use ($column) {
28772877
return isset($order['column'])
28782878
? $order['column'] === $column : false;

src/Illuminate/Foundation/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ public function registered($callback)
836836
*/
837837
public function registerConfiguredProviders()
838838
{
839-
$providers = Collection::make($this->make('config')->get('app.providers'))
839+
$providers = (new Collection($this->make('config')->get('app.providers')))
840840
->partition(fn ($provider) => str_starts_with($provider, 'Illuminate\\'));
841841

842842
$providers->splice(1, 0, [$this->make(PackageManifest::class)->providers()]);

src/Illuminate/Foundation/Console/DocsCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,10 @@ protected function openViaBuiltInStrategy($url)
381381
return;
382382
}
383383

384-
$binary = Collection::make(match ($this->systemOsFamily) {
384+
$binary = (new Collection(match ($this->systemOsFamily) {
385385
'Darwin' => ['open'],
386386
'Linux' => ['xdg-open', 'wslview'],
387-
})->first(fn ($binary) => (new ExecutableFinder)->find($binary) !== null);
387+
}))->first(fn ($binary) => (new ExecutableFinder)->find($binary) !== null);
388388

389389
if ($binary === null) {
390390
$this->components->warn('Unable to open the URL on your system. You will need to open it yourself or create a custom opener for your system.');
@@ -475,7 +475,7 @@ protected function version()
475475
*/
476476
protected function searchQuery()
477477
{
478-
return Collection::make($_SERVER['argv'])->skip(3)->implode(' ');
478+
return (new Collection($_SERVER['argv']))->skip(3)->implode(' ');
479479
}
480480

481481
/**

src/Illuminate/Foundation/Exceptions/Renderer/Mappers/BladeMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function map(FlattenException $exception)
8787
$exception = $previous;
8888
}
8989

90-
$trace = Collection::make($exception->getTrace())
90+
$trace = (new Collection($exception->getTrace()))
9191
->map(function ($frame) {
9292
if ($originalPath = $this->findCompiledView((string) Arr::get($frame, 'file', ''))) {
9393
$frame['file'] = $originalPath;

src/Illuminate/Foundation/Inspiring.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function quote()
6767
*/
6868
public static function quotes()
6969
{
70-
return Collection::make([
70+
return new Collection([
7171
'Act only according to that maxim whereby you can, at the same time, will that it should become a universal law. - Immanuel Kant',
7272
'An unexamined life is not worth living. - Socrates',
7373
'Be present above all else. - Naval Ravikant',

src/Illuminate/Foundation/Vite.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public function __invoke($entrypoints, $buildDirectory = null)
405405
]);
406406

407407
foreach ($manifest[$import]['css'] ?? [] as $css) {
408-
$partialManifest = Collection::make($manifest)->where('file', $css);
408+
$partialManifest = (new Collection($manifest))->where('file', $css);
409409

410410
$preloads->push([
411411
$partialManifest->keys()->first(),
@@ -431,7 +431,7 @@ public function __invoke($entrypoints, $buildDirectory = null)
431431
));
432432

433433
foreach ($chunk['css'] ?? [] as $css) {
434-
$partialManifest = Collection::make($manifest)->where('file', $css);
434+
$partialManifest = (new Collection($manifest))->where('file', $css);
435435

436436
$preloads->push([
437437
$partialManifest->keys()->first(),
@@ -624,7 +624,7 @@ protected function makePreloadTagForChunk($src, $url, $chunk, $manifest)
624624
}
625625

626626
$this->preloadedAssets[$url] = $this->parseAttributes(
627-
Collection::make($attributes)->forget('href')->all()
627+
(new Collection($attributes))->forget('href')->all()
628628
);
629629

630630
return '<link '.implode(' ', $this->parseAttributes($attributes)).' />';
@@ -811,7 +811,7 @@ protected function isCssPath($path)
811811
*/
812812
protected function parseAttributes($attributes)
813813
{
814-
return Collection::make($attributes)
814+
return (new Collection($attributes))
815815
->reject(fn ($value, $key) => in_array($value, [false, null], true))
816816
->flatMap(fn ($value, $key) => $value === true ? [$key] : [$key => $value])
817817
->map(fn ($value, $key) => is_int($key) ? $value : $key.'="'.$value.'"')

src/Illuminate/Http/Client/Response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function object()
105105
*/
106106
public function collect($key = null)
107107
{
108-
return Collection::make($this->json($key));
108+
return new Collection($this->json($key));
109109
}
110110

111111
/**

src/Illuminate/Http/Concerns/CanBePrecognitive.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function filterPrecognitiveRules($rules)
1818
return $rules;
1919
}
2020

21-
return Collection::make($rules)
21+
return (new Collection($rules))
2222
->only(explode(',', $this->header('Precognition-Validate-Only')))
2323
->all();
2424
}

src/Illuminate/Http/Middleware/AddLinkHeadersForPreloadedAssets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function handle($request, $next)
1919
{
2020
return tap($next($request), function ($response) {
2121
if ($response instanceof Response && Vite::preloadedAssets() !== []) {
22-
$response->header('Link', Collection::make(Vite::preloadedAssets())
22+
$response->header('Link', (new Collection(Vite::preloadedAssets()))
2323
->map(fn ($attributes, $url) => "<{$url}>; ".implode('; ', $attributes))
2424
->join(', '), false);
2525
}

src/Illuminate/Mail/Mailable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ private function hasEnvelopeAttachment($attachment, $options = [])
10461046

10471047
$attachments = $this->attachments();
10481048

1049-
return Collection::make(is_object($attachments) ? [$attachments] : $attachments)
1049+
return (new Collection(is_object($attachments) ? [$attachments] : $attachments))
10501050
->map(fn ($attached) => $attached instanceof Attachable ? $attached->toMailAttachment() : $attached)
10511051
->contains(fn ($attached) => $attached->isEquivalent($attachment, $options));
10521052
}
@@ -1766,7 +1766,7 @@ private function ensureAttachmentsAreHydrated()
17661766

17671767
$attachments = $this->attachments();
17681768

1769-
Collection::make(is_object($attachments) ? [$attachments] : $attachments)
1769+
(new Collection(is_object($attachments) ? [$attachments] : $attachments))
17701770
->each(function ($attachment) {
17711771
$this->attach($attachment);
17721772
});

src/Illuminate/Pagination/CursorPaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct($items, $perPage, $cursor = null, array $options = [
6464
*/
6565
protected function setItems($items)
6666
{
67-
$this->items = $items instanceof Collection ? $items : Collection::make($items);
67+
$this->items = $items instanceof Collection ? $items : new Collection($items);
6868

6969
$this->hasMore = $this->items->count() > $this->perPage;
7070

src/Illuminate/Pagination/LengthAwarePaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function __construct($items, $total, $perPage, $currentPage = null, array
6262
$this->lastPage = max((int) ceil($total / $perPage), 1);
6363
$this->path = $this->path !== '/' ? rtrim($this->path, '/') : $this->path;
6464
$this->currentPage = $this->setCurrentPage($currentPage, $this->pageName);
65-
$this->items = $items instanceof Collection ? $items : Collection::make($items);
65+
$this->items = $items instanceof Collection ? $items : new Collection($items);
6666
}
6767

6868
/**

src/Illuminate/Pagination/Paginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ protected function setCurrentPage($currentPage)
7777
*/
7878
protected function setItems($items)
7979
{
80-
$this->items = $items instanceof Collection ? $items : Collection::make($items);
80+
$this->items = $items instanceof Collection ? $items : new Collection($items);
8181

8282
$this->hasMore = $this->items->count() > $this->perPage;
8383

src/Illuminate/Support/Testing/Fakes/QueueFake.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct($app, $jobsToFake = [], $queue = null)
6363
parent::__construct($app);
6464

6565
$this->jobsToFake = Collection::wrap($jobsToFake);
66-
$this->jobsToBeQueued = Collection::make();
66+
$this->jobsToBeQueued = new Collection;
6767
$this->queue = $queue;
6868
}
6969

src/Illuminate/Testing/Fluent/Concerns/Matching.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function where(string $key, $expected): self
2626

2727
if ($expected instanceof Closure) {
2828
PHPUnit::assertTrue(
29-
$expected(is_array($actual) ? Collection::make($actual) : $actual),
29+
$expected(is_array($actual) ? new Collection($actual) : $actual),
3030
sprintf('Property [%s] was marked as invalid using a closure.', $this->dotPath($key))
3131
);
3232

@@ -64,7 +64,7 @@ public function whereNot(string $key, $expected): self
6464

6565
if ($expected instanceof Closure) {
6666
PHPUnit::assertFalse(
67-
$expected(is_array($actual) ? Collection::make($actual) : $actual),
67+
$expected(is_array($actual) ? new Collection($actual) : $actual),
6868
sprintf('Property [%s] was marked as invalid using a closure.', $this->dotPath($key))
6969
);
7070

@@ -157,11 +157,11 @@ public function whereAllType(array $bindings): self
157157
*/
158158
public function whereContains(string $key, $expected)
159159
{
160-
$actual = Collection::make(
160+
$actual = new Collection(
161161
$this->prop($key) ?? $this->prop()
162162
);
163163

164-
$missing = Collection::make($expected)
164+
$missing = (new Collection($expected))
165165
->map(fn ($search) => enum_value($search))
166166
->reject(function ($search) use ($key, $actual) {
167167
if ($actual->containsStrict($key, $search)) {

src/Illuminate/Testing/TestResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ public function json($key = null)
10831083
*/
10841084
public function collect($key = null)
10851085
{
1086-
return Collection::make($this->json($key));
1086+
return new Collection($this->json($key));
10871087
}
10881088

10891089
/**

0 commit comments

Comments
 (0)
0