Skip to content

Commit

Permalink
[12.x] Use first-class callable syntax to improve static analysis (#5…
Browse files Browse the repository at this point in the history
…3924)

* Use first-class callable syntax

to improve static analysis

* Fix syntax error

* Revert first-class callable syntax for possibly non-existing methods
  • Loading branch information
shaedrich authored Dec 16, 2024
1 parent 8660d95 commit bacbc4b
Show file tree
Hide file tree
Showing 29 changed files with 48 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected function setEventDispatcher(Repository $repository)
*/
public function refreshEventDispatcher()
{
array_map([$this, 'setEventDispatcher'], $this->stores);
array_map($this->setEventDispatcher(...), $this->stores);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Cache/TagSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(Store $store, array $names = [])
*/
public function reset()
{
array_walk($this->names, [$this, 'resetTag']);
array_walk($this->names, $this->resetTag(...));
}

/**
Expand All @@ -63,7 +63,7 @@ public function resetTag($name)
*/
public function flush()
{
array_walk($this->names, [$this, 'flushTag']);
array_walk($this->names, $this->flushTag(...));
}

/**
Expand Down Expand Up @@ -93,7 +93,7 @@ public function getNamespace()
*/
protected function tagIds()
{
return array_map([$this, 'tagId'], $this->names);
return array_map($this->tagId(...), $this->names);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function doesntContain($key, $operator = null, $value = null)
public function crossJoin(...$lists)
{
return new static(Arr::crossJoin(
$this->items, ...array_map([$this, 'getArrayableItems'], $lists)
$this->items, ...array_map($this->getArrayableItems(...), $lists)
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ public function mapToGroups(callable $callback)
{
$groups = $this->mapToDictionary($callback);

return $groups->map([$this, 'make']);
return $groups->map($this->make(...));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Console/Scheduling/ScheduleListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function handle(Schedule $schedule)
*/
private function getCronExpressionSpacing($events)
{
$rows = $events->map(fn ($event) => array_map('mb_strlen', preg_split("/\s+/", $event->expression)));
$rows = $events->map(fn ($event) => array_map(mb_strlen(...), preg_split("/\s+/", $event->expression)));

return (new Collection($rows[0] ?? []))->keys()->map(fn ($key) => $rows->max($key))->all();
}
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class Grammar
*/
public function wrapArray(array $values)
{
return array_map([$this, 'wrap'], $values);
return array_map($this->wrap(...), $values);
}

/**
Expand Down Expand Up @@ -186,7 +186,7 @@ protected function isJsonSelector($value)
*/
public function columnize(array $columns)
{
return implode(', ', array_map([$this, 'wrap'], $columns));
return implode(', ', array_map($this->wrap(...), $columns));
}

/**
Expand All @@ -197,7 +197,7 @@ public function columnize(array $columns)
*/
public function parameterize(array $values)
{
return implode(', ', array_map([$this, 'parameter'], $values));
return implode(', ', array_map($this->parameter(...), $values));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4220,7 +4220,7 @@ public function addBinding($value, $type = 'where')

if (is_array($value)) {
$this->bindings[$type] = array_values(array_map(
[$this, 'castBinding'],
$this->castBinding(...),
array_merge($this->bindings[$type], $value),
));
} else {
Expand Down Expand Up @@ -4270,7 +4270,7 @@ public function cleanBindings(array $bindings)
->reject(function ($binding) {
return $binding instanceof ExpressionContract;
})
->map([$this, 'castBinding'])
->map($this->castBinding(...))
->values()
->all();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function getTypes()
public function hasColumn($table, $column)
{
return in_array(
strtolower($column), array_map('strtolower', $this->getColumnListing($table))
strtolower($column), array_map(strtolower(...), $this->getColumnListing($table))
);
}

Expand All @@ -252,7 +252,7 @@ public function hasColumn($table, $column)
*/
public function hasColumns($table, array $columns)
{
$tableColumns = array_map('strtolower', $this->getColumnListing($table));
$tableColumns = array_map(strtolower(...), $this->getColumnListing($table));

foreach ($columns as $column) {
if (! in_array(strtolower($column), $tableColumns)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/AliasLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function register()
*/
protected function prependToLoaderStack()
{
spl_autoload_register([$this, 'load'], true, true);
spl_autoload_register($this->load(...), true, true);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Foundation/Console/RouteListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ protected function getHeaders()
*/
protected function getColumns()
{
return array_map('strtolower', $this->headers);
return array_map(strtolower(...), $this->headers);
}

/**
Expand All @@ -320,7 +320,7 @@ protected function parseColumns(array $columns)
}
}

return array_map('strtolower', $results);
return array_map(strtolower(...), $results);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Exceptions/Renderer/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Listener
*/
public function registerListeners(Dispatcher $events)
{
$events->listen(QueryExecuted::class, [$this, 'onQueryExecuted']);
$events->listen(QueryExecuted::class, $this->onQueryExecuted(...));

$events->listen([JobProcessing::class, JobProcessed::class], function () {
$this->queries = [];
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Http/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function getValidatorInstance()
$factory = $this->container->make(ValidationFactory::class);

if (method_exists($this, 'validator')) {
$validator = $this->container->call([$this, 'validator'], compact('factory'));
$validator = $this->container->call($this->validator(...), compact('factory'));
} else {
$validator = $this->createDefaultValidator($factory);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Http/Middleware/TrustProxies.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected function setTrustedProxyIpAddresses(Request $request)
}

$trustedIps = is_string($trustedIps)
? array_map('trim', explode(',', $trustedIps))
? array_map(trim(...), explode(',', $trustedIps))
: $trustedIps;

if (is_array($trustedIps)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ public function assertDontSeeInHtml($string, $escape = true)
*/
public function assertSeeInOrderInHtml($strings, $escape = true)
{
$strings = $escape ? array_map('e', $strings) : $strings;
$strings = $escape ? array_map(e(...), $strings) : $strings;

[$html, $text] = $this->renderForAssertions();

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Notifications/Messages/SimpleMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ protected function formatLine($line)
}

if (is_array($line)) {
return implode(' ', array_map('trim', $line));
return implode(' ', array_map(trim(...), $line));
}

return trim(implode(' ', array_map('trim', preg_split('/\\r\\n|\\r|\\n/', $line ?? ''))));
return trim(implode(' ', array_map(trim(...), preg_split('/\\r\\n|\\r|\\n/', $line ?? ''))));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Redis/Connections/PacksPhpRedisValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function pack(array $values): array
}

if ($this->supportsPacking()) {
return array_map([$this->client, '_pack'], $values);
return array_map($this->client->_pack(...), $values);
}

if ($this->compressed()) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Redis/Connectors/PhpRedisConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function connectToCluster(array $config, array $clusterOptions, array $op
$options = array_merge($options, $clusterOptions, Arr::pull($config, 'options', []));

return new PhpRedisClusterConnection($this->createRedisClusterInstance(
array_map([$this, 'buildClusterConnectionString'], $config), $options
array_map($this->buildClusterConnectionString(...), $config), $options
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function view($uri, $view, $data = [], $status = 200, array $headers = []
*/
public function match($methods, $uri, $action = null)
{
return $this->addRoute(array_map('strtoupper', (array) $methods), $uri, $action);
return $this->addRoute(array_map(strtoupper(...), (array) $methods), $uri, $action);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/ConfigurationUrlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function parseConfiguration($config)
$rawComponents = $this->parseUrl($url);

$decodedComponents = $this->parseStringsToNativeTypes(
array_map('rawurldecode', $rawComponents)
array_map(rawurldecode(...), $rawComponents)
);

return array_merge(
Expand Down Expand Up @@ -151,7 +151,7 @@ protected function parseUrl($url)
protected function parseStringsToNativeTypes($value)
{
if (is_array($value)) {
return array_map([$this, 'parseStringsToNativeTypes'], $value);
return array_map($this->parseStringsToNativeTypes(...), $value);
}

if (! is_string($value)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,8 @@ public static function headline($value)
$parts = explode(' ', $value);

$parts = count($parts) > 1
? array_map([static::class, 'title'], $parts)
: array_map([static::class, 'title'], static::ucsplit(implode('_', $parts)));
? array_map(static::title(...), $parts)
: array_map(static::title(...), static::ucsplit(implode('_', $parts)));

$collapsed = static::replace(['-', '_', ' '], '_', implode('_', $parts));

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Testing/Fakes/ExceptionHandlerFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function assertReported(Closure|string $exception)

if (is_string($exception)) {
Assert::assertTrue(
in_array($exception, array_map('get_class', $this->reported), true),
in_array($exception, array_map(get_class(...), $this->reported), true),
$message,
);

Expand Down Expand Up @@ -135,7 +135,7 @@ public function assertNothingReported()
$this->reported,
sprintf(
'The following exceptions were reported: %s.',
implode(', ', array_map('get_class', $this->reported)),
implode(', ', array_map(get_class(...), $this->reported)),
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/TestComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function assertSee($value, $escape = true)
*/
public function assertSeeInOrder(array $values, $escape = true)
{
$values = $escape ? array_map('e', $values) : $values;
$values = $escape ? array_map(e(...), $values) : $values;

PHPUnit::assertThat($values, new SeeInOrder($this->rendered));

Expand Down Expand Up @@ -93,7 +93,7 @@ public function assertSeeText($value, $escape = true)
*/
public function assertSeeTextInOrder(array $values, $escape = true)
{
$values = $escape ? array_map('e', $values) : $values;
$values = $escape ? array_map(e(...), $values) : $values;

PHPUnit::assertThat($values, new SeeInOrder(strip_tags($this->rendered)));

Expand Down
12 changes: 6 additions & 6 deletions src/Illuminate/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function assertSee($value, $escape = true)
{
$value = Arr::wrap($value);

$values = $escape ? array_map('e', $value) : $value;
$values = $escape ? array_map(e(...), $value) : $value;

foreach ($values as $value) {
PHPUnit::withResponse($this)->assertStringContainsString((string) $value, $this->getContent());
Expand Down Expand Up @@ -596,7 +596,7 @@ public function assertSeeHtml($value)
*/
public function assertSeeInOrder(array $values, $escape = true)
{
$values = $escape ? array_map('e', $values) : $values;
$values = $escape ? array_map(e(...), $values) : $values;

PHPUnit::withResponse($this)->assertThat($values, new SeeInOrder($this->getContent()));

Expand Down Expand Up @@ -625,7 +625,7 @@ public function assertSeeText($value, $escape = true)
{
$value = Arr::wrap($value);

$values = $escape ? array_map('e', $value) : $value;
$values = $escape ? array_map(e(...), $value) : $value;

$content = strip_tags($this->getContent());

Expand All @@ -645,7 +645,7 @@ public function assertSeeText($value, $escape = true)
*/
public function assertSeeTextInOrder(array $values, $escape = true)
{
$values = $escape ? array_map('e', $values) : $values;
$values = $escape ? array_map(e(...), $values) : $values;

PHPUnit::withResponse($this)->assertThat($values, new SeeInOrder(strip_tags($this->getContent())));

Expand All @@ -663,7 +663,7 @@ public function assertDontSee($value, $escape = true)
{
$value = Arr::wrap($value);

$values = $escape ? array_map('e', $value) : $value;
$values = $escape ? array_map(e(...), $value) : $value;

foreach ($values as $value) {
PHPUnit::withResponse($this)->assertStringNotContainsString((string) $value, $this->getContent());
Expand Down Expand Up @@ -694,7 +694,7 @@ public function assertDontSeeText($value, $escape = true)
{
$value = Arr::wrap($value);

$values = $escape ? array_map('e', $value) : $value;
$values = $escape ? array_map(e(...), $value) : $value;

$content = strip_tags($this->getContent());

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Testing/TestView.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function assertSee($value, $escape = true)
*/
public function assertSeeInOrder(array $values, $escape = true)
{
$values = $escape ? array_map('e', $values) : $values;
$values = $escape ? array_map(e(...), $values) : $values;

PHPUnit::assertThat($values, new SeeInOrder($this->rendered));

Expand Down Expand Up @@ -176,7 +176,7 @@ public function assertSeeText($value, $escape = true)
*/
public function assertSeeTextInOrder(array $values, $escape = true)
{
$values = $escape ? array_map('e', $values) : $values;
$values = $escape ? array_map(e(...), $values) : $values;

PHPUnit::assertThat($values, new SeeInOrder(strip_tags($this->rendered)));

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Rules/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected function buildValidationRules()
$rules = array_merge($rules, $this->buildMimetypes());

if (! empty($this->allowedExtensions)) {
$rules[] = 'extensions:'.implode(',', array_map('strtolower', $this->allowedExtensions));
$rules[] = 'extensions:'.implode(',', array_map(strtolower(...), $this->allowedExtensions));
}

$rules[] = match (true) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/ValidationRuleParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function explodeExplicitRule($rule, $attribute)
}

return array_map(
[$this, 'prepareRule'],
$this->prepareRule(...),
$rule,
array_fill((int) array_key_first($rule), count($rule), $attribute)
);
Expand Down
Loading

0 comments on commit bacbc4b

Please sign in to comment.