Skip to content

Commit

Permalink
allow shutdown function name at CallableThisArrayToAnonymousFunctionR…
Browse files Browse the repository at this point in the history
…ector
  • Loading branch information
TomasVotruba committed Dec 30, 2019
1 parent 8121742 commit 6c9ed81
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
Expand Down Expand Up @@ -133,7 +134,15 @@ private function shouldSkipArray(Array_ $array): bool
}

// 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');
}

/**
Expand Down Expand Up @@ -241,4 +250,19 @@ private function copyParams(array $params): array

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);
}
}
Original file line number Diff line number Diff line change
@@ -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()
{
}
}

0 comments on commit 6c9ed81

Please sign in to comment.