Skip to content

Commit eac931d

Browse files
prefer new Collection over collect() (#55059)
this is a continuation of #53563 Co-authored-by: Taylor Otwell <[email protected]>
1 parent e673658 commit eac931d

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/Illuminate/Foundation/Console/AboutCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ protected function gatherApplicationInformation()
230230
*/
231231
protected function determineStoragePathLinkStatus(callable $formatStorageLinkedStatus): array
232232
{
233-
return collect(config('filesystems.links', []))
233+
return (new Collection(config('filesystems.links', [])))
234234
->mapWithKeys(function ($target, $link) use ($formatStorageLinkedStatus) {
235235
$path = Str::replace(public_path(), '', $link);
236236

src/Illuminate/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ public function merge(array $input)
363363
{
364364
return tap($this, function (Request $request) use ($input) {
365365
$request->getInputSource()
366-
->replace(collect($input)->reduce(
366+
->replace((new Collection($input))->reduce(
367367
fn ($requestInput, $value, $key) => data_set($requestInput, $key, $value),
368368
$this->getInputSource()->all()
369369
));

src/Illuminate/Testing/TestResponse.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,11 +989,16 @@ public function assertOnlyJsonValidationErrors($errors, $responseKey = 'errors')
989989

990990
$jsonErrors = Arr::get($this->json(), $responseKey) ?? [];
991991

992-
$expectedErrorKeys = collect($errors)->map(fn ($value, $key) => is_int($key) ? $value : $key)->all();
992+
$expectedErrorKeys = (new Collection($errors))
993+
->map(fn ($value, $key) => is_int($key) ? $value : $key)
994+
->all();
993995

994996
$unexpectedErrorKeys = Arr::except($jsonErrors, $expectedErrorKeys);
995997

996-
PHPUnit::withResponse($this)->assertTrue(count($unexpectedErrorKeys) === 0, 'Response has unexpected validation errors: '.collect($unexpectedErrorKeys)->keys()->map(fn ($key) => "'{$key}'")->join(', '));
998+
PHPUnit::withResponse($this)->assertTrue(
999+
count($unexpectedErrorKeys) === 0,
1000+
'Response has unexpected validation errors: '.(new Collection($unexpectedErrorKeys))->keys()->map(fn ($key) => "'{$key}'")->join(', ')
1001+
);
9971002

9981003
return $this;
9991004
}
@@ -1398,14 +1403,15 @@ public function assertOnlyInvalid($errors = null, $errorBag = 'default', $respon
13981403
->getBag($errorBag)
13991404
->getMessages();
14001405

1401-
$expectedErrorKeys = collect($errors)
1402-
->map(fn ($value, $key) => is_int($key) ? $value : $key)->all();
1406+
$expectedErrorKeys = (new Collection($errors))
1407+
->map(fn ($value, $key) => is_int($key) ? $value : $key)
1408+
->all();
14031409

14041410
$unexpectedErrorKeys = Arr::except($sessionErrors, $expectedErrorKeys);
14051411

14061412
PHPUnit::withResponse($this)->assertTrue(
14071413
count($unexpectedErrorKeys) === 0,
1408-
'Response has unexpected validation errors: '.collect($unexpectedErrorKeys)->keys()->map(fn ($key) => "'{$key}'")->join(', ')
1414+
'Response has unexpected validation errors: '.(new Collection($unexpectedErrorKeys))->keys()->map(fn ($key) => "'{$key}'")->join(', ')
14091415
);
14101416

14111417
return $this;

0 commit comments

Comments
 (0)