Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/Illuminate/Bus/Queueable.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,9 @@ public function through($middleware)
*/
public function chain($chain)
{
$jobs = ChainedBatch::prepareNestedBatches(new Collection($chain));

$this->chained = $jobs->map(function ($job) {
return $this->serializeJob($job);
})->all();
$this->chained = ChainedBatch::prepareNestedBatches(new Collection($chain))
->map(fn ($job) => $this->serializeJob($job))
->all();

return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Collections/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1766,9 +1766,9 @@ public function zip($items)
$iterables = func_get_args();

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

while ($iterators->contains->valid()) {
yield new static($iterators->map->current());
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Console/Scheduling/ScheduleFinishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ class ScheduleFinishCommand extends Command
*/
public function handle(Schedule $schedule)
{
(new Collection($schedule->events()))->filter(function ($value) {
return $value->mutexName() == $this->argument('id');
})->each(function ($event) {
$event->finish($this->laravel, $this->argument('code'));
(new Collection($schedule->events()))
->filter(fn ($value) => $value->mutexName() == $this->argument('id'))
->each(function ($event) {
$event->finish($this->laravel, $this->argument('code'));

$this->laravel->make(Dispatcher::class)->dispatch(new ScheduledBackgroundTaskFinished($event));
});
$this->laravel->make(Dispatcher::class)->dispatch(new ScheduledBackgroundTaskFinished($event));
});
}
}
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Casts/AsEnumArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public function set($model, $key, $value, $attributes)

public function serialize($model, string $key, $value, array $attributes)
{
return (new Collection($value->getArrayCopy()))->map(function ($enum) {
return $this->getStorableEnumValue($enum);
})->toArray();
return (new Collection($value->getArrayCopy()))
->map(fn ($enum) => $this->getStorableEnumValue($enum))
->toArray();
}

protected function getStorableEnumValue($enum)
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Eloquent/Casts/AsEnumCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function set($model, $key, $value, $attributes)

public function serialize($model, string $key, $value, array $attributes)
{
return (new Collection($value))->map(function ($enum) {
return $this->getStorableEnumValue($enum);
})->toArray();
return (new Collection($value))
->map(fn ($enum) => $this->getStorableEnumValue($enum))
->toArray();
}

protected function getStorableEnumValue($enum)
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -1195,9 +1195,9 @@ public function compileInsert(Builder $query, array $values)
// We need to build a list of parameter place-holders of values that are bound
// to the query. Each insert should have the exact same number of parameter
// bindings so we will loop through the record and parameterize them all.
$parameters = (new Collection($values))->map(function ($record) {
return '('.$this->parameterize($record).')';
})->implode(', ');
$parameters = (new Collection($values))
->map(fn ($record) => '('.$this->parameterize($record).')')
->implode(', ');

return "insert into $table ($columns) values $parameters";
}
Expand Down Expand Up @@ -1294,9 +1294,9 @@ public function compileUpdate(Builder $query, array $values)
*/
protected function compileUpdateColumns(Builder $query, array $values)
{
return (new Collection($values))->map(function ($value, $key) {
return $this->wrap($key).' = '.$this->parameter($value);
})->implode(', ');
return (new Collection($values))
->map(fn ($value, $key) => $this->wrap($key).' = '.$this->parameter($value))
->implode(', ');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ public function whereFullText(Builder $query, $where)
$language = 'english';
}

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

$mode = 'plainto_tsquery';

