Skip to content

Commit b7510a1

Browse files
authored
minor code formatting improvements (#56296)
utilize short closures and new line chaining to improve readability and prep for better diffs. no behavior change, purely formatting.
1 parent 84612f0 commit b7510a1

File tree

22 files changed

+109
-104
lines changed

22 files changed

+109
-104
lines changed

src/Illuminate/Bus/Queueable.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,9 @@ public function through($middleware)
204204
*/
205205
public function chain($chain)
206206
{
207-
$jobs = ChainedBatch::prepareNestedBatches(new Collection($chain));
208-
209-
$this->chained = $jobs->map(function ($job) {
210-
return $this->serializeJob($job);
211-
})->all();
207+
$this->chained = ChainedBatch::prepareNestedBatches(new Collection($chain))
208+
->map(fn ($job) => $this->serializeJob($job))
209+
->all();
212210

213211
return $this;
214212
}

src/Illuminate/Collections/LazyCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,9 +1766,9 @@ public function zip($items)
17661766
$iterables = func_get_args();
17671767

17681768
return new static(function () use ($iterables) {
1769-
$iterators = (new Collection($iterables))->map(function ($iterable) {
1770-
return $this->makeIterator($iterable);
1771-
})->prepend($this->getIterator());
1769+
$iterators = (new Collection($iterables))
1770+
->map(fn ($iterable) => $this->makeIterator($iterable))
1771+
->prepend($this->getIterator());
17721772

17731773
while ($iterators->contains->valid()) {
17741774
yield new static($iterators->map->current());

src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class ScheduleFinishCommand extends Command
4040
*/
4141
public function handle(Schedule $schedule)
4242
{
43-
(new Collection($schedule->events()))->filter(function ($value) {
44-
return $value->mutexName() == $this->argument('id');
45-
})->each(function ($event) {
46-
$event->finish($this->laravel, $this->argument('code'));
43+
(new Collection($schedule->events()))
44+
->filter(fn ($value) => $value->mutexName() == $this->argument('id'))
45+
->each(function ($event) {
46+
$event->finish($this->laravel, $this->argument('code'));
4747

48-
$this->laravel->make(Dispatcher::class)->dispatch(new ScheduledBackgroundTaskFinished($event));
49-
});
48+
$this->laravel->make(Dispatcher::class)->dispatch(new ScheduledBackgroundTaskFinished($event));
49+
});
5050
}
5151
}

src/Illuminate/Database/Eloquent/Casts/AsEnumArrayObject.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public function set($model, $key, $value, $attributes)
6868

6969
public function serialize($model, string $key, $value, array $attributes)
7070
{
71-
return (new Collection($value->getArrayCopy()))->map(function ($enum) {
72-
return $this->getStorableEnumValue($enum);
73-
})->toArray();
71+
return (new Collection($value->getArrayCopy()))
72+
->map(fn ($enum) => $this->getStorableEnumValue($enum))
73+
->toArray();
7474
}
7575

7676
protected function getStorableEnumValue($enum)

src/Illuminate/Database/Eloquent/Casts/AsEnumCollection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public function set($model, $key, $value, $attributes)
6464

6565
public function serialize($model, string $key, $value, array $attributes)
6666
{
67-
return (new Collection($value))->map(function ($enum) {
68-
return $this->getStorableEnumValue($enum);
69-
})->toArray();
67+
return (new Collection($value))
68+
->map(fn ($enum) => $this->getStorableEnumValue($enum))
69+
->toArray();
7070
}
7171

7272
protected function getStorableEnumValue($enum)

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,9 +1195,9 @@ public function compileInsert(Builder $query, array $values)
11951195
// We need to build a list of parameter place-holders of values that are bound
11961196
// to the query. Each insert should have the exact same number of parameter
11971197
// bindings so we will loop through the record and parameterize them all.
1198-
$parameters = (new Collection($values))->map(function ($record) {
1199-
return '('.$this->parameterize($record).')';
1200-
})->implode(', ');
1198+
$parameters = (new Collection($values))
1199+
->map(fn ($record) => '('.$this->parameterize($record).')')
1200+
->implode(', ');
12011201

12021202
return "insert into $table ($columns) values $parameters";
12031203
}
@@ -1294,9 +1294,9 @@ public function compileUpdate(Builder $query, array $values)
12941294
*/
12951295
protected function compileUpdateColumns(Builder $query, array $values)
12961296
{
1297-
return (new Collection($values))->map(function ($value, $key) {
1298-
return $this->wrap($key).' = '.$this->parameter($value);
1299-
})->implode(', ');
1297+
return (new Collection($values))
1298+
->map(fn ($value, $key) => $this->wrap($key).' = '.$this->parameter($value))
1299+
->implode(', ');
13001300
}
13011301

13021302
/**

src/Illuminate/Database/Query/Grammars/PostgresGrammar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ public function whereFullText(Builder $query, $where)
167167
$language = 'english';
168168
}
169169

170-
$columns = (new Collection($where['columns']))->map(function ($column) use ($language) {
171-
return "to_tsvector('{$language}', {$this->wrap($column)})";
172-
})->implode(' || ');
170+
$columns = (new Collection($where['columns']))
171+
->map(fn ($column) => "to_tsvector('{$language}', {$this->wrap($column)})")
172+
->implode(' || ');
173173

174174
$mode = 'plainto_tsquery';
175175

src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,17 @@ protected function compileUpdateColumns(Builder $query, array $values)
289289
{
290290
$jsonGroups = $this->groupJsonColumnsForUpdate($values);
291291

292-
return (new Collection($values))->reject(function ($value, $key) {
293-
return $this->isJsonSelector($key);
294-
})->merge($jsonGroups)->map(function ($value, $key) use ($jsonGroups) {
295-
$column = last(explode('.', $key));
292+
return (new Collection($values))
293+
->reject(fn ($value, $key) => $this->isJsonSelector($key))
294+
->merge($jsonGroups)
295+
->map(function ($value, $key) use ($jsonGroups) {
296+
$column = last(explode('.', $key));
296297

297-
$value = isset($jsonGroups[$key]) ? $this->compileJsonPatch($column, $value) : $this->parameter($value);
298+
$value = isset($jsonGroups[$key]) ? $this->compileJsonPatch($column, $value) : $this->parameter($value);
298299

299-
return $this->wrap($column).' = '.$value;
300-
})->implode(', ');
300+
return $this->wrap($column).' = '.$value;
301+
})
302+
->implode(', ');
301303
}
302304

303305
/**

src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,15 @@ public function compileUpsert(Builder $query, array $values, array $uniqueBy, ar
419419

420420
$sql = 'merge '.$this->wrapTable($query->from).' ';
421421

422-
$parameters = (new Collection($values))->map(function ($record) {
423-
return '('.$this->parameterize($record).')';
424-
})->implode(', ');
422+
$parameters = (new Collection($values))
423+
->map(fn ($record) => '('.$this->parameterize($record).')')
424+
->implode(', ');
425425

426426
$sql .= 'using (values '.$parameters.') '.$this->wrapTable('laravel_source').' ('.$columns.') ';
427427

428-
$on = (new Collection($uniqueBy))->map(function ($column) use ($query) {
429-
return $this->wrap('laravel_source.'.$column).' = '.$this->wrap($query->from.'.'.$column);
430-
})->implode(' and ');
428+
$on = (new Collection($uniqueBy))
429+
->map(fn ($column) => $this->wrap('laravel_source.'.$column).' = '.$this->wrap($query->from.'.'.$column))
430+
->implode(' and ');
431431

432432
$sql .= 'on '.$on.' ';
433433

src/Illuminate/Database/Schema/Blueprint.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,8 @@ protected function ensureCommandsAreValid()
179179
*/
180180
protected function commandsNamed(array $names)
181181
{
182-
return (new Collection($this->commands))->filter(function ($command) use ($names) {
183-
return in_array($command->name, $names);
184-
});
182+
return (new Collection($this->commands))
183+
->filter(fn ($command) => in_array($command->name, $names));
185184
}
186185

187186
/**
@@ -316,9 +315,8 @@ public function addAlterCommands()
316315
*/
317316
public function creating()
318317
{
319-
return (new Collection($this->commands))->contains(function ($command) {
320-
return ! $command instanceof ColumnDefinition && $command->name === 'create';
321-
});
318+
return (new Collection($this->commands))
319+
->contains(fn ($command) => ! $command instanceof ColumnDefinition && $command->name === 'create');
322320
}
323321

324322
/**

0 commit comments

Comments
 (0)