diff --git a/packages/CodeQuality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php b/packages/CodeQuality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php index a284fb6a40a..b48878f3a3a 100644 --- a/packages/CodeQuality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php +++ b/packages/CodeQuality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php @@ -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); + } } diff --git a/packages/CodeQuality/tests/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_error_handler_shutdown.php.inc b/packages/CodeQuality/tests/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_error_handler_shutdown.php.inc new file mode 100644 index 00000000000..8b5980c88ca --- /dev/null +++ b/packages/CodeQuality/tests/Rector/Array_/CallableThisArrayToAnonymousFunctionRector/Fixture/skip_error_handler_shutdown.php.inc @@ -0,0 +1,15 @@ +