Expand Down
16 changes: 9 additions & 7 deletions src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,17 @@ protected function compileUpdateColumns(Builder $query, array $values)
{
$jsonGroups = $this->groupJsonColumnsForUpdate($values);

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

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

return $this->wrap($column).' = '.$value;
})->implode(', ');
return $this->wrap($column).' = '.$value;
})
->implode(', ');
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,15 +419,15 @@ public function compileUpsert(Builder $query, array $values, array $uniqueBy, ar

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

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

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

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

$sql .= 'on '.$on.' ';

Expand Down
10 changes: 4 additions & 6 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ protected function ensureCommandsAreValid()
*/
protected function commandsNamed(array $names)
{
return (new Collection($this->commands))->filter(function ($command) use ($names) {
return in_array($command->name, $names);
});
return (new Collection($this->commands))
->filter(fn ($command) => in_array($command->name, $names));
}

/**
Expand Down Expand Up @@ -316,9 +315,8 @@ public function addAlterCommands()
*/
public function creating()
{
return (new Collection($this->commands))->contains(function ($command) {
return ! $command instanceof ColumnDefinition && $command->name === 'create';
});
return (new Collection($this->commands))
->contains(fn ($command) => ! $command instanceof ColumnDefinition && $command->name === 'create');
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Foundation/Console/ConfigPublishCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ public function handle()

$name = (string) (is_null($this->argument('name')) ? select(
label: 'Which configuration file would you like to publish?',
options: (new Collection($config))->map(function (string $path) {
return basename($path, '.php');
}),
options: (new Collection($config))->map(fn (string $path) => basename($path, '.php')),
) : $this->argument('name'));

if (! is_null($name) && ! isset($config[$name])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class RegisterErrorViewPaths
*/
public function __invoke()
{
View::replaceNamespace('errors', (new Collection(config('view.paths')))->map(function ($path) {
return "{$path}/errors";
})->push(__DIR__.'/views')->all());
View::replaceNamespace('errors', (new Collection(config('view.paths')))
->map(fn ($path) => "{$path}/errors")
->push(__DIR__.'/views')
->all()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,10 @@ protected function prepareCookiesForRequest()
return array_merge($this->defaultCookies, $this->unencryptedCookies);
}

return (new Collection($this->defaultCookies))->map(function ($value, $key) {
return encrypt(CookieValuePrefix::create($key, app('encrypter')->getKey()).$value, false);
})->merge($this->unencryptedCookies)->all();
return (new Collection($this->defaultCookies))
->map(fn ($value, $key) => encrypt(CookieValuePrefix::create($key, app('encrypter')->getKey()).$value, false))
->merge($this->unencryptedCookies)
->all();
}

/**
Expand Down
26 changes: 15 additions & 11 deletions src/Illuminate/Log/LogManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,17 +271,21 @@ protected function createStackDriver(array $config)
$config['channels'] = explode(',', $config['channels']);
}

$handlers = (new Collection($config['channels']))->flatMap(function ($channel) {
return $channel instanceof LoggerInterface
? $channel->getHandlers()
: $this->channel($channel)->getHandlers();
})->all();

$processors = (new Collection($config['channels']))->flatMap(function ($channel) {
return $channel instanceof LoggerInterface
? $channel->getProcessors()
: $this->channel($channel)->getProcessors();
})->all();
$handlers = (new Collection($config['channels']))
->flatMap(function ($channel) {
return $channel instanceof LoggerInterface
? $channel->getHandlers()
: $this->channel($channel)->getHandlers();
})
->all();

$processors = (new Collection($config['channels']))
->flatMap(function ($channel) {
return $channel instanceof LoggerInterface
? $channel->getProcessors()
: $this->channel($channel)->getProcessors();
})
->all();

if ($config['ignore_exceptions'] ?? false) {
$handlers = [new WhatFailureGroupHandler($handlers)];
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Pagination/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public function parameter(string $parameterName)
*/
public function parameters(array $parameterNames)
{
return (new Collection($parameterNames))->map(function ($parameterName) {
return $this->parameter($parameterName);
})->toArray();
return (new Collection($parameterNames))
->map(fn ($parameterName) => $this->parameter($parameterName))
->toArray();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Process/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ public function assertRanTimes(Closure|string $callback, int $times = 1)
{
$callback = is_string($callback) ? fn ($process) => $process->command === $callback : $callback;

$count = (new Collection($this->recorded))->filter(function ($pair) use ($callback) {
return $callback($pair[0], $pair[1]);
})->count();
$count = (new Collection($this->recorded))
->filter(fn ($pair) => $callback($pair[0], $pair[1]))
->count();

PHPUnit::assertSame(
$times, $count,
Expand Down
29 changes: 15 additions & 14 deletions src/Illuminate/Queue/Failed/DynamoDbFailedJobProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,21 @@ public function all()
'ScanIndexForward' => false,
]);

return (new Collection($results['Items']))->sortByDesc(function ($result) {
return (int) $result['failed_at']['N'];
})->map(function ($result) {
return (object) [
'id' => $result['uuid']['S'],
'connection' => $result['connection']['S'],
'queue' => $result['queue']['S'],
'payload' => $result['payload']['S'],
'exception' => $result['exception']['S'],
'failed_at' => Carbon::createFromTimestamp(
(int) $result['failed_at']['N'], date_default_timezone_get()
)->format(DateTimeInterface::ISO8601),
];
})->all();
return (new Collection($results['Items']))
->sortByDesc(fn ($result) => (int) $result['failed_at']['N'])
->map(function ($result) {
return (object) [
'id' => $result['uuid']['S'],
'connection' => $result['connection']['S'],
'queue' => $result['queue']['S'],
'payload' => $result['payload']['S'],
'exception' => $result['exception']['S'],
'failed_at' => Carbon::createFromTimestamp(
(int) $result['failed_at']['N'], date_default_timezone_get()
)->format(DateTimeInterface::ISO8601),
];
})
->all();
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Illuminate/Routing/ControllerDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ public function getMiddleware($controller, $method)
return [];
}

return (new Collection($controller->getMiddleware()))->reject(function ($data) use ($method) {
return static::methodExcludedByOptions($method, $data['options']);
})->pluck('middleware')->all();
return (new Collection($controller->getMiddleware()))
->reject(fn ($data) => static::methodExcludedByOptions($method, $data['options']))
->pluck('middleware')
->all();
}
}
9 changes: 5 additions & 4 deletions src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,9 @@ public function resolveMiddleware(array $middleware, array $excluded = [])
->values()
->all();

$middleware = (new Collection($middleware))->map(function ($name) {
return (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups);
})->flatten()
$middleware = (new Collection($middleware))
->map(fn ($name) => (array) MiddlewareNameResolver::resolve($name, $this->middleware, $this->middlewareGroups))
->flatten()
->when(
! empty($excluded),
fn ($collection) => $collection->reject(function ($name) use ($excluded) {
Expand All @@ -861,7 +861,8 @@ public function resolveMiddleware(array $middleware, array $excluded = [])
fn ($exclude) => class_exists($exclude) && $reflection->isSubclassOf($exclude)
);
})
)->values();
)
->values();

