Skip to content

Commit

Permalink
[DeadCode] Do not remove class method if required by parent ocntract
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 2, 2021
1 parent 3ccca63 commit a920e9e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Rector\DeadCode\NodeAnalyzer\DataProviderMethodNamesResolver;
use Rector\NodeCollector\ValueObject\ArrayCallable;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VendorLocker\NodeVendorLocker\ClassMethodReturnVendorLockResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;

Expand All @@ -32,9 +33,17 @@ final class RemoveUnusedPublicMethodRector extends AbstractRector implements Zer
*/
private $calls = [];

public function __construct(DataProviderMethodNamesResolver $dataProviderMethodNamesResolver)
{
/**
* @var ClassMethodReturnVendorLockResolver
*/
private $classMethodReturnVendorLockResolver;

public function __construct(
DataProviderMethodNamesResolver $dataProviderMethodNamesResolver,
ClassMethodReturnVendorLockResolver $classMethodReturnVendorLockResolver
) {
$this->dataProviderMethodNamesResolver = $dataProviderMethodNamesResolver;
$this->classMethodReturnVendorLockResolver = $classMethodReturnVendorLockResolver;
}

public function getRuleDefinition(): RuleDefinition
Expand Down Expand Up @@ -128,6 +137,10 @@ private function shouldSkip(ClassMethod $classMethod): bool
return true;
}

if ($this->classMethodReturnVendorLockResolver->isVendorLocked($classMethod)) {
return true;
}

if ($classMethod->isMagic()) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedPublicMethodRector\Fixture;

use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use Rector\Core\Contract\Rector\PhpRectorInterface;

final class SkipRequiredByContract extends NodeVisitorAbstract implements PhpRectorInterface
{
public function getNodeTypes(): array
{
}

public function refactor(Node $node): ?Node
{
}
}

0 comments on commit a920e9e

Please sign in to comment.