Skip to content

Commit d16c1a1

Browse files
authored
[12.x] multiline chaining on Collections (#55061)
* multiline chaining on Collections when chaining methods or properties on a `Collection`, place them on a newline for easier readability and clearer diffs. also use short closures for simple bodies. this is a continuation of some of my previous formatting commits. * minor formatting
1 parent 86f8574 commit d16c1a1

File tree

20 files changed

+132
-95
lines changed

20 files changed

+132
-95
lines changed

src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ protected function extractAuthParameters($pattern, $channel, $callback)
141141
{
142142
$callbackParameters = $this->extractParameters($callback);
143143

144-
return (new Collection($this->extractChannelKeys($pattern, $channel)))->reject(function ($value, $key) {
145-
return is_numeric($key);
146-
})->map(function ($value, $key) use ($callbackParameters) {
147-
return $this->resolveBinding($key, $value, $callbackParameters);
148-
})->values()->all();
144+
return (new Collection($this->extractChannelKeys($pattern, $channel)))
145+
->reject(fn ($value, $key) => is_numeric($key))
146+
->map(fn ($value, $key) => $this->resolveBinding($key, $value, $callbackParameters))
147+
->values()
148+
->all();
149149
}
150150

151151
/**

src/Illuminate/Cache/Repository.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ public function many(array $keys)
142142
{
143143
$this->event(new RetrievingManyKeys($this->getName(), $keys));
144144

145-
$values = $this->store->many((new Collection($keys))->map(function ($value, $key) {
146-
return is_string($key) ? $key : $value;
147-
})->values()->all());
145+
$values = $this->store->many((new Collection($keys))
146+
->map(fn ($value, $key) => is_string($key) ? $key : $value)
147+
->values()
148+
->all()
149+
);
148150

149151
return (new Collection($values))
150152
->map(fn ($value, $key) => $this->handleManyResult($keys, $key, $value))

src/Illuminate/Database/Console/PruneCommand.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,11 @@ protected function models()
138138
['\\', ''],
139139
Str::after($model->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
140140
);
141-
})->when(! empty($except), function ($models) use ($except) {
142-
return $models->reject(function ($model) use ($except) {
143-
return in_array($model, $except);
144-
});
145-
})->filter(function ($model) {
146-
return class_exists($model);
147-
})->filter(function ($model) {
148-
return $this->isPrunable($model);
149-
})->values();
141+
})
142+
->when(! empty($except), fn ($models) => $models->reject(fn ($model) => in_array($model, $except)))
143+
->filter(fn ($model) => class_exists($model))
144+
->filter(fn ($model) => $this->isPrunable($model))
145+
->values();
150146
}
151147

152148
/**

src/Illuminate/Database/Query/Builder.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2850,11 +2850,9 @@ public function reorder($column = null, $direction = 'asc')
28502850
protected function removeExistingOrdersFor($column)
28512851
{
28522852
return (new Collection($this->orders))
2853-
->reject(function ($order) use ($column) {
2854-
return isset($order['column'])
2855-
? $order['column'] === $column
2856-
: false;
2857-
})->values()->all();
2853+
->reject(fn ($order) => isset($order['column']) && $order['column'] === $column)
2854+
->values()
2855+
->all();
28582856
}
28592857

28602858
/**

src/Illuminate/Foundation/Console/RouteListCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ public function handle()
114114
*/
115115
protected function getRoutes()
116116
{
117-
$routes = (new Collection($this->router->getRoutes()))->map(function ($route) {
118-
return $this->getRouteInformation($route);
119-
})->filter()->all();
117+
$routes = (new Collection($this->router->getRoutes()))
118+
->map(fn ($route) => $this->getRouteInformation($route))
119+
->filter()
120+
->all();
120121

121122
if (($sort = $this->option('sort')) !== null) {
122123
$routes = $this->sortRoutes($sort, $routes);
@@ -208,9 +209,9 @@ protected function displayRoutes(array $routes)
208209
*/
209210
protected function getMiddleware($route)
210211
{
211-
return (new Collection($this->router->gatherRouteMiddleware($route)))->map(function ($middleware) {
212-
return $middleware instanceof Closure ? 'Closure' : $middleware;
213-
})->implode("\n");
212+
return (new Collection($this->router->gatherRouteMiddleware($route)))
213+
->map(fn ($middleware) => $middleware instanceof Closure ? 'Closure' : $middleware)
214+
->implode("\n");
214215
}
215216

216217
/**

src/Illuminate/Foundation/Exceptions/Handler.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,10 +483,14 @@ public function stopIgnoring(array|string $exceptions)
483483
$exceptions = Arr::wrap($exceptions);
484484

485485
$this->dontReport = (new Collection($this->dontReport))
486-
->reject(fn ($ignored) => in_array($ignored, $exceptions))->values()->all();
486+
->reject(fn ($ignored) => in_array($ignored, $exceptions))
487+
->values()
488+
->all();
487489

488490
$this->internalDontReport = (new Collection($this->internalDontReport))
489-
->reject(fn ($ignored) => in_array($ignored, $exceptions))->values()->all();
491+
->reject(fn ($ignored) => in_array($ignored, $exceptions))
492+
->values()
493+
->all();
490494

491495
return $this;
492496
}

src/Illuminate/Foundation/PackageManifest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ public function aliases()
8888
*/
8989
public function config($key)
9090
{
91-
return (new Collection($this->getManifest()))->flatMap(function ($configuration) use ($key) {
92-
return (array) ($configuration[$key] ?? []);
93-
})->filter()->all();
91+
return (new Collection($this->getManifest()))
92+
->flatMap(fn ($configuration) => (array) ($configuration[$key] ?? []))
93+
->filter()
94+
->all();
9495
}
9596

9697
/**

src/Illuminate/Http/Client/PendingRequest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -991,13 +991,15 @@ protected function parseHttpOptions(array $options)
991991
$options[$this->bodyFormat] = $this->pendingBody;
992992
}
993993

994-
return (new Collection($options))->map(function ($value, $key) {
995-
if ($key === 'json' && $value instanceof JsonSerializable) {
996-
return $value;
997-
}
994+
return (new Collection($options))
995+
->map(function ($value, $key) {
996+
if ($key === 'json' && $value instanceof JsonSerializable) {
997+
return $value;
998+
}
998999

999-
return $value instanceof Arrayable ? $value->toArray() : $value;
1000-
})->all();
1000+
return $value instanceof Arrayable ? $value->toArray() : $value;
1001+
})
1002+
->all();
10011003
}
10021004

10031005
/**

src/Illuminate/Notifications/Channels/MailChannel.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,13 @@ protected function getRecipients($notifiable, $notification, $message)
263263
$recipients = [$recipients];
264264
}
265265

266-
return (new Collection($recipients))->mapWithKeys(function ($recipient, $email) {
267-
return is_numeric($email)
268-
? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
269-
: [$email => $recipient];
270-
})->all();
266+
return (new Collection($recipients))
267+
->mapWithKeys(function ($recipient, $email) {
268+
return is_numeric($email)
269+
? [$email => (is_string($recipient) ? $recipient : $recipient->email)]
270+
: [$email => $recipient];
271+
})
272+
->all();
271273
}
272274

273275
/**

src/Illuminate/Notifications/Messages/MailMessage.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,10 @@ public function data()
372372
*/
373373
protected function parseAddresses($value)
374374
{
375-
return (new Collection($value))->map(function ($address, $name) {
376-
return [$address, is_numeric($name) ? null : $name];
377-
})->values()->all();
375+
return (new Collection($value))
376+
->map(fn ($address, $name) => [$address, is_numeric($name) ? null : $name])
377+
->values()
378+
->all();
378379
}
379380

380381
/**

0 commit comments

Comments
 (0)