mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 11:44:14 +01:00
Fix RemoveUnusedPrivateMethodRector for this calls
This commit is contained in:
parent
71f1af830c
commit
a92ae429f0
@ -0,0 +1,22 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
|
||||
final class KeepUsedMethod
|
||||
{
|
||||
public function processArgumentPosition(Node $node, int $argumentPosition): ?Node
|
||||
{
|
||||
$this->findPreviousNodeAssign($node, $argumentPosition);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function findPreviousNodeAssign(Node $node, Node $firstArgument): ?Assign
|
||||
{
|
||||
return $this->betterNodeFinder->findFirstPrevious($node, function (Node $checkedNode) use ($firstArgument) {
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
|
||||
final class KeepUsedMethodStatic
|
||||
{
|
||||
public function processArgumentPosition(Node $node, int $argumentPosition): ?Node
|
||||
{
|
||||
self::findPreviousNodeAssign($node, $argumentPosition);
|
||||
}
|
||||
|
||||
private static function findPreviousNodeAssign(Node $node, Node $firstArgument): ?Assign
|
||||
{
|
||||
return $this->betterNodeFinder->findFirstPrevious($node, function (Node $checkedNode) use ($firstArgument) {
|
||||
});
|
||||
}
|
||||
}
|
@ -17,6 +17,8 @@ final class RemoveUnusedPrivateMethodRectorTest extends AbstractRectorTestCase
|
||||
__DIR__ . '/Fixture/keep_anonymous.php.inc',
|
||||
__DIR__ . '/Fixture/skip_local_called.php.inc',
|
||||
__DIR__ . '/Fixture/keep_in_trait.php.inc',
|
||||
__DIR__ . '/Fixture/keep_used_method.php.inc',
|
||||
__DIR__ . '/Fixture/keep_used_method_static.php.inc',
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -525,7 +525,12 @@ final class ParsedNodesByType
|
||||
*/
|
||||
private function addCall(Node $node): void
|
||||
{
|
||||
$className = $this->nodeTypeResolver->resolve($node)[0] ?? null;
|
||||
if ($node instanceof MethodCall && $node->var instanceof Node\Expr\Variable && $node->var->name === 'this') {
|
||||
$className = $node->getAttribute(AttributeKey::CLASS_NAME);
|
||||
} else {
|
||||
$className = $this->nodeTypeResolver->resolve($node)[0] ?? null;
|
||||
}
|
||||
|
||||
if ($className === null) { // anonymous
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user