return $this->sortMiddleware($middleware);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Illuminate/Testing/ParallelConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ public function __construct($output)
*/
public function write($messages, bool $newline = false, int $options = 0): void
{
$messages = (new Collection($messages))->filter(function ($message) {
return ! Str::contains($message, $this->ignore);
});
$messages = (new Collection($messages))
->filter(fn ($message) => ! Str::contains($message, $this->ignore));

$this->output->write($messages->toArray(), $newline, $options);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Validation/Rules/DatabaseRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public function queryCallbacks()
*/
protected function formatWheres()
{
return (new Collection($this->wheres))->map(function ($where) {
return $where['column'].','.'"'.str_replace('"', '""', $where['value']).'"';
})->implode(',');
return (new Collection($this->wheres))
->map(fn ($where) => $where['column'].','.'"'.str_replace('"', '""', $where['value']).'"')
->implode(',');
}
}
6 changes: 3 additions & 3 deletions src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,9 @@ public function component($class, $alias = null, $prefix = '')

if (is_null($alias)) {
$alias = str_contains($class, '\\View\\Components\\')
? (new Collection(explode('\\', Str::after($class, '\\View\\Components\\'))))->map(function ($segment) {
return Str::kebab($segment);
})->implode(':')
? (new Collection(explode('\\', Str::after($class, '\\View\\Components\\'))))
->map(fn ($segment) => Str::kebab($segment))
->implode(':')
: Str::kebab(class_basename($class));
}

Expand Down