mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-02 09:20:52 +00:00
[DeadCode] Skip used in Closure use on RemoveUnusedConstructorParamRector (#2341)
This commit is contained in:
parent
b4120a8850
commit
fef1a03955
|
@ -0,0 +1,15 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector\Fixture;
|
||||
|
||||
final class SkipUsedInClosureUse
|
||||
{
|
||||
public function __construct($hey, $man)
|
||||
{
|
||||
echo $hey . ' ';
|
||||
|
||||
(function () use ($man) {
|
||||
echo $man;
|
||||
})();
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Rector\Core\NodeAnalyzer;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\NullableType;
|
||||
|
@ -28,11 +29,21 @@ final class ParamAnalyzer
|
|||
return (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped($classMethod, function (Node $node) use (
|
||||
$param
|
||||
): bool {
|
||||
if (! $node instanceof Variable) {
|
||||
if (! $node instanceof Variable && ! $node instanceof Closure) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->nodeComparator->areNodesEqual($node, $param->var);
|
||||
if ($node instanceof Variable) {
|
||||
return $this->nodeComparator->areNodesEqual($node, $param->var);
|
||||
}
|
||||
|
||||
foreach ($node->uses as $use) {
|
||||
if ($this->nodeComparator->areNodesEqual($use->var, $param->var)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user