Skip to content

Commit

Permalink
feature: ArrayPushFixer now fix short arrays (#6639)
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Hasanov authored Oct 11, 2022
1 parent c626578 commit d47a339
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/Fixer/Alias/ArrayPushFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ private function getSecondArgumentEnd(Tokens $tokens, int $index, int $endIndex)
return null;
}

$index = $tokens->getNextMeaningfulToken($index);

for (; $index <= $endIndex; ++$index) {
$blockType = Tokens::detectBlockType($tokens[$index]);

Expand Down
24 changes: 24 additions & 0 deletions tests/Fixer/Alias/ArrayPushFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ public function provideFixCases(): iterable
',
];

yield 'simple traditional array' => [
'<?php $a[] = array($b, $c);',
'<?php array_push($a, array($b, $c));',
];

yield 'simple short array' => [
'<?php $a[] = [$b];',
'<?php array_push($a, [$b]);',
];

yield 'multiple element short array' => [
'<?php $a[] = [[], [], $b, $c];',
'<?php array_push($a, [[], [], $b, $c]);',
];

yield 'second argument wrapped in `(` `)`' => [
'<?php $a::$c[] = ($b);',
'<?php array_push($a::$c, ($b));',
];

yield [
'<?php $a::$c[] = $b;',
'<?php array_push($a::$c, $b);',
Expand Down Expand Up @@ -166,6 +186,10 @@ public function provideFixCases(): iterable
'<?php ; array_push($a6a, $b9->$a(1,2), $c);',
];

yield 'push multiple short' => [
'<?php array_push($a6, [$b,$c], []);',
];

yield 'returns number of elements in the array I' => [
'<?php foo(array_push($a7, $b10)); // ;array_push($a, $b);',
];
Expand Down

0 comments on commit d47a339

Please sign in to comment.