diff --git a/rules-tests/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector/Fixture/name_id_to_integer_index.php.inc b/rules-tests/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector/Fixture/name_id_to_integer_index.php.inc new file mode 100644 index 00000000..5df6fcba --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector/Fixture/name_id_to_integer_index.php.inc @@ -0,0 +1,31 @@ +id) { + + } +} + +?> +----- + diff --git a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php index 020fc3f1..b46d5974 100644 --- a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php +++ b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php @@ -111,7 +111,8 @@ private function refactorMethodCall(MethodCall $methodCall): ?Ternary private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary { - if (! $this->isName($propertyFetch->name, 'text')) { + $propertyFetchName = $this->getName($propertyFetch->name); + if (! in_array($propertyFetchName, ['id', 'text'], true)) { return null; } @@ -120,7 +121,10 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary } $isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($propertyFetch->var)]); - $arrayDimFetch = new ArrayDimFetch($propertyFetch->var, new LNumber(1)); + $arrayDimFetch = new ArrayDimFetch( + $propertyFetch->var, + $propertyFetchName === 'id' ? new LNumber(0) : new LNumber(1) + ); return new Ternary($isArrayFuncCall, $arrayDimFetch, $propertyFetch->var); }