Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ parameters:
identifier: symplify.noReference
message: '#Use explicit return value over magic &reference#'
paths:
- src/PhpDocParser/PhpDocParser/PhpDocNodeTraverser.php
- rules/Php70/EregToPcreTransformer.php
- src/BetterPhpDocParser/PhpDocManipulator/PhpDocClassRenamer.php
- src/NodeTypeResolver/PHPStan/Type/TypeFactory.php
Expand Down
11 changes: 5 additions & 6 deletions rules/CodingStyle/ClassNameImport/ShortNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassLike;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
Expand All @@ -17,7 +18,7 @@
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\ValueObject\Application\File;

Expand Down Expand Up @@ -176,10 +177,7 @@ private function resolveDocBlockShortNames(Node $node): array
}

$shortNames = [];
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable(
$phpDocInfo->getPhpDocNode(),
'',
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(
static function ($node) use (&$shortNames): null {
if ($node instanceof PhpDocTagNode) {
$shortName = trim($node->name, '@');
Expand All @@ -196,7 +194,8 @@ static function ($node) use (&$shortNames): null {

return null;
}
);
)]);
$phpDocNodeTraverser->traverse([$phpDocInfo->getPhpDocNode()]);

return $shortNames;
}
Expand Down
11 changes: 6 additions & 5 deletions rules/DeadCode/PhpDoc/TagRemover/ParamTagRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

use PhpParser\Node\FunctionLike;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\DeadCode\PhpDoc\DeadParamTagValueNodeAnalyzer;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;

final readonly class ParamTagRemover
{
Expand All @@ -29,8 +30,7 @@ public function removeParamTagsIfUseless(
): bool {
$hasChanged = false;

$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (Node $docNode) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(function (Node $docNode) use (
$functionLike,
&$hasChanged,
$type,
Expand Down Expand Up @@ -61,8 +61,9 @@ public function removeParamTagsIfUseless(
}

$hasChanged = true;
return PhpDocNodeTraverser::NODE_REMOVE;
});
return NodeTraverser::REMOVE_NODE;
})]);
$phpDocNodeTraverser->traverse([$phpDocInfo->getPhpDocNode()]);

if ($hasChanged) {
$this->docBlockUpdater->updateRefactoredNodeWithPhpDocInfo($functionLike);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\PhpDocParser\Ast\Node as PhpDocNode;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
Expand All @@ -18,7 +19,7 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
use Rector\RuleDoc\RuleDefinition;
Expand Down Expand Up @@ -113,8 +114,7 @@ private function removeMixedParamTags(PhpDocInfo $phpDocInfo, Node $functionLike

$hasChanged = false;

$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (PhpDocNode $phpDocNode) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(function (PhpDocNode $phpDocNode) use (
$declaredParamNames,
&$hasChanged
): ?int {
Expand Down Expand Up @@ -147,8 +147,9 @@ private function removeMixedParamTags(PhpDocInfo $phpDocInfo, Node $functionLike
}

$hasChanged = true;
return PhpDocNodeTraverser::NODE_REMOVE;
});
return NodeTraverser::REMOVE_NODE;
})]);
$phpDocNodeTraverser->traverse([$phpDocInfo->getPhpDocNode()]);

return $hasChanged;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Property;
use PHPStan\PhpDocParser\Ast\Node as AstNode;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
Expand All @@ -19,7 +20,7 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
use Rector\RuleDoc\RuleDefinition;
Expand Down Expand Up @@ -137,10 +138,7 @@ private function isNull(VarTagValueNode|ParamTagValueNode|ReturnTagValueNode $ta
*/
private function removeParamNullTag(PhpDocInfo $phpDocInfo, array $paramNames): void
{
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable(
$phpDocInfo->getPhpDocNode(),
'',
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(
static function (AstNode $astNode) use ($paramNames): ?int {
if (! $astNode instanceof PhpDocTagNode) {
return null;
Expand All @@ -151,12 +149,13 @@ static function (AstNode $astNode) use ($paramNames): ?int {
}

if (in_array($astNode->value->parameterName, $paramNames, true)) {
return PhpDocNodeTraverser::NODE_REMOVE;
return NodeTraverser::REMOVE_NODE;
}

return null;
}
);
)]);
$phpDocNodeTraverser->traverse([$phpDocInfo->getPhpDocNode()]);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PHPStan\PhpDoc\Tag\TypeAliasImportTag;
use PHPStan\PhpDoc\Tag\TypeAliasTag;
use PHPStan\PhpDocParser\Ast\Node as AstNode;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
Expand All @@ -22,7 +23,7 @@
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\PHPStan\ScopeFetcher;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
Expand Down Expand Up @@ -185,18 +186,18 @@ private function containsTypeAliasName(TypeNode $typeNode, array $typeAliases):
$hasTypeAliasName = false;

// the traverser visits sub-nodes only, that is why the type node itself is checked above
$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($typeNode, '', static function (AstNode $astNode) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(static function (AstNode $astNode) use (
$typeAliases,
&$hasTypeAliasName
): ?int {
if ($astNode instanceof IdentifierTypeNode && isset($typeAliases[$astNode->name])) {
$hasTypeAliasName = true;
return PhpDocNodeTraverser::STOP_TRAVERSAL;
return NodeTraverser::STOP_TRAVERSAL;
}

return null;
});
})]);
$phpDocNodeTraverser->traverse([$typeNode]);

