[CodeQuality] Skip empty array push args and no 2nd arg on ChangeArrayPushToArrayAssignRector (#2266)

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

* Fixed 🎉
This commit is contained in:
Abdul Malik Ikhsan 2022-05-08 18:15:42 +07:00 committed by GitHub
parent 88c9b8e20d
commit ae2e38ed98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace Rector\Tests\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector\Fixture;
class SkipEmptyArgs
{
public function run()
{
array_push();
echo 'test';
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace Rector\Tests\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector\Fixture;
class SkipNoSecondArg
{
public function run(array $items)
{
array_push($items);
}
}

View File

@ -70,9 +70,17 @@ CODE_SAMPLE
$args = $funcCall->getArgs();
if ($args === []) {
return null;
}
/** @var Arg $firstArg */
$firstArg = array_shift($args);
if ($args === []) {
return null;
}
$arrayDimFetch = new ArrayDimFetch($firstArg->value);
$newStmts = [];