diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/simple_array_merge.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/simple_array_merge.php.inc new file mode 100644 index 00000000000..82c80916eb9 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/simple_array_merge.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/skip_simple_array_merge.php.inc b/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/skip_simple_array_merge.php.inc deleted file mode 100644 index fd4c55fef4c..00000000000 --- a/rules-tests/CodingStyle/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector/FixturePhp81/skip_simple_array_merge.php.inc +++ /dev/null @@ -1,11 +0,0 @@ -value; - if ($this->shouldSkipArrayForInvalidTypeOrKeys($value)) { + if ($this->shouldSkipArrayForInvalidKeys($value)) { return null; } @@ -134,29 +130,16 @@ private function refactorArray(FuncCall $funcCall): ?Array_ return $array; } - private function shouldSkipArrayForInvalidTypeOrKeys(Expr $expr): bool + private function shouldSkipArrayForInvalidKeys(Expr $expr): bool { - // we have no idea what it is → cannot change it - if (! $this->arrayTypeAnalyzer->isArrayType($expr)) { - return true; - } - - $arrayStaticType = $this->getType($expr); - if (! $arrayStaticType instanceof ArrayType && ! $arrayStaticType instanceof ConstantArrayType) { - return true; - } + $type = $this->getType($expr); - return ! $this->isArrayKeyTypeAllowed($arrayStaticType); - } - - private function isArrayKeyTypeAllowed(ArrayType|ConstantArrayType $arrayType): bool - { - if ($arrayType->getIterableKeyType()->isInteger()->yes()) { - return true; + if ($type->getIterableKeyType()->isInteger()->yes()) { + return false; } // php 8.1+ allow mixed key: int, string, and null - return $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS); + return ! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ARRAY_SPREAD_STRING_KEYS); } private function resolveValue(Expr $expr): Expr