diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index 15d62355..e304152f 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -13,7 +13,6 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Name; use PHPStan\Analyser\MutatingScope; -use PHPStan\Type\ArrayType; use PHPStan\Type\IterableType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; @@ -85,7 +84,7 @@ private function createArrayMergeFuncCall(array $arrayItems, MutatingScope $muta return $this->createArgFromSpreadArrayItem($mutatingScope, $arrayItem); } - return new Arg($arrayItem); + return new Arg($arrayItem->value); }, $arrayItems); return new FuncCall(new Name('array_merge'), $args); @@ -121,13 +120,13 @@ private function createArgFromSpreadArrayItem(MutatingScope $mutatingScope, Arra } } - $iteratorToArrayFuncCall = new FuncCall(new Name('iterator_to_array'), [new Arg($arrayItem)]); + $iteratorToArrayFuncCall = new FuncCall(new Name('iterator_to_array'), [new Arg($arrayItem->value)]); // If we know it is an array, then print it directly // Otherwise PHPStan throws an error: // "Else branch is unreachable because ternary operator condition is always true." - if ($type instanceof ArrayType) { - return new Arg($arrayItem); + if ($type->isArray()->yes()) { + return new Arg($arrayItem->value); } // If it is iterable, then directly return `iterator_to_array` @@ -136,8 +135,8 @@ private function createArgFromSpreadArrayItem(MutatingScope $mutatingScope, Arra } // Print a ternary, handling either an array or an iterator - $inArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($arrayItem)]); - return new Arg(new Ternary($inArrayFuncCall, $arrayItem, $iteratorToArrayFuncCall)); + $inArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($arrayItem->value)]); + return new Arg(new Ternary($inArrayFuncCall, $arrayItem->value, $iteratorToArrayFuncCall)); } /** diff --git a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php index b5ed83cd..4bfc177f 100644 --- a/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php +++ b/rules/DowngradePhp81/Rector/Array_/DowngradeArraySpreadStringKeyRector.php @@ -4,6 +4,7 @@ namespace Rector\DowngradePhp81\Rector\Array_; +use PHPStan\Type\Constant\ConstantArrayType; use PhpParser\Node; use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; @@ -89,10 +90,11 @@ private function shouldSkipArray(Array_ $array): bool } $type = $this->nodeTypeResolver->getType($item->value); - if (! $type instanceof ArrayType) { + if (! $type->isArray()->yes()) { continue; } + /** @var ArrayType|ConstantArrayType $type */ $keyType = $type->getKeyType(); if ($keyType instanceof IntegerType) { return true;