Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions rules/DeadCode/Rector/Node/RemoveNonExistingVarAnnotationRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\MultiInstanceofChecker;
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -34,25 +33,8 @@
*/
final class RemoveNonExistingVarAnnotationRector extends AbstractRector
{
/**
* @var array<class-string<Node>>
*/
private const NODES_TO_MATCH = [
Foreach_::class,
Static_::class,
Echo_::class,
Return_::class,
Expression::class,
Throw_::class,
If_::class,
While_::class,
Switch_::class,
Nop::class,
];

public function __construct(
private readonly ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer,
private readonly MultiInstanceofChecker $multiInstanceofChecker
private readonly ExprUsedInNodeAnalyzer $exprUsedInNodeAnalyzer
) {
}

Expand Down Expand Up @@ -92,7 +74,18 @@ public function get()
*/
public function getNodeTypes(): array
{
return [Node::class];
return [
Foreach_::class,
Static_::class,
Echo_::class,
Return_::class,
Expression::class,
Throw_::class,
If_::class,
While_::class,
Switch_::class,
Nop::class,
];
}

public function refactor(Node $node): ?Node
Expand Down Expand Up @@ -158,15 +151,7 @@ private function isUsedInNextNodeWithExtractPreviouslyCalled(Node $node, string

private function shouldSkip(Node $node): bool
{
if (! $node instanceof Nop) {
return ! $this->multiInstanceofChecker->isInstanceOf($node, self::NODES_TO_MATCH);
}

if (count($node->getComments()) <= 1) {
return ! $this->multiInstanceofChecker->isInstanceOf($node, self::NODES_TO_MATCH);
}

return true;
return count($node->getComments()) !== 1;
}

private function hasVariableName(Node $node, string $variableName): bool
Expand Down