From ef614a2be1246263468a5cb4da31674bd75b0327 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 6 Aug 2025 21:38:52 +0700 Subject: [PATCH 1/2] [TypeDeclaration] Skip ArrayAccess as array item type on AddArrowFunctionParamArrayWhereDimFetchRector --- ...ddArrowFunctionParamArrayWhereDimFetchRector.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php b/rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php index 9f8ae4c813f..9e404ea0acc 100644 --- a/rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php +++ b/rules/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector.php @@ -4,14 +4,15 @@ namespace Rector\TypeDeclaration\Rector\FuncCall; -use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; +use PhpParser\Node\Expr\Instanceof_; +use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; +use PHPStan\Type\ArrayType; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\Rector\AbstractRector; use Rector\TypeDeclaration\Enum\NativeFuncCallPositions; @@ -85,6 +86,9 @@ public function refactor(Node $node): ?Node continue; } + $arrayPosition = $positions['array']; + $closureItems = $node->getArgs()[$arrayPosition]->value; + $isArrayVariableNames = $this->resolveIsArrayVariables($closureExpr); $instanceofVariableNames = $this->resolveInstanceofVariables($closureExpr); $skippedVariableNames = array_merge($isArrayVariableNames, $instanceofVariableNames); @@ -106,6 +110,11 @@ public function refactor(Node $node): ?Node continue; } + $type = $this->getType($closureItems); + if ($type instanceof ArrayType && $type->getItemType()->isObject()->yes()) { + continue; + } + $hasChanged = true; $closureParam->type = new Identifier('array'); } From 294254f4b32cb7507d2974dd94e11d4664e1c165 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 6 Aug 2025 21:38:56 +0700 Subject: [PATCH 2/2] [TypeDeclaration] Skip ArrayAccess as array item type on AddArrowFunctionParamArrayWhereDimFetchRector --- .../Fixture/skip_array_access_type.php.inc | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector/Fixture/skip_array_access_type.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector/Fixture/skip_array_access_type.php.inc b/rules-tests/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector/Fixture/skip_array_access_type.php.inc new file mode 100644 index 00000000000..2cfddb62ace --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/FuncCall/AddArrowFunctionParamArrayWhereDimFetchRector/Fixture/skip_array_access_type.php.inc @@ -0,0 +1,17 @@ +> $items + */ + public function run(array $items) + { + usort( + $items, + fn ($a, $b): int => $a['key'] <=> $b['key'] + ); + } +}