Skip to content

Commit

Permalink
[CodeQuality] Skip empty array push args and no 2nd arg on ChangeArra…
Browse files Browse the repository at this point in the history
…yPushToArrayAssignRector (#2266)

* [CodeQuality] Skip empty array push args and no 2nd arg on ChangeArrayPushToArrayAssignRector

* Fixed 🎉
  • Loading branch information
samsonasik committed May 8, 2022
1 parent 88c9b8e commit ae2e38e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector\Fixture;

class SkipEmptyArgs
{
public function run()
{
array_push();

echo 'test';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector\Fixture;

class SkipNoSecondArg
{
public function run(array $items)
{
array_push($items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,17 @@ public function refactor(Node $node): ?array

$args = $funcCall->getArgs();

if ($args === []) {
return null;
}

/** @var Arg $firstArg */
$firstArg = array_shift($args);

if ($args === []) {
return null;
}

$arrayDimFetch = new ArrayDimFetch($firstArg->value);

$newStmts = [];
Expand Down

0 comments on commit ae2e38e

Please sign in to comment.