diff --git a/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php b/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php index 6ebde3b7e3af..7340f55181df 100644 --- a/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php +++ b/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php @@ -141,11 +141,11 @@ protected function extractAuthParameters($pattern, $channel, $callback) { $callbackParameters = $this->extractParameters($callback); - return (new Collection($this->extractChannelKeys($pattern, $channel)))->reject(function ($value, $key) { - return is_numeric($key); - })->map(function ($value, $key) use ($callbackParameters) { - return $this->resolveBinding($key, $value, $callbackParameters); - })->values()->all(); + return (new Collection($this->extractChannelKeys($pattern, $channel))) + ->reject(fn ($value, $key) => is_numeric($key)) + ->map(fn ($value, $key) => $this->resolveBinding($key, $value, $callbackParameters)) + ->values() + ->all(); } /** diff --git a/src/Illuminate/Cache/Repository.php b/src/Illuminate/Cache/Repository.php index a5f1df9db137..978e2ffbadaf 100755 --- a/src/Illuminate/Cache/Repository.php +++ b/src/Illuminate/Cache/Repository.php @@ -142,9 +142,11 @@ public function many(array $keys) { $this->event(new RetrievingManyKeys($this->getName(), $keys)); - $values = $this->store->many((new Collection($keys))->map(function ($value, $key) { - return is_string($key) ? $key : $value; - })->values()->all()); + $values = $this->store->many((new Collection($keys)) + ->map(fn ($value, $key) => is_string($key) ? $key : $value) + ->values() + ->all() + ); return (new Collection($values)) ->map(fn ($value, $key) => $this->handleManyResult($keys, $key, $value)) diff --git a/src/Illuminate/Database/Console/PruneCommand.php b/src/Illuminate/Database/Console/PruneCommand.php index db8dead36342..a7b58e560189 100644 --- a/src/Illuminate/Database/Console/PruneCommand.php +++ b/src/Illuminate/Database/Console/PruneCommand.php @@ -138,15 +138,11 @@ protected function models() ['\\', ''], Str::after($model->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR) ); - })->when(! empty($except), function ($models) use ($except) { - return $models->reject(function ($model) use ($except) { - return in_array($model, $except); - }); - })->filter(function ($model) { - return class_exists($model); - })->filter(function ($model) { - return $this->isPrunable($model); - })->values(); + }) + ->when(! empty($except), fn ($models) => $models->reject(fn ($model) => in_array($model, $except))) + ->filter(fn ($model) => class_exists($model)) + ->filter(fn ($model) => $this->isPrunable($model)) + ->values(); } /** diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index f824f1c90b13..be76e9754fa2 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -2850,11 +2850,9 @@ public function reorder($column = null, $direction = 'asc') protected function removeExistingOrdersFor($column) { return (new Collection($this->orders)) - ->reject(function ($order) use ($column) { - return isset($order['column']) - ? $order['column'] === $column - : false; - })->values()->all(); + ->reject(fn ($order) => isset($order['column']) && $order['column'] === $column) + ->values() + ->all(); } /** diff --git a/src/Illuminate/Foundation/Console/RouteListCommand.php b/src/Illuminate/Foundation/Console/RouteListCommand.php index b6c416b1363b..5f735925ed04 100644 --- a/src/Illuminate/Foundation/Console/RouteListCommand.php +++ b/src/Illuminate/Foundation/Console/RouteListCommand.php @@ -114,9 +114,10 @@ public function handle() */ protected function getRoutes() { - $routes = (new Collection($this->router->getRoutes()))->map(function ($route) { - return $this->getRouteInformation($route); - })->filter()->all(); + $routes = (new Collection($this->router->getRoutes())) + ->map(fn ($route) => $this->getRouteInformation($route)) + ->filter() + ->all(); if (($sort = $this->option('sort')) !== null) { $routes = $this->sortRoutes($sort, $routes); @@ -208,9 +209,9 @@ protected function displayRoutes(array $routes) */ protected function getMiddleware($route) { - return (new Collection($this->router->gatherRouteMiddleware($route)))->map(function ($middleware) { - return $middleware instanceof Closure ? 'Closure' : $middleware; - })->implode("\n"); + return (new Collection($this->router->gatherRouteMiddleware($route))) + ->map(fn ($middleware) => $middleware instanceof Closure ? 'Closure' : $middleware) + ->implode("\n"); } /** diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index f79734bdb8e2..a4b773c4a43f 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -483,10 +483,14 @@ public function stopIgnoring(array|string $exceptions) $exceptions = Arr::wrap($exceptions); $this->dontReport = (new Collection($this->dontReport)) - ->reject(fn ($ignored) => in_array($ignored, $exceptions))->values()->all(); + ->reject(fn ($ignored) => in_array($ignored, $exceptions)) + ->values() + ->all(); $this->internalDontReport = (new Collection($this->internalDontReport)) - ->reject(fn ($ignored) => in_array($ignored, $exceptions))->values()->all(); + ->reject(fn ($ignored) => in_array($ignored, $exceptions)) + ->values() + ->all(); return $this; } diff --git a/src/Illuminate/Foundation/PackageManifest.php b/src/Illuminate/Foundation/PackageManifest.php index c569b7740fb4..c3f66ba69ab1 100644 --- a/src/Illuminate/Foundation/PackageManifest.php +++ b/src/Illuminate/Foundation/PackageManifest.php @@ -88,9 +88,10 @@ public function aliases() */ public function config($key) { - return (new Collection($this->getManifest()))->flatMap(function ($configuration) use ($key) { - return (array) ($configuration[$key] ?? []); - })->filter()->all(); + return (new Collection($this->getManifest())) + ->flatMap(fn ($configuration) => (array) ($configuration[$key] ?? [])) + ->filter() + ->all(); } /** diff --git a/src/Illuminate/Http/Client/PendingRequest.php b/src/Illuminate/Http/Client/PendingRequest.php index 2915bc3f367c..cf87583e3264 100644 --- a/src/Illuminate/Http/Client/PendingRequest.php +++ b/src/Illuminate/Http/Client/PendingRequest.php @@ -991,13 +991,15 @@ protected function parseHttpOptions(array $options) $options[$this->bodyFormat] = $this->pendingBody; } - return (new Collection($options))->map(function ($value, $key) { - if ($key === 'json' && $value instanceof JsonSerializable) { - return $value; - } + return (new Collection($options)) + ->map(function ($value, $key) { + if ($key === 'json' && $value instanceof JsonSerializable) { + return $value; + } - return $value instanceof Arrayable ? $value->toArray() : $value; - })->all(); + return $value instanceof Arrayable ? $value->toArray() : $value; + }) + ->all(); } /** diff --git a/src/Illuminate/Notifications/Channels/MailChannel.php b/src/Illuminate/Notifications/Channels/MailChannel.php index f11016ddb1c6..81215f3b0348 100644 --- a/src/Illuminate/Notifications/Channels/MailChannel.php +++ b/src/Illuminate/Notifications/Channels/MailChannel.php @@ -263,11 +263,13 @@ protected function getRecipients($notifiable, $notification, $message) $recipients = [$recipients]; } - return (new Collection($recipients))->mapWithKeys(function ($recipient, $email) { - return is_numeric($email) - ? [$email => (is_string($recipient) ? $recipient : $recipient->email)] - : [$email => $recipient]; - })->all(); + return (new Collection($recipients)) + ->mapWithKeys(function ($recipient, $email) { + return is_numeric($email) + ? [$email => (is_string($recipient) ? $recipient : $recipient->email)] + : [$email => $recipient]; + }) + ->all(); } /** diff --git a/src/Illuminate/Notifications/Messages/MailMessage.php b/src/Illuminate/Notifications/Messages/MailMessage.php index a80117a50178..f6eab8ca6798 100644 --- a/src/Illuminate/Notifications/Messages/MailMessage.php +++ b/src/Illuminate/Notifications/Messages/MailMessage.php @@ -372,9 +372,10 @@ public function data() */ protected function parseAddresses($value) { - return (new Collection($value))->map(function ($address, $name) { - return [$address, is_numeric($name) ? null : $name]; - })->values()->all(); + return (new Collection($value)) + ->map(fn ($address, $name) => [$address, is_numeric($name) ? null : $name]) + ->values() + ->all(); } /** diff --git a/src/Illuminate/Process/FakeProcessDescription.php b/src/Illuminate/Process/FakeProcessDescription.php index fdf6dc18cdba..1c397176eafb 100644 --- a/src/Illuminate/Process/FakeProcessDescription.php +++ b/src/Illuminate/Process/FakeProcessDescription.php @@ -94,9 +94,10 @@ public function errorOutput(array|string $output) */ public function replaceOutput(string $output) { - $this->output = (new Collection($this->output))->reject(function ($output) { - return $output['type'] === 'out'; - })->values()->all(); + $this->output = (new Collection($this->output)) + ->reject(fn ($output) => $output['type'] === 'out') + ->values() + ->all(); if (strlen($output) > 0) { $this->output[] = [ @@ -116,9 +117,10 @@ public function replaceOutput(string $output) */ public function replaceErrorOutput(string $output) { - $this->output = (new Collection($this->output))->reject(function ($output) { - return $output['type'] === 'err'; - })->values()->all(); + $this->output = (new Collection($this->output)) + ->reject(fn ($output) => $output['type'] === 'err') + ->values() + ->all(); if (strlen($output) > 0) { $this->output[] = [ diff --git a/src/Illuminate/Process/Pool.php b/src/Illuminate/Process/Pool.php index 1a98a8541a57..3e274d84c783 100644 --- a/src/Illuminate/Process/Pool.php +++ b/src/Illuminate/Process/Pool.php @@ -74,7 +74,8 @@ public function start(?callable $output = null) if (! $pendingProcess instanceof PendingProcess) { throw new InvalidArgumentException('Process pool must only contain pending processes.'); } - })->mapWithKeys(function ($pendingProcess, $key) use ($output) { + }) + ->mapWithKeys(function ($pendingProcess, $key) use ($output) { return [$key => $pendingProcess->start(output: $output ? function ($type, $buffer) use ($key, $output) { $output($type, $buffer, $key); } : null)]; diff --git a/src/Illuminate/Queue/Failed/FileFailedJobProvider.php b/src/Illuminate/Queue/Failed/FileFailedJobProvider.php index dff5f44a6082..61f66657654d 100644 --- a/src/Illuminate/Queue/Failed/FileFailedJobProvider.php +++ b/src/Illuminate/Queue/Failed/FileFailedJobProvider.php @@ -155,9 +155,11 @@ public function prune(DateTimeInterface $before) return $this->lock(function () use ($before) { $jobs = $this->read(); - $this->write($prunedJobs = (new Collection($jobs))->reject(function ($job) use ($before) { - return $job->failed_at_timestamp <= $before->getTimestamp(); - })->values()->all()); + $this->write($prunedJobs = (new Collection($jobs)) + ->reject(fn ($job) => $job->failed_at_timestamp <= $before->getTimestamp()) + ->values() + ->all() + ); return count($jobs) - count($prunedJobs); }); diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index d877268d1ffb..a4ccd94cb99b 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -1139,15 +1139,22 @@ public function controllerMiddleware() */ protected function staticallyProvidedControllerMiddleware(string $class, string $method) { - return (new Collection($class::middleware()))->map(function ($middleware) { - return $middleware instanceof Middleware - ? $middleware - : new Middleware($middleware); - })->reject(function ($middleware) use ($method) { - return static::methodExcludedByOptions( - $method, ['only' => $middleware->only, 'except' => $middleware->except] - ); - })->map->middleware->flatten()->values()->all(); + return (new Collection($class::middleware())) + ->map(function ($middleware) { + return $middleware instanceof Middleware + ? $middleware + : new Middleware($middleware); + }) + ->reject(function ($middleware) use ($method) { + return static::methodExcludedByOptions( + $method, ['only' => $middleware->only, 'except' => $middleware->except], + ); + }) + ->map + ->middleware + ->flatten() + ->values() + ->all(); } /** diff --git a/src/Illuminate/Routing/Router.php b/src/Illuminate/Routing/Router.php index d29050277ca5..4a0c21ccc48b 100644 --- a/src/Illuminate/Routing/Router.php +++ b/src/Illuminate/Routing/Router.php @@ -830,9 +830,13 @@ public function gatherRouteMiddleware(Route $route) */ public function resolveMiddleware(array $middleware, array $excluded = []) { - $excluded = $excluded === [] ? $excluded : (new Collection($excluded))->map(function ($name) { - return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups); - })->flatten()->values()->all(); + $excluded = $excluded === [] + ? $excluded + : (new Collection($excluded)) + ->map(fn ($name) => (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups)) + ->flatten() + ->values() + ->all(); $middleware = (new Collection($middleware))->map(function ($name) { return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups); diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php index 556479fabb16..3bb47011d654 100644 --- a/src/Illuminate/Support/Str.php +++ b/src/Illuminate/Support/Str.php @@ -1051,8 +1051,10 @@ public static function password($length = 32, $letters = true, $numbers = true, ']', '|', ':', ';', ] : null, 'spaces' => $spaces === true ? [' '] : null, - ]))->filter()->each(fn ($c) => $password->push($c[random_int(0, count($c) - 1)]) - )->flatten(); + ])) + ->filter() + ->each(fn ($c) => $password->push($c[random_int(0, count($c) - 1)])) + ->flatten(); $length = $length - $password->count(); diff --git a/src/Illuminate/Support/Testing/Fakes/QueueFake.php b/src/Illuminate/Support/Testing/Fakes/QueueFake.php index 75e976583c0d..d703ab12fe59 100644 --- a/src/Illuminate/Support/Testing/Fakes/QueueFake.php +++ b/src/Illuminate/Support/Testing/Fakes/QueueFake.php @@ -379,9 +379,10 @@ public function connection($value = null) */ public function size($queue = null) { - return (new Collection($this->jobs))->flatten(1)->filter( - fn ($job) => $job['queue'] === $queue - )->count(); + return (new Collection($this->jobs)) + ->flatten(1) + ->filter(fn ($job) => $job['queue'] === $queue) + ->count(); } /** diff --git a/src/Illuminate/Support/Traits/InteractsWithData.php b/src/Illuminate/Support/Traits/InteractsWithData.php index 722478ec0a0b..bd39205d942d 100644 --- a/src/Illuminate/Support/Traits/InteractsWithData.php +++ b/src/Illuminate/Support/Traits/InteractsWithData.php @@ -338,9 +338,10 @@ public function enums($key, $enumClass) return []; } - return $this->collect($key)->map(function ($value) use ($enumClass) { - return $enumClass::tryFrom($value); - })->filter()->all(); + return $this->collect($key) + ->map(fn ($value) => $enumClass::tryFrom($value)) + ->filter() + ->all(); } /** diff --git a/src/Illuminate/Support/Traits/ReflectsClosures.php b/src/Illuminate/Support/Traits/ReflectsClosures.php index 34f3ec805e89..9e12285a30a7 100644 --- a/src/Illuminate/Support/Traits/ReflectsClosures.php +++ b/src/Illuminate/Support/Traits/ReflectsClosures.php @@ -47,13 +47,17 @@ protected function firstClosureParameterTypes(Closure $closure) { $reflection = new ReflectionFunction($closure); - $types = (new Collection($reflection->getParameters()))->mapWithKeys(function ($parameter) { - if ($parameter->isVariadic()) { - return [$parameter->getName() => null]; - } + $types = (new Collection($reflection->getParameters())) + ->mapWithKeys(function ($parameter) { + if ($parameter->isVariadic()) { + return [$parameter->getName() => null]; + } - return [$parameter->getName() => Reflector::getParameterClassNames($parameter)]; - })->filter()->values()->all(); + return [$parameter->getName() => Reflector::getParameterClassNames($parameter)]; + }) + ->filter() + ->values() + ->all(); if (empty($types)) { throw new RuntimeException('The given Closure has no parameters.'); @@ -78,12 +82,14 @@ protected function closureParameterTypes(Closure $closure) { $reflection = new ReflectionFunction($closure); - return (new Collection($reflection->getParameters()))->mapWithKeys(function ($parameter) { - if ($parameter->isVariadic()) { - return [$parameter->getName() => null]; - } + return (new Collection($reflection->getParameters())) + ->mapWithKeys(function ($parameter) { + if ($parameter->isVariadic()) { + return [$parameter->getName() => null]; + } - return [$parameter->getName() => Reflector::getParameterClassName($parameter)]; - })->all(); + return [$parameter->getName() => Reflector::getParameterClassName($parameter)]; + }) + ->all(); } } diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 517577dac5d5..0bafe724bb0b 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -1042,9 +1042,11 @@ public function invalid() */ protected function attributesThatHaveMessages() { - return (new Collection($this->messages()->toArray()))->map(function ($message, $key) { - return explode('.', $key)[0]; - })->unique()->flip()->all(); + return (new Collection($this->messages()->toArray())) + ->map(fn ($message, $key) => explode('.', $key)[0]) + ->unique() + ->flip() + ->all(); } /** @@ -1217,9 +1219,11 @@ public function getRulesWithoutPlaceholders() */ public function setRules(array $rules) { - $rules = (new Collection($rules))->mapWithKeys(function ($value, $key) { - return [str_replace('\.', '__dot__'.static::$placeholderHash, $key) => $value]; - })->toArray(); + $rules = (new Collection($rules)) + ->mapWithKeys(function ($value, $key) { + return [str_replace('\.', '__dot__'.static::$placeholderHash, $key) => $value]; + }) + ->toArray(); $this->initialRules = $rules;