allow shutdown function name at CallableThisArrayToAnonymousFunctionRector

This commit is contained in:
TomasVotruba 2019-12-30 15:04:45 +01:00
parent 36523e970a
commit cba238c308
2 changed files with 40 additions and 1 deletions

View File

@ -10,6 +10,7 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ClosureUse;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
@ -133,7 +134,15 @@ PHP
}
// can be totally empty in case of "[, $value]"
return $array->items[0] === null;
if ($array->items[0] === null) {
return true;
}
if ($array->items[1] === null) {
return true;
}
return $this->isCallbackAtFunctionName($array, 'register_shutdown_function');
}
/**
@ -241,4 +250,19 @@ PHP
return $newParams;
}
private function isCallbackAtFunctionName(Array_ $array, string $functionName): bool
{
$parentNode = $array->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentNode instanceof Arg) {
return false;
}
$parentParentNode = $parentNode->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentParentNode instanceof FuncCall) {
return false;
}
return $this->isName($parentParentNode, $functionName);
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace Rector\CodeQuality\Tests\Rector\Array_\CallableThisArrayToAnonymousFunctionRector\Fixture;
class SkipErrorHandlerShutdown
{
public function run()
{
register_shutdown_function([$this, 'shutdown_function']);
}
public function shutdown_function()
{
}
}