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
4 changes: 4 additions & 0 deletions config/set/php81.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

declare(strict_types=1);

use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector;
use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Php81\Rector\Class_\MyCLabsClassToEnumRector;
Expand All @@ -26,7 +27,10 @@
SpatieEnumMethodCallToEnumConstRector::class,
NullToStrictStringFuncCallArgRector::class,
NullToStrictIntPregSlitFuncCallLimitArgRector::class,
// array of local method call
FirstClassCallableRector::class,
// closure/arrow function
FunctionLikeToFirstClassCallableRector::class,
RemoveReflectionSetAccessibleCallsRector::class,
]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

final class ArrayMap
{
public function call($items)
{
array_map(fn($x) => strlen($x), $items);
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

final class ArrayMap
{
public function call($items)
{
array_map(strlen(...), $items);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

final class MultipleParams
{
public function call($items)
{
usort($items, fn($a, $b) => strcmp($a, $b));
}
}

?>
-----
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

final class MultipleParams
{
public function call($items)
{
usort($items, strcmp(...));
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ final class FunctionLikeToFirstClassCallableRector extends AbstractRector
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'converts function like to first class callable',
'Converts arrow function and closures to first class callable',
[new CodeSample(
<<<'CODE_SAMPLE'
function ($parameter) { return Call::to($parameter); }
function ($parameter) {
return Call::to($parameter);
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function hasCallLikeInAssignExpr(Expr $expr): bool
{
return (bool) $this->betterNodeFinder->findFirst(
$expr,
fn (Node $subNode): bool => $this->sideEffectNodeDetector->detectCallExpr($subNode)
$this->sideEffectNodeDetector->detectCallExpr(...)
);
}

Expand Down
2 changes: 1 addition & 1 deletion rules/DeadCode/SideEffect/SideEffectNodeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function detect(Expr $expr): bool

return (bool) $this->betterNodeFinder->findFirst(
$expr,
fn (Node $subNode): bool => $this->detectCallExpr($subNode)
$this->detectCallExpr(...)
);
}

Expand Down
2 changes: 1 addition & 1 deletion rules/Php81/NodeFactory/EnumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ private function collectMappings(array $items, array $mapping): array
*/
private function getIdentifierTypeFromMappings(array $mapping): string
{
$callableGetType = static fn ($value): string => gettype($value);
$callableGetType = gettype(...);
$valueTypes = array_map($callableGetType, $mapping);
$uniqueValueTypes = array_unique($valueTypes);
if (count($uniqueValueTypes) === 1) {
Expand Down
3 changes: 1 addition & 2 deletions src/Configuration/RectorConfigBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ public function __invoke(RectorConfig $rectorConfig): void
{
if ($this->setGroups !== [] || $this->setProviders !== []) {
$setProviderCollector = new SetProviderCollector(array_map(
static fn (string $setProvider): SetProviderInterface =>
$rectorConfig->make($setProvider),
$rectorConfig->make(...),
\array_keys($this->setProviders)
));

Expand Down
4 changes: 2 additions & 2 deletions src/FileSystem/FileAndDirectoryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class FileAndDirectoryFilter
*/
public function filterDirectories(array $filesAndDirectories): array
{
$directories = array_filter($filesAndDirectories, static fn (string $path): bool => is_dir($path));
$directories = array_filter($filesAndDirectories, is_dir(...));

return array_values($directories);
}
Expand All @@ -26,7 +26,7 @@ public function filterDirectories(array $filesAndDirectories): array
*/
public function filterFiles(array $filesAndDirectories): array
{
$files = array_filter($filesAndDirectories, static fn (string $path): bool => is_file($path));
$files = array_filter($filesAndDirectories, is_file(...));

return array_values($files);
}
Expand Down
2 changes: 1 addition & 1 deletion src/FileSystem/FilesystemTweaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ private function foundInGlob(string $path): array
/** @var string[] $paths */
$paths = (array) glob($path);

return array_filter($paths, static fn (string $path): bool => file_exists($path));
return array_filter($paths, file_exists(...));
}
}
2 changes: 1 addition & 1 deletion src/Util/ArrayParametersMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function merge(mixed $left, mixed $right): mixed
return $this->mergeLeftToRightWithCallable(
$left,
$right,
fn ($leftValue, $rightValue): mixed => $this->merge($leftValue, $rightValue)
$this->merge(...)
);
}

Expand Down