return $hasTypeAliasName;
}
Expand Down
11 changes: 6 additions & 5 deletions rules/Php80/Rector/Class_/AnnotationToAttributeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Use_;
use PHPStan\PhpDocParser\Ast\Node as DocNode;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
Expand All @@ -37,7 +38,7 @@
use Rector\Php80\ValueObject\AttributeValueAndDocComment;
use Rector\Php80\ValueObject\DoctrineTagAndAnnotationToAttribute;
use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\ConfiguredCodeSample;
use Rector\RuleDoc\RuleDefinition;
Expand Down Expand Up @@ -225,8 +226,7 @@ private function processGenericTags(PhpDocInfo $phpDocInfo): array
{
$attributeGroups = [];

$phpDocNodeTraverser = new PhpDocNodeTraverser();
$phpDocNodeTraverser->traverseWithCallable($phpDocInfo->getPhpDocNode(), '', function (DocNode $docNode) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(function (DocNode $docNode) use (
&$attributeGroups,
): int|PhpDocChildNode|null {

Expand Down Expand Up @@ -263,12 +263,13 @@ private function processGenericTags(PhpDocInfo $phpDocInfo): array
return new PhpDocTextNode($attributeValueAndDocComment->docComment);
}

return PhpDocNodeTraverser::NODE_REMOVE;
return NodeTraverser::REMOVE_NODE;

}

return null;
});
})]);
$phpDocNodeTraverser->traverse([$phpDocInfo->getPhpDocNode()]);

return $attributeGroups;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Rector\BetterPhpDocParser\Contract;

use Rector\PhpDocParser\PhpDocParser\Contract\PhpDocNodeVisitorInterface;
use PHPStan\PhpDocParser\Ast\NodeVisitor;

interface BasePhpDocNodeVisitorInterface extends PhpDocNodeVisitorInterface
interface BasePhpDocNodeVisitorInterface extends NodeVisitor
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\PhpDoc\ArrayItemNode;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\StaticTypeMapper\Naming\NameScopeFactory;

/**
Expand All @@ -20,8 +21,7 @@
final readonly class ArrayItemClassNameDecorator implements PhpDocNodeDecoratorInterface
{
public function __construct(
private NameScopeFactory $nameScopeFactory,
private PhpDocNodeTraverser $phpDocNodeTraverser
private NameScopeFactory $nameScopeFactory
) {
}

Expand All @@ -32,7 +32,7 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
return;
}

$this->phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function (Node $node) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(function (Node $node) use (
$phpNode
): Node|null {
if (! $node instanceof ArrayItemNode) {
Expand All @@ -51,7 +51,8 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
}

return $node;
});
})]);
$phpDocNodeTraverser->traverse([$phpDocNode]);
}

private function resolveClassFromScopeResolution(mixed $value, PhpNode $phpNode): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstFetchNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\StaticTypeMapper\Naming\NameScopeFactory;

/**
Expand All @@ -20,8 +21,7 @@
final readonly class ConstExprClassNameDecorator implements PhpDocNodeDecoratorInterface
{
public function __construct(
private NameScopeFactory $nameScopeFactory,
private PhpDocNodeTraverser $phpDocNodeTraverser
private NameScopeFactory $nameScopeFactory
) {
}

Expand All @@ -32,7 +32,7 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
return;
}

$this->phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function (Node $node) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(function (Node $node) use (
$phpNode
): Node|null {
if (! $node instanceof ConstFetchNode) {
Expand All @@ -43,7 +43,8 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
$node->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $className);

return $node;
});
})]);
$phpDocNodeTraverser->traverse([$phpDocNode]);
}

private function resolveFullyQualifiedClass(ConstFetchNode $constFetchNode, PhpNode $phpNode): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

use PhpParser\Node as PhpNode;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\ValueObject\PhpDocAttributeKey;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeTraverser;
use Rector\PhpDocParser\PhpDocParser\PhpDocNodeVisitor\CallablePhpDocNodeVisitor;
use Rector\StaticTypeMapper\Naming\NameScopeFactory;

/**
Expand All @@ -23,8 +24,7 @@
final readonly class PhpDocTagGenericUsesDecorator implements PhpDocNodeDecoratorInterface
{
public function __construct(
private NameScopeFactory $nameScopeFactory,
private PhpDocNodeTraverser $phpDocNodeTraverser
private NameScopeFactory $nameScopeFactory
) {
}

Expand All @@ -35,7 +35,7 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
return;
}

$this->phpDocNodeTraverser->traverseWithCallable($phpDocNode, '', function (Node $node) use (
$phpDocNodeTraverser = new NodeTraverser([new CallablePhpDocNodeVisitor(function (Node $node) use (
$phpNode
): Node|null {
if (! $node instanceof PhpDocTagNode) {
Expand Down Expand Up @@ -64,7 +64,8 @@ public function decorate(PhpDocNode $phpDocNode, PhpNode $phpNode): void
$node->value->setAttribute(PhpDocAttributeKey::RESOLVED_CLASS, $className);

return $node;
});
})]);
$phpDocNodeTraverser->traverse([$phpDocNode]);
}

private function resolveFullyQualifiedClass(string $classValue, PhpNode $phpNode): string
Expand Down
Loading
Loading