diff --git a/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php b/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php index 265a5d51db2..2cd215d6c6d 100644 --- a/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php +++ b/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php @@ -66,6 +66,12 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + // no kind attribute yet, it means just created + // no need to reprint, it already will be short array by default + if (! $node->hasAttribute(AttributeKey::KIND)) { + return null; + } + if ($node->getAttribute(AttributeKey::KIND) === Array_::KIND_SHORT) { return null; } diff --git a/tests/Issues/CountArrayLongToShort/CountArrayLongToShortTest.php b/tests/Issues/CountArrayLongToShort/CountArrayLongToShortTest.php new file mode 100644 index 00000000000..f7377e4a126 --- /dev/null +++ b/tests/Issues/CountArrayLongToShort/CountArrayLongToShortTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Issues/CountArrayLongToShort/Fixture/count_to_empty_array_compare.php.inc b/tests/Issues/CountArrayLongToShort/Fixture/count_to_empty_array_compare.php.inc new file mode 100644 index 00000000000..7008101cb70 --- /dev/null +++ b/tests/Issues/CountArrayLongToShort/Fixture/count_to_empty_array_compare.php.inc @@ -0,0 +1,33 @@ + +----- + diff --git a/tests/Issues/CountArrayLongToShort/config/configured_rule.php b/tests/Issues/CountArrayLongToShort/config/configured_rule.php new file mode 100644 index 00000000000..004fa448b35 --- /dev/null +++ b/tests/Issues/CountArrayLongToShort/config/configured_rule.php @@ -0,0 +1,13 @@ +withRules([ + CountArrayToEmptyArrayComparisonRector::class, + LongArrayToShortArrayRector::class, + ]); \ No newline at end of file