diff --git a/composer.json b/composer.json index b67090f15f86..f8a3164c3eda 100644 --- a/composer.json +++ b/composer.json @@ -38,8 +38,8 @@ "nette/robot-loader": "^3.4", "nette/utils": "^3.2", "nikic/php-parser": "^4.10.4", - "phpstan/phpdoc-parser": "^0.5", "phpstan/phpstan": "^0.12.82", + "phpstan/phpdoc-parser": "^0.5.1", "phpstan/phpstan-phpunit": "^0.12.18", "rector/rector-symfony": "dev-main", "rector/rector-nette": "dev-main", @@ -52,20 +52,20 @@ "symfony/http-kernel": "^4.4.8|^5.1", "symfony/process": "^4.4.8|^5.1", "symfony/uid": "^4.4.8|^5.1", - "symplify/astral": "^9.2", - "symplify/autowire-array-parameter": "^9.2", - "symplify/console-color-diff": "^9.2", - "symplify/package-builder": "^9.2", - "symplify/rule-doc-generator-contracts": "^9.2", - "symplify/set-config-resolver": "^9.2", - "symplify/simple-php-doc-parser": "^9.2", - "symplify/skipper": "^9.2", - "symplify/smart-file-system": "^9.2", - "symplify/symfony-php-config": "^9.2", + "symplify/astral": "^9.2.12", + "symplify/autowire-array-parameter": "^9.2.12", + "symplify/console-color-diff": "^9.2.12", + "symplify/package-builder": "^9.2.12", + "symplify/rule-doc-generator-contracts": "^9.2.12", + "symplify/set-config-resolver": "^9.2.12", + "symplify/simple-php-doc-parser": "^9.2.12", + "symplify/skipper": "^9.2.12", + "symplify/smart-file-system": "^9.2.12", + "symplify/symfony-php-config": "^9.2.12", "webmozart/assert": "^1.10" }, "require-dev": { - "symplify/rule-doc-generator": "^9.2", + "symplify/rule-doc-generator": "^9.2.12", "friendsofphp/php-cs-fixer": "^2.18.3", "nette/application": "^3.0.7", "nette/di": "^3.0", @@ -73,11 +73,11 @@ "phpstan/phpstan-nette": "^0.12.16", "phpunit/phpunit": "^9.5", "rector/rector-generator": "^0.1.1", - "symplify/coding-standard": "^9.2", - "symplify/easy-ci": "^9.2", - "symplify/easy-coding-standard": "^9.2", - "symplify/easy-testing": "^9.2", - "symplify/phpstan-extensions": "^9.2", + "symplify/coding-standard": "^9.2.12", + "symplify/easy-ci": "^9.2.12", + "symplify/easy-coding-standard": "^9.2.12", + "symplify/easy-testing": "^9.2.12", + "symplify/phpstan-extensions": "^9.2.12", "symplify/phpstan-rules": "^9.2", "tracy/tracy": "^2.8" }, diff --git a/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php b/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php index 1b2eb7c50705..2cba5ad1f7d5 100644 --- a/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php +++ b/packages-tests/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactoryTest.php @@ -11,9 +11,6 @@ use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\NullableTypeNode; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePropertyTagValueNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareNullableTypeNode; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; use Rector\Core\HttpKernel\RectorKernel; use Symplify\PackageBuilder\Testing\AbstractKernelTestCase; @@ -57,28 +54,17 @@ public function testPropertyTag(): void /** @var PhpDocTagNode $childNode */ $propertyTagValueNode = $childNode->value; $this->assertInstanceOf(PropertyTagValueNode::class, $propertyTagValueNode); - $this->assertInstanceOf(AttributeAwarePropertyTagValueNode::class, $propertyTagValueNode); // test nullable /** @var PropertyTagValueNode $propertyTagValueNode */ $nullableTypeNode = $propertyTagValueNode->type; $this->assertInstanceOf(NullableTypeNode::class, $nullableTypeNode); - $this->assertInstanceOf(AttributeAwareNullableTypeNode::class, $nullableTypeNode); // test type inside nullable /** @var NullableTypeNode $nullableTypeNode */ $identifierTypeNode = $nullableTypeNode->type; $this->assertInstanceOf(IdentifierTypeNode::class, $identifierTypeNode); - $this->assertInstanceOf(AttributeAwareIdentifierTypeNode::class, $identifierTypeNode); - } - - public function testAlreadyAttributeAware(): void - { - $attributeAwarePhpDocNode = new AttributeAwarePhpDocNode([]); - $returnedNode = $this->attributeAwareNodeFactory->createFromNode($attributeAwarePhpDocNode, ''); - - $this->assertSame($returnedNode, $attributeAwarePhpDocNode); } /** diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineTable/TableWithIndexes.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineTable/TableWithIndexes.php deleted file mode 100644 index a7cb63e8213f..000000000000 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/Fixture/DoctrineTable/TableWithIndexes.php +++ /dev/null @@ -1,16 +0,0 @@ -isVariadic ? '...' : ''; diff --git a/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocNode.php b/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocNode.php index 406ff9a774b5..c462041483ab 100644 --- a/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocNode.php +++ b/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocNode.php @@ -4,17 +4,16 @@ namespace Rector\AttributeAwarePhpDoc\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; use Symplify\SimplePhpDocParser\ValueObject\Ast\PhpDoc\SimplePhpDocNode; -final class AttributeAwarePhpDocNode extends SimplePhpDocNode implements AttributeAwareNodeInterface +final class AttributeAwarePhpDocNode extends SimplePhpDocNode { - use AttributeTrait; + use NodeAttributes; /** - * @var PhpDocChildNode[]|AttributeAwareNodeInterface[] + * @var array */ public $children = []; diff --git a/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocTagNode.php b/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocTagNode.php deleted file mode 100644 index 31a0e1ecc1dd..000000000000 --- a/packages/AttributeAwarePhpDoc/Ast/PhpDoc/AttributeAwarePhpDocTagNode.php +++ /dev/null @@ -1,14 +0,0 @@ -type instanceof CallableTypeNode) { diff --git a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeNode.php b/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeNode.php index e90269265232..437a8287c6c0 100644 --- a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeNode.php +++ b/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeNode.php @@ -5,15 +5,14 @@ namespace Rector\AttributeAwarePhpDoc\Ast\Type; use Nette\Utils\Strings; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\CallableTypeNode; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; -final class AttributeAwareCallableTypeNode extends CallableTypeNode implements AttributeAwareNodeInterface +final class AttributeAwareCallableTypeNode extends CallableTypeNode { - use AttributeTrait; + use NodeAttributes; public function __toString(): string { diff --git a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeParameterNode.php b/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeParameterNode.php deleted file mode 100644 index a6c8b9652279..000000000000 --- a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareCallableTypeParameterNode.php +++ /dev/null @@ -1,14 +0,0 @@ -genericTypes !== []) { - return parent::__toString(); - } - - return (string) $this->type; - } -} diff --git a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareIdentifierTypeNode.php b/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareIdentifierTypeNode.php deleted file mode 100644 index b3fcff27663d..000000000000 --- a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareIdentifierTypeNode.php +++ /dev/null @@ -1,14 +0,0 @@ -types); diff --git a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareNullableTypeNode.php b/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareNullableTypeNode.php deleted file mode 100644 index 93eb88bb49b2..000000000000 --- a/packages/AttributeAwarePhpDoc/Ast/Type/AttributeAwareNullableTypeNode.php +++ /dev/null @@ -1,14 +0,0 @@ -type; + } +} diff --git a/packages/AttributeAwarePhpDoc/Ast/Type/FullyQualifiedIdentifierTypeNode.php b/packages/AttributeAwarePhpDoc/Ast/Type/FullyQualifiedIdentifierTypeNode.php index 98e9fab850df..5144a4a4ae21 100644 --- a/packages/AttributeAwarePhpDoc/Ast/Type/FullyQualifiedIdentifierTypeNode.php +++ b/packages/AttributeAwarePhpDoc/Ast/Type/FullyQualifiedIdentifierTypeNode.php @@ -5,13 +5,9 @@ namespace Rector\AttributeAwarePhpDoc\Ast\Type; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; -final class FullyQualifiedIdentifierTypeNode extends IdentifierTypeNode implements AttributeAwareNodeInterface +final class FullyQualifiedIdentifierTypeNode extends IdentifierTypeNode { - use AttributeTrait; - public function __toString(): string { return '\\' . $this->name; diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareDeprecatedTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareDeprecatedTagValueNodeFactory.php deleted file mode 100644 index 4e3c89ccf437..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareDeprecatedTagValueNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -description); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareExtendsTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareExtendsTagValueNodeFactory.php deleted file mode 100644 index cfde1c1024b8..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareExtendsTagValueNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwareExtendsTagValueNode($node->type, $node->description); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareGenericTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareGenericTagValueNodeFactory.php deleted file mode 100644 index 29fc44ca92b1..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareGenericTagValueNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -value); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareImplementsTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareImplementsTagValueNodeFactory.php deleted file mode 100644 index 44c4bee92fb7..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareImplementsTagValueNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwareImplementsTagValueNode($node->type, $node->description); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareInvalidTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareInvalidTagValueNodeFactory.php deleted file mode 100644 index c5f717ff7953..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareInvalidTagValueNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -value, $node->exception); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueNodeFactory.php deleted file mode 100644 index c34693244379..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueNodeFactory.php +++ /dev/null @@ -1,73 +0,0 @@ -attributizeReturnType($node, $docContent); - - foreach ($node->parameters as $key => $parameter) { - $node->parameters[$key] = $this->attributeAwareNodeFactory->createFromNode($parameter, $docContent); - } - - return new AttributeAwareMethodTagValueNode( - $node->isStatic, - $returnType, - $node->methodName, - $node->parameters, - $node->description - ); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } - - private function attributizeReturnType( - MethodTagValueNode $methodTagValueNode, - string $docContent - ): ?AttributeAwareNodeInterface { - if ($methodTagValueNode->returnType !== null) { - return $this->createAttributeAwareReturnType($methodTagValueNode->returnType, $docContent); - } - - return null; - } - - private function createAttributeAwareReturnType(TypeNode $typeNode, string $docContent): AttributeAwareNodeInterface - { - return $this->attributeAwareNodeFactory->createFromNode($typeNode, $docContent); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueParameterNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueParameterNodeFactory.php deleted file mode 100644 index 0981b9dcda46..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMethodTagValueParameterNodeFactory.php +++ /dev/null @@ -1,54 +0,0 @@ -type !== null) { - $node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - } - - return new AttributeAwareMethodTagValueParameterNode( - $node->type, - $node->isReference, - $node->isVariadic, - $node->parameterName, - $node->defaultValue - ); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMixinTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMixinTagValueNodeFactory.php deleted file mode 100644 index 91d9bebdca58..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareMixinTagValueNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -type, $node->description); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareParamTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareParamTagValueNodeFactory.php index a693c983abb9..7b61e3a525c3 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareParamTagValueNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareParamTagValueNodeFactory.php @@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class AttributeAwareParamTagValueNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface { @@ -19,11 +18,6 @@ final class AttributeAwareParamTagValueNodeFactory implements AttributeNodeAware */ private $attributeAwareNodeFactory; - public function getOriginalNodeClass(): string - { - return ParamTagValueNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, ParamTagValueNode::class, true); @@ -31,8 +25,9 @@ public function isMatch(Node $node): bool /** * @param ParamTagValueNode $node + * @return AttributeAwareParamTagValueNode */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { $node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocNodeFactory.php index 5ed4eb189e57..247dc04fe3b7 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocNodeFactory.php @@ -10,7 +10,7 @@ use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Symplify\SimplePhpDocParser\PhpDocNodeTraverser; final class AttributeAwarePhpDocNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface @@ -30,11 +30,6 @@ public function __construct(PhpDocNodeTraverser $phpDocNodeTraverser) $this->phpDocNodeTraverser = $phpDocNodeTraverser; } - public function getOriginalNodeClass(): string - { - return PhpDocNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, PhpDocNode::class, true); @@ -43,15 +38,11 @@ public function isMatch(Node $node): bool /** * @param PhpDocNode $node */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { $this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function (Node $node) use ( $docContent - ): AttributeAwareNodeInterface { - if ($node instanceof AttributeAwareNodeInterface) { - return $node; - } - + ): Node { return $this->attributeAwareNodeFactory->createFromNode($node, $docContent); }); diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocTagNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocTagNodeFactory.php deleted file mode 100644 index 3de8e8a969e9..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocTagNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -name, $node->value); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocTextNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocTextNodeFactory.php deleted file mode 100644 index 1fb258135097..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePhpDocTextNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -text); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePropertyTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePropertyTagValueNodeFactory.php deleted file mode 100644 index 28ba2566e514..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwarePropertyTagValueNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwarePropertyTagValueNode($node->type, $node->propertyName, $node->description); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareReturnTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareReturnTagValueNodeFactory.php deleted file mode 100644 index 0272a7ec8d9f..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareReturnTagValueNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwareReturnTagValueNode($node->type, $node->description); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareTemplateTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareTemplateTagValueNodeFactory.php index 9531928eb17a..efda34f2386d 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareTemplateTagValueNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareTemplateTagValueNodeFactory.php @@ -8,15 +8,9 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareTemplateTagValueNode; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class AttributeAwareTemplateTagValueNodeFactory implements AttributeNodeAwareFactoryInterface { - public function getOriginalNodeClass(): string - { - return TemplateTagValueNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, TemplateTagValueNode::class, true); @@ -25,7 +19,7 @@ public function isMatch(Node $node): bool /** * @param TemplateTagValueNode $node */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { return new AttributeAwareTemplateTagValueNode($node->name, $node->bound, $node->description, $docContent); } diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareThrowsTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareThrowsTagValueNodeFactory.php deleted file mode 100644 index f412ff7d5360..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareThrowsTagValueNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwareThrowsTagValueNode($node->type, $node->description); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareUsesTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareUsesTagValueNodeFactory.php deleted file mode 100644 index 2e02786a2455..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareUsesTagValueNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -type, $node->description); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareVarTagValueNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareVarTagValueNodeFactory.php deleted file mode 100644 index 528962d41d21..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/PhpDoc/AttributeAwareVarTagValueNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwareVarTagValueNode($node->type, $node->variableName, $node->description); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeItemNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeItemNodeFactory.php index fd62350b17ec..94ead9dc4883 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeItemNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeItemNodeFactory.php @@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface { @@ -19,11 +18,6 @@ final class AttributeAwareArrayShapeItemNodeFactory implements AttributeNodeAwar */ private $attributeAwareNodeFactory; - public function getOriginalNodeClass(): string - { - return ArrayShapeItemNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, ArrayShapeItemNode::class, true); @@ -31,8 +25,9 @@ public function isMatch(Node $node): bool /** * @param ArrayShapeItemNode $node + * @return AttributeAwareArrayShapeItemNode */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { $node->valueType = $this->attributeAwareNodeFactory->createFromNode($node->valueType, $docContent); return new AttributeAwareArrayShapeItemNode($node->keyName, $node->optional, $node->valueType, $docContent); diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeNodeFactory.php deleted file mode 100644 index 9f3faaba68a9..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayShapeNodeFactory.php +++ /dev/null @@ -1,49 +0,0 @@ -items as $item) { - $items[] = $this->attributeAwareNodeFactory->createFromNode($item, $docContent); - } - - return new AttributeAwareArrayShapeNode($items); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayTypeNodeFactory.php index 60641d909c0b..5eb34fe9f4fb 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayTypeNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareArrayTypeNodeFactory.php @@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class AttributeAwareArrayTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface { @@ -19,11 +18,6 @@ final class AttributeAwareArrayTypeNodeFactory implements AttributeNodeAwareFact */ private $attributeAwareNodeFactory; - public function getOriginalNodeClass(): string - { - return ArrayTypeNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, ArrayTypeNode::class, true); @@ -31,8 +25,9 @@ public function isMatch(Node $node): bool /** * @param ArrayTypeNode $node + * @return AttributeAwareArrayTypeNode */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { $node->type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php index 36716154f7d4..0b93410392b6 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeNodeFactory.php @@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class AttributeAwareCallableTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface { @@ -19,11 +18,6 @@ final class AttributeAwareCallableTypeNodeFactory implements AttributeNodeAwareF */ private $attributeAwareNodeFactory; - public function getOriginalNodeClass(): string - { - return CallableTypeNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, CallableTypeNode::class, true); @@ -31,8 +25,9 @@ public function isMatch(Node $node): bool /** * @param CallableTypeNode $node + * @return AttributeAwareCallableTypeNode */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { $identifier = $this->attributeAwareNodeFactory->createFromNode($node->identifier, $docContent); diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeParameterNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeParameterNodeFactory.php deleted file mode 100644 index 1f8fed196ca6..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareCallableTypeParameterNodeFactory.php +++ /dev/null @@ -1,38 +0,0 @@ -type, - $node->isReference, - $node->isVariadic, - $node->parameterName, - $node->isOptional - ); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareConstTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareConstTypeNodeFactory.php deleted file mode 100644 index 55c44916d001..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareConstTypeNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -constExpr); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareGenericTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareGenericTypeNodeFactory.php deleted file mode 100644 index 8d99757a1ffb..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareGenericTypeNodeFactory.php +++ /dev/null @@ -1,51 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - $genericTypes = []; - foreach ($node->genericTypes as $genericType) { - $genericTypes[] = $this->attributeAwareNodeFactory->createFromNode($genericType, $docContent); - } - - return new AttributeAwareGenericTypeNode($node->type, $genericTypes); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIdentifierTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIdentifierTypeNodeFactory.php deleted file mode 100644 index 641dd92dcbc5..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIdentifierTypeNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -name); - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIntersectionTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIntersectionTypeNodeFactory.php index d80dfc3114f2..6d43a7855710 100644 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIntersectionTypeNodeFactory.php +++ b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareIntersectionTypeNodeFactory.php @@ -10,7 +10,6 @@ use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class AttributeAwareIntersectionTypeNodeFactory implements AttributeNodeAwareFactoryInterface, AttributeAwareNodeFactoryAwareInterface { @@ -19,11 +18,6 @@ final class AttributeAwareIntersectionTypeNodeFactory implements AttributeNodeAw */ private $attributeAwareNodeFactory; - public function getOriginalNodeClass(): string - { - return IntersectionTypeNode::class; - } - public function isMatch(Node $node): bool { return is_a($node, IntersectionTypeNode::class, true); @@ -32,7 +26,7 @@ public function isMatch(Node $node): bool /** * @param IntersectionTypeNode $node */ - public function create(Node $node, string $docContent): AttributeAwareNodeInterface + public function create(Node $node, string $docContent): Node { foreach ($node->types as $key => $intersectionedType) { $node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($intersectionedType, $docContent); diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareNullableTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareNullableTypeNodeFactory.php deleted file mode 100644 index 05b555fc33ea..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareNullableTypeNodeFactory.php +++ /dev/null @@ -1,46 +0,0 @@ -type = $this->attributeAwareNodeFactory->createFromNode($node->type, $docContent); - - return new AttributeAwareNullableTypeNode($node->type); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareThisTypeNodeFactory.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareThisTypeNodeFactory.php deleted file mode 100644 index fce6a5d31136..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactory/Type/AttributeAwareThisTypeNodeFactory.php +++ /dev/null @@ -1,32 +0,0 @@ -types as $key => $unionedType) { - $node->types[$key] = $this->attributeAwareNodeFactory->createFromNode($unionedType, $docContent); - } - - return new AttributeAwareUnionTypeNode($node->types, $docContent); - } - - public function setAttributeAwareNodeFactory(AttributeAwareNodeFactory $attributeAwareNodeFactory): void - { - $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - } -} diff --git a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactoryCollector.php b/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactoryCollector.php deleted file mode 100644 index ed50a9f8986c..000000000000 --- a/packages/AttributeAwarePhpDoc/AttributeAwareNodeFactoryCollector.php +++ /dev/null @@ -1,44 +0,0 @@ -attributeAwareNodeFactories = $attributeAwareNodeFactories; - } - - /** - * @return AttributeNodeAwareFactoryInterface[] - */ - public function provide(): array - { - return $this->attributeAwareNodeFactories; - } - - /** - * @return string[] - */ - public function getSupportedNodeClasses(): array - { - $supportedNodeClasses = []; - foreach ($this->attributeAwareNodeFactories as $attributeAwareNodeFactory) { - $supportedNodeClasses[] = $attributeAwareNodeFactory->getOriginalNodeClass(); - } - - return $supportedNodeClasses; - } -} diff --git a/packages/AttributeAwarePhpDoc/Contract/AttributeNodeAwareFactory/AttributeNodeAwareFactoryInterface.php b/packages/AttributeAwarePhpDoc/Contract/AttributeNodeAwareFactory/AttributeNodeAwareFactoryInterface.php index 074ef77c9f1c..c76ee6a4843f 100644 --- a/packages/AttributeAwarePhpDoc/Contract/AttributeNodeAwareFactory/AttributeNodeAwareFactoryInterface.php +++ b/packages/AttributeAwarePhpDoc/Contract/AttributeNodeAwareFactory/AttributeNodeAwareFactoryInterface.php @@ -5,13 +5,15 @@ namespace Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory; use PHPStan\PhpDocParser\Ast\Node; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; interface AttributeNodeAwareFactoryInterface { - public function getOriginalNodeClass(): string; - public function isMatch(Node $node): bool; - public function create(Node $node, string $docContent): AttributeAwareNodeInterface; + /** + * @template T of Node + * @param T $node + * @return T + */ + public function create(Node $node, string $docContent): Node; } diff --git a/packages/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactory.php b/packages/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactory.php index 151f142dc399..2e64f5519304 100644 --- a/packages/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactory.php +++ b/packages/BetterPhpDocParser/Attributes/Ast/AttributeAwareNodeFactory.php @@ -5,13 +5,14 @@ namespace Rector\BetterPhpDocParser\Attributes\Ast; use PHPStan\PhpDocParser\Ast\Node; -use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode; -use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocNode; -use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; -use Rector\AttributeAwarePhpDoc\AttributeAwareNodeFactoryCollector; +use PHPStan\PhpDocParser\Ast\Type\ArrayShapeItemNode; +use PHPStan\PhpDocParser\Ast\Type\UnionTypeNode; +use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayShapeItemNode; +use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareUnionTypeNode; use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeAwareNodeFactoryAwareInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; -use Rector\Core\Exception\ShouldNotHappenException; +use Rector\AttributeAwarePhpDoc\Contract\AttributeNodeAwareFactory\AttributeNodeAwareFactoryInterface; + +use Symplify\SimplePhpDocParser\PhpDocNodeTraverser; /** * @see \Rector\Tests\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactoryTest @@ -19,41 +20,65 @@ final class AttributeAwareNodeFactory { /** - * @var AttributeAwareNodeFactoryCollector + * @var AttributeNodeAwareFactoryInterface[] */ - private $attributeAwareNodeFactoryCollector; + private $attributeAwareNodeFactories = []; - public function __construct(AttributeAwareNodeFactoryCollector $attributeAwareNodeFactoryCollector) + /** + * @var PhpDocNodeTraverser + */ + private $phpDocNodeTraverser; + + /** + * @param AttributeNodeAwareFactoryInterface[] $attributeAwareNodeFactories + */ + public function __construct(array $attributeAwareNodeFactories, PhpDocNodeTraverser $phpDocNodeTraverser) { - $this->attributeAwareNodeFactoryCollector = $attributeAwareNodeFactoryCollector; + foreach ($attributeAwareNodeFactories as $attributeAwareNodeFactory) { + // prevents cyclic dependency + if ($attributeAwareNodeFactory instanceof AttributeAwareNodeFactoryAwareInterface) { + $attributeAwareNodeFactory->setAttributeAwareNodeFactory($this); + } + } + + $this->attributeAwareNodeFactories = $attributeAwareNodeFactories; + $this->phpDocNodeTraverser = $phpDocNodeTraverser; } /** - * @return PhpDocNode|PhpDocChildNode|PhpDocTagValueNode|AttributeAwareNodeInterface + * @template T of \PHPStan\PhpDocParser\Ast\Node + * @param T $node + * @return T */ - public function createFromNode(Node $node, string $docContent): AttributeAwareNodeInterface + public function createFromNode(Node $node, string $docContent): Node { - if ($node instanceof AttributeAwareNodeInterface) { - return $node; - } + $node = $this->phpDocNodeTraverser->traverseWithCallable($node, $docContent, function ( + Node $node, + string $docContent + ): Node { + if ($node instanceof UnionTypeNode && ! $node instanceof AttributeAwareUnionTypeNode) { + return new AttributeAwareUnionTypeNode($node->types, $docContent); + } - foreach ($this->attributeAwareNodeFactoryCollector->provide() as $attributeNodeAwareFactory) { - if (! $attributeNodeAwareFactory->isMatch($node)) { - continue; + if ($node instanceof ArrayShapeItemNode && ! $node instanceof AttributeAwareArrayShapeItemNode) { + return new AttributeAwareArrayShapeItemNode( + $node->keyName, + $node->optional, + $node->valueType, + $docContent + ); } + return $node; + }); - // prevents cyclic dependency - if ($attributeNodeAwareFactory instanceof AttributeAwareNodeFactoryAwareInterface) { - $attributeNodeAwareFactory->setAttributeAwareNodeFactory($this); + foreach ($this->attributeAwareNodeFactories as $attributeAwareNodeFactory) { + if (! $attributeAwareNodeFactory->isMatch($node)) { + continue; } - return $attributeNodeAwareFactory->create($node, $docContent); + return $attributeAwareNodeFactory->create($node, $docContent); } - throw new ShouldNotHappenException(sprintf( - 'Node "%s" was missed in "%s". Generate it with: bin/rector sync-types', - get_class($node), - __METHOD__ - )); + return $node; } } diff --git a/packages/BetterPhpDocParser/Attributes/Ast/PhpDoc/SpacelessPhpDocTagNode.php b/packages/BetterPhpDocParser/Attributes/Ast/PhpDoc/SpacelessPhpDocTagNode.php index 196230b467da..114dcab6dfcc 100644 --- a/packages/BetterPhpDocParser/Attributes/Ast/PhpDoc/SpacelessPhpDocTagNode.php +++ b/packages/BetterPhpDocParser/Attributes/Ast/PhpDoc/SpacelessPhpDocTagNode.php @@ -5,17 +5,13 @@ namespace Rector\BetterPhpDocParser\Attributes\Ast\PhpDoc; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; /** * Useful for annotation class based annotation, e.g. @ORM\Entity to prevent space * between the @ORM\Entity and (someContent) */ -final class SpacelessPhpDocTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface +final class SpacelessPhpDocTagNode extends PhpDocTagNode { - use AttributeTrait; - public function __toString(): string { return $this->name . $this->value; diff --git a/packages/BetterPhpDocParser/Attributes/Attribute/AttributeTrait.php b/packages/BetterPhpDocParser/Attributes/Attribute/AttributeTrait.php deleted file mode 100644 index fd1b771737ea..000000000000 --- a/packages/BetterPhpDocParser/Attributes/Attribute/AttributeTrait.php +++ /dev/null @@ -1,29 +0,0 @@ -attributes[$name] ?? null; - } - - /** - * @param mixed $value - */ - public function setAttribute(string $name, $value): void - { - $this->attributes[$name] = $value; - } -} diff --git a/packages/BetterPhpDocParser/Contract/PhpDocNode/AttributeAwareNodeInterface.php b/packages/BetterPhpDocParser/Contract/PhpDocNode/AttributeAwareNodeInterface.php deleted file mode 100644 index 240517a82669..000000000000 --- a/packages/BetterPhpDocParser/Contract/PhpDocNode/AttributeAwareNodeInterface.php +++ /dev/null @@ -1,14 +0,0 @@ - */ public function getTagsByName(string $name): array { $name = $this->annotationNaming->normalizeName($name); - /** @var PhpDocTagNode[]|AttributeAwareNodeInterface[] $tags */ $tags = $this->phpDocNode->getTags(); $tags = array_filter($tags, function (PhpDocTagNode $tag) use ($name): bool { return $tag->name === $name; }); - $tags = array_values($tags); + $tags = array_values($tags); return array_values($tags); } public function getParamType(string $name): Type { - $attributeAwareParamTagValueNode = $this->getParamTagValueByName($name); - return $this->getTypeOrMixed($attributeAwareParamTagValueNode); + $paramTagValueByName = $this->getParamTagValueByName($name); + return $this->getTypeOrMixed($paramTagValueByName); } /** @@ -302,7 +299,7 @@ public function getByType(string $type): ?PhpDocNode /** * @template T of \PHPStan\PhpDocParser\Ast\Node * @param class-string $type - * @return T[] + * @return array */ public function findAllByType(string $type): array { @@ -332,9 +329,14 @@ public function findAllByType(string $type): array $foundTagsValueNodes[] = $phpDocChildNode->value; } + /** @var \PHPStan\PhpDocParser\Ast\Node[] $foundTagsValueNodes */ return $foundTagsValueNodes; } + /** + * @template T of \PHPStan\PhpDocParser\Ast\Node + * @param class-string $type + */ public function removeByType(string $type): void { $this->ensureTypeIsTagValueNode($type, __METHOD__); @@ -390,8 +392,8 @@ public function addTagValueNode(PhpDocTagValueNode $phpDocTagValueNode): void $name = $this->resolveNameForPhpDocTagValueNode($phpDocTagValueNode); - $attributeAwarePhpDocTagNode = new AttributeAwarePhpDocTagNode($name, $phpDocTagValueNode); - $this->addPhpDocTagNode($attributeAwarePhpDocTagNode); + $phpDocTagNode = new PhpDocTagNode($name, $phpDocTagValueNode); + $this->addPhpDocTagNode($phpDocTagNode); } public function isNewNode(): bool @@ -413,9 +415,8 @@ public function isSingleLine(): bool return $this->isSingleLine; } - public function getReturnTagValue(): ?AttributeAwareReturnTagValueNode + public function getReturnTagValue(): ?ReturnTagValueNode { - /** @var AttributeAwareReturnTagValueNode[] $returnTagValueNodes */ $returnTagValueNodes = $this->phpDocNode->getReturnTagValues(); return $returnTagValueNodes[0] ?? null; } @@ -481,12 +482,14 @@ private function getTypeOrMixed(?PhpDocTagValueNode $phpDocTagValueNode): Type private function ensureTypeIsTagValueNode(string $type, string $location): void { - if (StaticInstanceOf::isOneOf($type, [ + /** @var array $desiredTypes */ + $desiredTypes = array_merge([ PhpDocTagValueNode::class, PhpDocTagNode::class, - TypeAwareTagValueNodeInterface::class, PhpAttributableTagNodeInterface::class, - ])) { + ], NodeTypes::TYPE_AWARE_NODES); + + if (StaticInstanceOf::isOneOf($type, $desiredTypes)) { return; } diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php index ff9c5b88331f..67fbd34e1f47 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfoFactory.php @@ -14,7 +14,7 @@ use Rector\BetterPhpDocParser\Annotation\AnnotationNaming; use Rector\BetterPhpDocParser\Attributes\Ast\AttributeAwareNodeFactory; use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\BetterPhpDocParser\Contract\PhpDocNodeFactoryInterface; use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser; use Rector\BetterPhpDocParser\ValueObject\StartAndEnd; @@ -168,7 +168,6 @@ private function setPositionOfLastToken(AttributeAwarePhpDocNode $attributeAware } $phpDocChildNodes = $attributeAwarePhpDocNode->children; - /** @var AttributeAwareNodeInterface $lastChildNode */ $lastChildNode = array_pop($phpDocChildNodes); /** @var StartAndEnd $startAndEnd */ diff --git a/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php b/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php index 66f7a4fdf57a..61e8aba6b14a 100644 --- a/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php +++ b/packages/BetterPhpDocParser/PhpDocManipulator/PhpDocTypeChanger.php @@ -5,12 +5,12 @@ namespace Rector\BetterPhpDocParser\PhpDocManipulator; use PhpParser\Node\Param; +use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\MixedType; use PHPStan\Type\NeverType; use PHPStan\Type\Type; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareVarTagValueNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; use Rector\StaticTypeMapper\StaticTypeMapper; @@ -65,8 +65,8 @@ public function changeVarType(PhpDocInfo $phpDocInfo, Type $newType): void $phpDocInfo->markAsChanged(); } else { // add completely new one - $attributeAwareVarTagValueNode = new AttributeAwareVarTagValueNode($newPHPStanPhpDocType, '', ''); - $phpDocInfo->addTagValueNode($attributeAwareVarTagValueNode); + $varTagValueNode = new VarTagValueNode($newPHPStanPhpDocType, '', ''); + $phpDocInfo->addTagValueNode($varTagValueNode); } } @@ -87,8 +87,8 @@ public function changeReturnType(PhpDocInfo $phpDocInfo, Type $newType): void $phpDocInfo->markAsChanged(); } else { // add completely new one - $attributeAwareReturnTagValueNode = new AttributeAwareReturnTagValueNode($newPHPStanPhpDocType, ''); - $phpDocInfo->addTagValueNode($attributeAwareReturnTagValueNode); + $returnTagValueNode = new ReturnTagValueNode($newPHPStanPhpDocType, ''); + $phpDocInfo->addTagValueNode($returnTagValueNode); } } diff --git a/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php b/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php index a022db649ead..8ca3d3b6458b 100644 --- a/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php +++ b/packages/BetterPhpDocParser/PhpDocManipulator/VarAnnotationManipulator.php @@ -6,10 +6,10 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Expression; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareVarTagValueNode; use Rector\AttributeAwarePhpDoc\Ast\Type\FullyQualifiedIdentifierTypeNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; @@ -47,13 +47,8 @@ public function decorateNodeWithInlineVarType( $fullyQualifiedIdentifierTypeNode = new FullyQualifiedIdentifierTypeNode($typeWithClassName->getClassName()); - $attributeAwareVarTagValueNode = new AttributeAwareVarTagValueNode( - $fullyQualifiedIdentifierTypeNode, - '$' . $variableName, - '' - ); - - $phpDocInfo->addTagValueNode($attributeAwareVarTagValueNode); + $varTagValueNode = new VarTagValueNode($fullyQualifiedIdentifierTypeNode, '$' . $variableName, ''); + $phpDocInfo->addTagValueNode($varTagValueNode); } public function decorateNodeWithType(Node $node, Type $staticType): void diff --git a/packages/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php b/packages/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php index 72683921b6a2..a8148d02c78c 100644 --- a/packages/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php +++ b/packages/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php @@ -22,7 +22,6 @@ use Rector\BetterPhpDocParser\Contract\SpecificPhpDocNodeFactoryInterface; use Rector\BetterPhpDocParser\Contract\StringTagMatchingPhpDocNodeFactoryInterface; use Rector\BetterPhpDocParser\PhpDocNodeFactory\MultiPhpDocNodeFactory; -use Rector\BetterPhpDocParser\Printer\MultilineSpaceFormatPreserver; use Rector\BetterPhpDocParser\ValueObject\StartAndEnd; use Rector\Core\Configuration\CurrentNodeProvider; use Rector\Core\Exception\ShouldNotHappenException; @@ -40,12 +39,6 @@ final class BetterPhpDocParser extends PhpDocParser */ private const TAG_REGEX = '#@(var|param|return|throws|property|deprecated)#'; - /** - * @see https://regex101.com/r/iCJqCv/1 - * @var string - */ - private const SPACE_REGEX = '#\s+#'; - /** * @var PhpDocNodeFactoryInterface[] */ @@ -66,11 +59,6 @@ final class BetterPhpDocParser extends PhpDocParser */ private $attributeAwareNodeFactory; - /** - * @var MultilineSpaceFormatPreserver - */ - private $multilineSpaceFormatPreserver; - /** * @var CurrentNodeProvider */ @@ -99,7 +87,6 @@ public function __construct( TypeParser $typeParser, ConstExprParser $constExprParser, AttributeAwareNodeFactory $attributeAwareNodeFactory, - MultilineSpaceFormatPreserver $multilineSpaceFormatPreserver, CurrentNodeProvider $currentNodeProvider, ClassAnnotationMatcher $classAnnotationMatcher, AnnotationContentResolver $annotationContentResolver, @@ -108,15 +95,14 @@ public function __construct( ) { parent::__construct($typeParser, $constExprParser); + $this->setPhpDocNodeFactories($phpDocNodeFactories); + $this->privatesCaller = new PrivatesCaller(); $this->privatesAccessor = new PrivatesAccessor(); $this->attributeAwareNodeFactory = $attributeAwareNodeFactory; - $this->multilineSpaceFormatPreserver = $multilineSpaceFormatPreserver; $this->currentNodeProvider = $currentNodeProvider; $this->classAnnotationMatcher = $classAnnotationMatcher; $this->annotationContentResolver = $annotationContentResolver; - - $this->setPhpDocNodeFactories($phpDocNodeFactories); $this->stringTagMatchingPhpDocNodeFactories = $stringTagMatchingPhpDocNodeFactories; } @@ -223,6 +209,8 @@ private function parseChildAndStoreItsPositions(TokenIterator $tokenIterator): N $docContent = $this->annotationContentResolver->resolveFromTokenIterator($originalTokenIterator); $tokenStart = $this->getTokenIteratorIndex($tokenIterator); + + /** @var PhpDocNode $phpDocNode */ $phpDocNode = $this->privatesCaller->callPrivateMethod($this, 'parseChild', [$tokenIterator]); $tokenEnd = $this->resolveTokenEnd($tokenIterator); @@ -232,26 +220,6 @@ private function parseChildAndStoreItsPositions(TokenIterator $tokenIterator): N $attributeAwareNode = $this->attributeAwareNodeFactory->createFromNode($phpDocNode, $docContent); $attributeAwareNode->setAttribute(Attribute::START_END, $startAndEnd); - $possibleMultilineText = $this->multilineSpaceFormatPreserver->resolveCurrentPhpDocNodeText( - $attributeAwareNode - ); - - if ($possibleMultilineText) { - // add original text, for keeping trimmed spaces - $originalContent = $this->getOriginalContentFromTokenIterator($tokenIterator); - - // we try to match original content without trimmed spaces - $currentTextPattern = '#(?' . preg_quote($possibleMultilineText, '#') . ')#s'; - - $currentTextPattern = Strings::replace($currentTextPattern, self::SPACE_REGEX, '\s+'); - - $match = Strings::match($originalContent, $currentTextPattern); - - if (isset($match['line'])) { - $attributeAwareNode->setAttribute(Attribute::ORIGINAL_CONTENT, $match['line']); - } - } - return $attributeAwareNode; } @@ -328,32 +296,6 @@ private function resolveTokenEnd(TokenIterator $tokenIterator): int return $this->adjustTokenEndToFitClassAnnotation($tokenIterator, $tokenEnd); } - private function getOriginalContentFromTokenIterator(TokenIterator $tokenIterator): string - { - $originalTokens = $this->privatesAccessor->getPrivateProperty($tokenIterator, 'tokens'); - $originalContent = ''; - - foreach ($originalTokens as $originalToken) { - // skip opening - if ($originalToken[1] === Lexer::TOKEN_OPEN_PHPDOC) { - continue; - } - - // skip closing - if ($originalToken[1] === Lexer::TOKEN_CLOSE_PHPDOC) { - continue; - } - - if ($originalToken[1] === Lexer::TOKEN_PHPDOC_EOL) { - $originalToken[0] = PHP_EOL; - } - - $originalContent .= $originalToken[0]; - } - - return trim($originalContent); - } - /** * @see https://github.com/rectorphp/rector/issues/2158 * diff --git a/packages/BetterPhpDocParser/Printer/MultilineSpaceFormatPreserver.php b/packages/BetterPhpDocParser/Printer/MultilineSpaceFormatPreserver.php index acf332073397..5c88309cafb8 100644 --- a/packages/BetterPhpDocParser/Printer/MultilineSpaceFormatPreserver.php +++ b/packages/BetterPhpDocParser/Printer/MultilineSpaceFormatPreserver.php @@ -9,10 +9,7 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTextNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocTagNode; use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; final class MultilineSpaceFormatPreserver { @@ -50,33 +47,29 @@ public function resolveCurrentPhpDocNodeText(Node $node): ?string /** * Fix multiline BC break - https://github.com/phpstan/phpdoc-parser/pull/26/files */ - public function fixMultilineDescriptions(AttributeAwareNodeInterface $attributeAwareNode): void + public function fixMultilineDescriptions(Node $node): void { - $originalContent = $attributeAwareNode->getAttribute(Attribute::ORIGINAL_CONTENT); + $originalContent = $node->getAttribute(Attribute::ORIGINAL_CONTENT); if (! $originalContent) { return; } - $nodeWithRestoredSpaces = $this->restoreOriginalSpacingInText($attributeAwareNode); - if (! $nodeWithRestoredSpaces instanceof AttributeAwareNodeInterface) { + $nodeWithRestoredSpaces = $this->restoreOriginalSpacingInText($node); + if (! $nodeWithRestoredSpaces instanceof Node) { return; } - $attributeAwareNode = $nodeWithRestoredSpaces; - $attributeAwareNode->setAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES, true); + $node = $nodeWithRestoredSpaces; + $node->setAttribute(Attribute::HAS_DESCRIPTION_WITH_ORIGINAL_SPACES, true); } - /** - * @param PhpDocTextNode|AttributeAwareNodeInterface $attributeAwareNode - */ - private function restoreOriginalSpacingInText( - AttributeAwareNodeInterface $attributeAwareNode - ): ?AttributeAwareNodeInterface { + private function restoreOriginalSpacingInText(Node $node): ?Node + { /** @var string $originalContent */ - $originalContent = $attributeAwareNode->getAttribute(Attribute::ORIGINAL_CONTENT); + $originalContent = $node->getAttribute(Attribute::ORIGINAL_CONTENT); $oldSpaces = Strings::matchAll($originalContent, '#\s+#ms'); - $currentText = $this->resolveCurrentPhpDocNodeText($attributeAwareNode); + $currentText = $this->resolveCurrentPhpDocNodeText($node); if ($currentText === null) { return null; } @@ -105,33 +98,28 @@ private function restoreOriginalSpacingInText( return null; } - $this->decoratePhpDocNodeWithNewText($attributeAwareNode, $newText); - return $attributeAwareNode; + $this->decoratePhpDocNodeWithNewText($node, $newText); + return $node; } - private function decoratePhpDocNodeWithNewText( - AttributeAwareNodeInterface $attributeAwareNode, - string $newText - ): void { - if ($attributeAwareNode instanceof PhpDocTagNode && property_exists( - $attributeAwareNode->value, - 'description' - )) { - $attributeAwareNode->value->description = $newText; + private function decoratePhpDocNodeWithNewText(Node $node, string $newText): void + { + if ($node instanceof PhpDocTagNode && property_exists($node->value, 'description')) { + $node->value->description = $newText; } - if ($attributeAwareNode instanceof PhpDocTextNode) { - $attributeAwareNode->text = $newText; + if ($node instanceof PhpDocTextNode) { + $node->text = $newText; } - if (! $attributeAwareNode instanceof AttributeAwarePhpDocTagNode) { + if (! $node instanceof PhpDocTagNode) { return; } - if (! $attributeAwareNode->value instanceof AttributeAwareGenericTagValueNode) { + if (! $node->value instanceof GenericTagValueNode) { return; } - $attributeAwareNode->value->value = $newText; + $node->value->value = $newText; } } diff --git a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php index 5f415f607419..1953a011c8c6 100644 --- a/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php +++ b/packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php @@ -5,6 +5,7 @@ namespace Rector\BetterPhpDocParser\Printer; use Nette\Utils\Strings; +use PHPStan\PhpDocParser\Ast\Node; use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; @@ -15,7 +16,7 @@ use PHPStan\PhpDocParser\Lexer\Lexer; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwarePhpDocNode; use Rector\BetterPhpDocParser\Attributes\Attribute\Attribute; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\ValueObject\StartAndEnd; use Rector\Core\Exception\ShouldNotHappenException; @@ -218,7 +219,7 @@ private function removeExtraSpacesAfterAsterisk(string $phpDocString): string } private function printNode( - AttributeAwareNodeInterface $attributeAwareNode, + Node $node, ?StartAndEnd $startAndEnd = null, int $key = 0, int $nodeCount = 0 @@ -226,11 +227,11 @@ private function printNode( $output = ''; /** @var StartAndEnd|null $startAndEnd */ - $startAndEnd = $attributeAwareNode->getAttribute(Attribute::START_END) ?: $startAndEnd; - $this->multilineSpaceFormatPreserver->fixMultilineDescriptions($attributeAwareNode); + $startAndEnd = $node->getAttribute(Attribute::START_END) ?: $startAndEnd; + $this->multilineSpaceFormatPreserver->fixMultilineDescriptions($node); if ($startAndEnd !== null) { - $isLastToken = ($nodeCount === $key); + $isLastToken = $nodeCount === $key; $output = $this->addTokensFromTo( $output, @@ -242,26 +243,26 @@ private function printNode( $this->currentTokenPosition = $startAndEnd->getEnd(); } - if ($attributeAwareNode instanceof PhpDocTagNode) { + if ($node instanceof PhpDocTagNode) { if ($startAndEnd !== null) { - return $this->printPhpDocTagNode($attributeAwareNode, $startAndEnd, $output); + return $this->printPhpDocTagNode($node, $startAndEnd, $output); } - return $output . self::NEWLINE_ASTERISK . $this->printAttributeWithAsterisk($attributeAwareNode); + return $output . self::NEWLINE_ASTERISK . $this->printAttributeWithAsterisk($node); } - if (! $attributeAwareNode instanceof PhpDocTextNode && ! $attributeAwareNode instanceof GenericTagValueNode && $startAndEnd) { - $nodeContent = (string) $attributeAwareNode; + if (! $node instanceof PhpDocTextNode && ! $node instanceof GenericTagValueNode && $startAndEnd) { + $nodeContent = (string) $node; return $this->originalSpacingRestorer->restoreInOutputWithTokensStartAndEndPosition( - $attributeAwareNode, + $node, $nodeContent, $this->tokens, $startAndEnd ); } - return $output . $this->printAttributeWithAsterisk($attributeAwareNode); + return $output . $this->printAttributeWithAsterisk($node); } private function printEnd(string $output): string @@ -269,6 +270,9 @@ private function printEnd(string $output): string $lastTokenPosition = $this->attributeAwarePhpDocNode->getAttribute( Attribute::LAST_TOKEN_POSITION ) ?: $this->currentTokenPosition; + if ($lastTokenPosition === 0) { + $lastTokenPosition = 1; + } return $this->addTokensFromTo($output, $lastTokenPosition, $this->tokenCount, true); } @@ -301,20 +305,13 @@ private function addTokensFromTo( return $this->appendToOutput($output, $from, $to, $positionJumpSet); } - /** - * @param PhpDocTagNode|AttributeAwareNodeInterface $phpDocTagNode - */ private function printPhpDocTagNode( PhpDocTagNode $phpDocTagNode, StartAndEnd $startAndEnd, string $output ): string { $output .= $phpDocTagNode->name; - $phpDocTagNodeValue = $phpDocTagNode->value; - if (! $phpDocTagNodeValue instanceof AttributeAwareNodeInterface) { - throw new ShouldNotHappenException(); - } $nodeOutput = $this->printNode($phpDocTagNodeValue, $startAndEnd); $tagSpaceSeparator = $this->resolveTagSpaceSeparator($phpDocTagNode); @@ -341,10 +338,9 @@ private function printPhpDocTagNode( return $output . $nodeOutput; } - private function printAttributeWithAsterisk(AttributeAwareNodeInterface $attributeAwareNode): string + private function printAttributeWithAsterisk(Node $node): string { - $content = (string) $attributeAwareNode; - + $content = (string) $node; return $this->explodeAndImplode($content, PHP_EOL, self::NEWLINE_ASTERISK); } @@ -357,24 +353,40 @@ private function getRemovedNodesPositions(): array return $this->removedNodePositions; } - /** @var AttributeAwareNodeInterface[] $removedNodes */ $removedNodes = array_diff( $this->phpDocInfo->getOriginalPhpDocNode() ->children, $this->attributeAwarePhpDocNode->children ); + $lastEndPosition = null; + foreach ($removedNodes as $removedNode) { /** @var StartAndEnd $removedPhpDocNodeInfo */ $removedPhpDocNodeInfo = $removedNode->getAttribute(Attribute::START_END); // change start position to start of the line, so the whole line is removed $seekPosition = $removedPhpDocNodeInfo->getStart(); - while ($this->tokens[$seekPosition][1] !== Lexer::TOKEN_HORIZONTAL_WS) { + + while ($seekPosition >= 0 && $this->tokens[$seekPosition][1] !== Lexer::TOKEN_HORIZONTAL_WS) { + if ($this->tokens[$seekPosition][1] === Lexer::TOKEN_PHPDOC_EOL) { + break; + } + + // do not colide + if ($lastEndPosition < $seekPosition) { + break; + } + --$seekPosition; } - $this->removedNodePositions[] = new StartAndEnd($seekPosition - 1, $removedPhpDocNodeInfo->getEnd()); + $lastEndPosition = $removedPhpDocNodeInfo->getEnd(); + + $this->removedNodePositions[] = new StartAndEnd(max( + 0, + $seekPosition - 1 + ), $removedPhpDocNodeInfo->getEnd()); } return $this->removedNodePositions; @@ -388,6 +400,7 @@ private function appendToOutput(string $output, int $from, int $to, array $posit for ($i = $from; $i < $to; ++$i) { while (isset($positionJumpSet[$i])) { $i = $positionJumpSet[$i]; + continue; } $output .= $this->tokens[$i][0] ?? ''; @@ -419,9 +432,6 @@ private function resolveTagSpaceSeparator(PhpDocTagNode $phpDocTagNode): string return ''; } - /** - * @param AttributeAwareNodeInterface&PhpDocTagNode $phpDocTagNode - */ private function hasDescription(PhpDocTagNode $phpDocTagNode): bool { $hasDescriptionWithOriginalSpaces = $phpDocTagNode->getAttribute( diff --git a/packages/BetterPhpDocParser/Printer/SpacePatternFactory.php b/packages/BetterPhpDocParser/Printer/SpacePatternFactory.php index e09b94d56cf3..ed68b7439bf9 100644 --- a/packages/BetterPhpDocParser/Printer/SpacePatternFactory.php +++ b/packages/BetterPhpDocParser/Printer/SpacePatternFactory.php @@ -4,8 +4,8 @@ namespace Rector\BetterPhpDocParser\Printer; +use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareParamTagValueNode; final class SpacePatternFactory @@ -24,7 +24,7 @@ public function createSpacePattern(PhpDocTagNode $phpDocTagNode): string return $this->createSpacePatternForParamTagValueNode($phpDocTagNode->value, $spacePattern); } - if ($phpDocTagNode->value instanceof AttributeAwareGenericTagValueNode) { + if ($phpDocTagNode->value instanceof GenericTagValueNode) { $originalValue = $phpDocTagNode->value->getAttribute('original_value') ?? $phpDocTagNode->value->value; // break by line break, to prevent false content positive diff --git a/packages/BetterPhpDocParser/Printer/WhitespaceDetector.php b/packages/BetterPhpDocParser/Printer/WhitespaceDetector.php index db9f6509ded1..3221d8368d7b 100644 --- a/packages/BetterPhpDocParser/Printer/WhitespaceDetector.php +++ b/packages/BetterPhpDocParser/Printer/WhitespaceDetector.php @@ -8,8 +8,6 @@ use Nette\Utils\Strings; use PHPStan\PhpDocParser\Ast\Node; use PHPStan\PhpDocParser\Lexer\Lexer; -use Rector\BetterPhpDocParser\Contract\Doctrine\DoctrineTagNodeInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\ValueObject\StartAndEnd; final class WhitespaceDetector @@ -29,11 +27,6 @@ public function detectOldWhitespaces(Node $node, array $tokens, StartAndEnd $sta $oldWhitespaces = []; $start = $startAndEnd->getStart(); - // this is needed, because of 1 token taken from tokens and added annotation name: "ORM" + "\X" → "ORM\X" - // todo, this might be needed to be dynamic, based on taken tokens count (some Collector?) - if ($node instanceof DoctrineTagNodeInterface) { - --$start; - } for ($i = $start; $i < $startAndEnd->getEnd(); ++$i) { /** @var string $tokenValue */ @@ -42,11 +35,7 @@ public function detectOldWhitespaces(Node $node, array $tokens, StartAndEnd $sta if ($tokens[$i][1] === Lexer::TOKEN_HORIZONTAL_WS) { // give back "\s+\*" as well // do not overlap to previous node - if (($node instanceof DoctrineTagNodeInterface || $node instanceof ShortNameAwareTagInterface) && - $i - 1 > $start && - isset($tokens[$i - 1]) && - $tokens[$i - 1][1] === Lexer::TOKEN_PHPDOC_EOL - ) { + if ($i - 1 > $start && isset($tokens[$i - 1]) && $tokens[$i - 1][1] === Lexer::TOKEN_PHPDOC_EOL) { $previousTokenValue = $tokens[$i - 1][0]; if (Strings::match($previousTokenValue, self::SPACE_BEFORE_ASTERISK_REGEX)) { $tokenValue = $previousTokenValue . $tokenValue; @@ -57,6 +46,14 @@ public function detectOldWhitespaces(Node $node, array $tokens, StartAndEnd $sta continue; } + // fixes phpdoc parser multiline spaces BC break https://github.com/phpstan/phpdoc-parser/commit/b451b2f27a97c8c288de63db79c2a843727d4326 + if ($tokens[$i][1] === Lexer::TOKEN_PHPDOC_EOL) { + $nextToken = $tokens[$i + 1]; + if ($nextToken[1] !== Lexer::TOKEN_HORIZONTAL_WS) { + $oldWhitespaces[] = $tokens[$i][0]; + } + } + // quoted string with spaces? if ($this->isQuotedStringWithSpaces($tokens, $i)) { $matches = Strings::matchAll($tokenValue, '#\s+#m'); diff --git a/packages/BetterPhpDocParser/ValueObject/NodeTypes.php b/packages/BetterPhpDocParser/ValueObject/NodeTypes.php new file mode 100644 index 000000000000..2907ffb27156 --- /dev/null +++ b/packages/BetterPhpDocParser/ValueObject/NodeTypes.php @@ -0,0 +1,36 @@ +> + */ + public const TYPE_AWARE_NODES = [ + VarTagValueNode::class, + ParamTagValueNode::class, + ReturnTagValueNode::class, + ThrowsTagValueNode::class, + PropertyTagValueNode::class, + SerializerTypeTagValueNode::class, + OneToManyTagValueNode::class, + AssertChoiceTagValueNode::class, + AssertEmailTagValueNode::class, + AssertRangeTagValueNode::class, + ]; +} diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php index 98dd84c68f2b..656c57f4652d 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/AbstractTagValueNode.php @@ -5,9 +5,9 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode; use Nette\Utils\Strings; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\BetterPhpDocParser\Contract\PhpDocNode\TagAwareNodeInterface; use Rector\BetterPhpDocParser\Printer\ArrayPartPhpDocTagPrinter; use Rector\BetterPhpDocParser\Printer\TagValueNodePrinter; @@ -17,9 +17,9 @@ use Rector\Core\Exception\ShouldNotHappenException; use Symplify\PackageBuilder\Php\TypeChecker; -abstract class AbstractTagValueNode implements AttributeAwareNodeInterface, PhpDocTagValueNode +abstract class AbstractTagValueNode implements PhpDocTagValueNode { - use AttributeTrait; + use NodeAttributes; /** * @var mixed[] diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/ApiPhpDocTagNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/ApiPhpDocTagNode.php index 3715ad1c05df..7dd6d84b01bb 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/ApiPhpDocTagNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/ApiPhpDocTagNode.php @@ -4,18 +4,14 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode; +use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; /** * @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\ApiPhpDocNodeFactory */ -final class ApiPhpDocTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface +final class ApiPhpDocTagNode extends PhpDocTagNode { - use AttributeTrait; - /** * @var string */ @@ -23,7 +19,7 @@ final class ApiPhpDocTagNode extends PhpDocTagNode implements AttributeAwareNode public function __construct() { - parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode('')); + parent::__construct(self::NAME, new GenericTagValueNode('')); } public function __toString(): string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Doctrine/Property_/OneToManyTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Doctrine/Property_/OneToManyTagValueNode.php index 2d98578a9401..de043b988536 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Doctrine/Property_/OneToManyTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Doctrine/Property_/OneToManyTagValueNode.php @@ -6,12 +6,11 @@ use Rector\BetterPhpDocParser\Contract\Doctrine\MappedByNodeInterface; use Rector\BetterPhpDocParser\Contract\Doctrine\ToManyTagNodeInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\BetterPhpDocParser\Printer\ArrayPartPhpDocTagPrinter; use Rector\BetterPhpDocParser\Printer\TagValueNodePrinter; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode; -final class OneToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface, TypeAwareTagValueNodeInterface +final class OneToManyTagValueNode extends AbstractDoctrineTagValueNode implements ToManyTagNodeInterface, MappedByNodeInterface { /** * @var string|null diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/JMS/SerializerTypeTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/JMS/SerializerTypeTagValueNode.php index 7bcdb28bf7f6..368502e004ed 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/JMS/SerializerTypeTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/JMS/SerializerTypeTagValueNode.php @@ -7,10 +7,9 @@ use Nette\Utils\Strings; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode; -final class SerializerTypeTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, SilentKeyNodeInterface +final class SerializerTypeTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface { /** * @var string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteCrossOriginTagNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteCrossOriginTagNode.php index 9d5d2f7635e0..47b9c71957e2 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteCrossOriginTagNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteCrossOriginTagNode.php @@ -4,16 +4,13 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette; +use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface; -final class NetteCrossOriginTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface +final class NetteCrossOriginTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface { - use AttributeTrait; - /** * @var string */ @@ -21,7 +18,7 @@ final class NetteCrossOriginTagNode extends PhpDocTagNode implements PhpAttribut public function __construct() { - parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode('')); + parent::__construct(self::NAME, new GenericTagValueNode('')); } public function getShortName(): string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteInjectTagNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteInjectTagNode.php index 6ee8ae286c18..de922237d64d 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteInjectTagNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NetteInjectTagNode.php @@ -4,19 +4,16 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette; +use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface; /** * @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\NetteInjectPhpDocNodeFactory */ -final class NetteInjectTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface +final class NetteInjectTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface { - use AttributeTrait; - /** * @var string */ @@ -24,7 +21,7 @@ final class NetteInjectTagNode extends PhpDocTagNode implements PhpAttributableT public function __construct() { - parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode('')); + parent::__construct(self::NAME, new GenericTagValueNode('')); } public function getShortName(): string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NettePersistentTagNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NettePersistentTagNode.php index 8e501a21e77e..0262ace8ba26 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NettePersistentTagNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Nette/NettePersistentTagNode.php @@ -4,19 +4,16 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette; +use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface; /** * @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\NettePersistentPhpDocNodeFactory */ -final class NettePersistentTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface, AttributeAwareNodeInterface +final class NettePersistentTagNode extends PhpDocTagNode implements PhpAttributableTagNodeInterface { - use AttributeTrait; - /** * @var string */ @@ -24,7 +21,7 @@ final class NettePersistentTagNode extends PhpDocTagNode implements PhpAttributa public function __construct() { - parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode('')); + parent::__construct(self::NAME, new GenericTagValueNode('')); } public function getShortName(): string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDataProviderTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDataProviderTagValueNode.php index 457d4d2fba28..c446b75cbaa0 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDataProviderTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDataProviderTagValueNode.php @@ -4,13 +4,12 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\PHPUnit; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; -final class PHPUnitDataProviderTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface +final class PHPUnitDataProviderTagValueNode implements PhpDocTagValueNode { - use AttributeTrait; + use NodeAttributes; /** * @var string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDoesNotPerformAssertionTagNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDoesNotPerformAssertionTagNode.php index 2e076e49e6ce..85944153028c 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDoesNotPerformAssertionTagNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitDoesNotPerformAssertionTagNode.php @@ -4,18 +4,14 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\PHPUnit; +use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareGenericTagValueNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; /** * @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\PHPUnitDataDoesNotPerformAssertionDocNodeFactory */ -final class PHPUnitDoesNotPerformAssertionTagNode extends PhpDocTagNode implements AttributeAwareNodeInterface +final class PHPUnitDoesNotPerformAssertionTagNode extends PhpDocTagNode { - use AttributeTrait; - /** * @var string */ @@ -23,6 +19,6 @@ final class PHPUnitDoesNotPerformAssertionTagNode extends PhpDocTagNode implemen public function __construct() { - parent::__construct(self::NAME, new AttributeAwareGenericTagValueNode('')); + parent::__construct(self::NAME, new GenericTagValueNode('')); } } diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitExpectedExceptionTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitExpectedExceptionTagValueNode.php index 8f4ad9f0d9a1..b3c01b03946d 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitExpectedExceptionTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/PHPUnit/PHPUnitExpectedExceptionTagValueNode.php @@ -4,17 +4,16 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\PHPUnit; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; -use Rector\BetterPhpDocParser\Attributes\Attribute\AttributeTrait; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; /** * @see \Rector\BetterPhpDocParser\PhpDocNodeFactory\StringMatchingPhpDocNodeFactory\PHPUnitExpectedExceptionDocNodeFactory */ -final class PHPUnitExpectedExceptionTagValueNode implements PhpDocTagValueNode, AttributeAwareNodeInterface +final class PHPUnitExpectedExceptionTagValueNode implements PhpDocTagValueNode { - use AttributeTrait; + use NodeAttributes; /** * @var string diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php index ab488d04d068..f33cffa7d72b 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertChoiceTagValueNode.php @@ -6,13 +6,12 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode; /** * @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest */ -final class AssertChoiceTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, SilentKeyNodeInterface +final class AssertChoiceTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, SilentKeyNodeInterface { public function isCallbackClass(string $class): bool { diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertEmailTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertEmailTagValueNode.php index e23df22babbc..57cedbeb8420 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertEmailTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertEmailTagValueNode.php @@ -6,14 +6,13 @@ use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; use Rector\BetterPhpDocParser\Contract\PhpDocNode\SilentKeyNodeInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode; use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface; /** * @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\TagValueNodeReprint\TagValueNodeReprintTest */ -final class AssertEmailTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, PhpAttributableTagNodeInterface, SilentKeyNodeInterface +final class AssertEmailTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, PhpAttributableTagNodeInterface, SilentKeyNodeInterface { public function getShortName(): string { diff --git a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertRangeTagValueNode.php b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertRangeTagValueNode.php index c93add2319e4..ae32815ad03f 100644 --- a/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertRangeTagValueNode.php +++ b/packages/BetterPhpDocParser/ValueObject/PhpDocNode/Symfony/Validator/Constraints/AssertRangeTagValueNode.php @@ -5,11 +5,10 @@ namespace Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Symfony\Validator\Constraints; use Rector\BetterPhpDocParser\Contract\PhpDocNode\ShortNameAwareTagInterface; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\AbstractTagValueNode; use Rector\PhpAttribute\Contract\PhpAttributableTagNodeInterface; -final class AssertRangeTagValueNode extends AbstractTagValueNode implements TypeAwareTagValueNodeInterface, ShortNameAwareTagInterface, PhpAttributableTagNodeInterface +final class AssertRangeTagValueNode extends AbstractTagValueNode implements ShortNameAwareTagInterface, PhpAttributableTagNodeInterface { public function getShortName(): string { diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php index 7973fb2953c0..2fffc5de97ec 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php @@ -7,6 +7,8 @@ use PhpParser\Node; use PhpParser\Node\Name; use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ArrayType; @@ -20,10 +22,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareUnionTypeNode; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeCommonTypeNarrower; @@ -189,10 +188,10 @@ private function isGenericArrayCandidate(ArrayType $arrayType): bool return false; } - private function createGenericArrayType(ArrayType $arrayType, bool $withKey = false): AttributeAwareGenericTypeNode + private function createGenericArrayType(ArrayType $arrayType, bool $withKey = false): GenericTypeNode { $itemTypeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($arrayType->getItemType()); - $attributeAwareIdentifierTypeNode = new AttributeAwareIdentifierTypeNode('array'); + $identifierTypeNode = new IdentifierTypeNode('array'); // is class-string[] list only if ($this->isClassStringArrayType($arrayType)) { @@ -209,13 +208,12 @@ private function createGenericArrayType(ArrayType $arrayType, bool $withKey = fa // @see https://github.com/phpstan/phpdoc-parser/blob/98a088b17966bdf6ee25c8a4b634df313d8aa531/tests/PHPStan/Parser/PhpDocParserTest.php#L2692-L2696 foreach ($genericTypes as $genericType) { - /** @var AttributeAwareNodeInterface $genericType */ + /** @var \PHPStan\PhpDocParser\Ast\Node $genericType */ $genericType->setAttribute(self::HAS_GENERIC_TYPE_PARENT, $withKey); } - $attributeAwareIdentifierTypeNode->setAttribute(self::HAS_GENERIC_TYPE_PARENT, $withKey); - - return new AttributeAwareGenericTypeNode($attributeAwareIdentifierTypeNode, $genericTypes); + $identifierTypeNode->setAttribute(self::HAS_GENERIC_TYPE_PARENT, $withKey); + return new GenericTypeNode($identifierTypeNode, $genericTypes); } private function mapArrayUnionTypeToDocString(ArrayType $arrayType, UnionType $unionType): string @@ -264,15 +262,15 @@ private function narrowConstantArrayTypeOfUnionType(ArrayType $arrayType, Type $ private function createTypeNodeFromGenericClassStringType( GenericClassStringType $genericClassStringType - ): AttributeAwareNodeInterface { + ): TypeNode { $genericType = $genericClassStringType->getGenericType(); if ($genericType instanceof ObjectType && ! $this->reflectionProvider->hasClass($genericType->getClassName())) { - return new AttributeAwareIdentifierTypeNode($genericType->getClassName()); + return new IdentifierTypeNode($genericType->getClassName()); } $itemTypeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($genericClassStringType); - return new AttributeAwareGenericTypeNode(new AttributeAwareIdentifierTypeNode('array'), [$itemTypeNode]); + return new GenericTypeNode(new IdentifierTypeNode('array'), [$itemTypeNode]); } private function isClassStringArrayType(ArrayType $arrayType): bool diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php index ecafc1e75d41..b50bd6e0706a 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/BooleanTypeMapper.php @@ -6,10 +6,10 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\BooleanType; use PHPStan\Type\Type; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -41,10 +41,10 @@ public function getNodeClass(): string public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { if ($this->isFalseBooleanTypeWithUnion($type)) { - return new AttributeAwareIdentifierTypeNode('false'); + return new IdentifierTypeNode('false'); } - return new AttributeAwareIdentifierTypeNode('bool'); + return new IdentifierTypeNode('bool'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php index 7d3c9cfd6b13..8daa8d3abe60 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ClassStringTypeMapper.php @@ -6,14 +6,14 @@ use PhpParser\Node; use PhpParser\Node\Expr; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\ClassStringType; use PHPStan\Type\Generic\GenericClassStringType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\PHPStanStaticTypeMapperAwareInterface; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper; @@ -38,7 +38,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - $attributeAwareIdentifierTypeNode = new AttributeAwareIdentifierTypeNode('class-string'); + $attributeAwareIdentifierTypeNode = new IdentifierTypeNode('class-string'); if ($type instanceof GenericClassStringType) { $genericType = $type->getGenericType(); @@ -49,7 +49,7 @@ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode } $genericTypeNode = $this->phpStanStaticTypeMapper->mapToPHPStanPhpDocTypeNode($genericType); - return new AttributeAwareGenericTypeNode($attributeAwareIdentifierTypeNode, [$genericTypeNode]); + return new GenericTypeNode($attributeAwareIdentifierTypeNode, [$genericTypeNode]); } return $attributeAwareIdentifierTypeNode; diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/FloatTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/FloatTypeMapper.php index 9d4f34c08502..17bbf0a47ba2 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/FloatTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/FloatTypeMapper.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\FloatType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -40,7 +40,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('float'); + return new IdentifierTypeNode('float'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/IntegerTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/IntegerTypeMapper.php index 3b1dbf3ca0de..1829257c4a93 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/IntegerTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/IntegerTypeMapper.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\IntegerType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -40,7 +40,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('int'); + return new IdentifierTypeNode('int'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php index d0a123a5b569..42fbea74b4af 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php @@ -5,11 +5,11 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper; use PhpParser\Node; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class MixedTypeMapper implements TypeMapperInterface @@ -27,7 +27,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('mixed'); + return new IdentifierTypeNode('mixed'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/NeverTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/NeverTypeMapper.php index 83228e37096a..edf44348c7b9 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/NeverTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/NeverTypeMapper.php @@ -5,10 +5,10 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper; use PhpParser\Node; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\NeverType; use PHPStan\Type\Type; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class NeverTypeMapper implements TypeMapperInterface @@ -26,7 +26,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('mixed'); + return new IdentifierTypeNode('mixed'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/NonEmptyArrayTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/NonEmptyArrayTypeMapper.php index 485bf2b8989e..484a7ad3f85d 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/NonEmptyArrayTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/NonEmptyArrayTypeMapper.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Accessory\NonEmptyArrayType; use PHPStan\Type\Type; use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class NonEmptyArrayTypeMapper implements TypeMapperInterface @@ -28,7 +28,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareArrayTypeNode(new AttributeAwareIdentifierTypeNode('mixed')); + return new AttributeAwareArrayTypeNode(new IdentifierTypeNode('mixed')); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/NullTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/NullTypeMapper.php index 9f0dbfedc8fd..438d11e9fa58 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/NullTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/NullTypeMapper.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\NullType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind; @@ -29,7 +29,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('null'); + return new IdentifierTypeNode('null'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectTypeMapper.php index f66a81139e25..5d99bc37d6c7 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectTypeMapper.php @@ -8,6 +8,7 @@ use PhpParser\Node; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Reflection\ReflectionProvider; @@ -16,8 +17,6 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\PHPStanStaticTypeMapperAwareInterface; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper; @@ -58,18 +57,18 @@ public function getNodeClass(): string public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { if ($type instanceof ShortenedObjectType) { - return new AttributeAwareIdentifierTypeNode($type->getClassName()); + return new IdentifierTypeNode($type->getClassName()); } if ($type instanceof AliasedObjectType) { - return new AttributeAwareIdentifierTypeNode($type->getClassName()); + return new IdentifierTypeNode($type->getClassName()); } if ($type instanceof GenericObjectType) { return $this->mapGenericObjectType($type); } - return new AttributeAwareIdentifierTypeNode('\\' . $type->getClassName()); + return new IdentifierTypeNode('\\' . $type->getClassName()); } /** @@ -143,7 +142,7 @@ public function setPHPStanStaticTypeMapper(PHPStanStaticTypeMapper $phpStanStati $this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper; } - private function mapGenericObjectType(GenericObjectType $genericObjectType): AttributeAwareGenericTypeNode + private function mapGenericObjectType(GenericObjectType $genericObjectType): TypeNode { $name = $this->resolveGenericObjectTypeName($genericObjectType); $identifierTypeNode = new IdentifierTypeNode($name); @@ -159,7 +158,11 @@ private function mapGenericObjectType(GenericObjectType $genericObjectType): Att $genericTypeNodes[] = $typeNode; } - return new AttributeAwareGenericTypeNode($identifierTypeNode, $genericTypeNodes); + if ($genericTypeNodes === []) { + return $identifierTypeNode; + } + + return new GenericTypeNode($identifierTypeNode, $genericTypeNodes); } private function resolveGenericObjectTypeName(GenericObjectType $genericObjectType): string diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectWithoutClassTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectWithoutClassTypeMapper.php index be844df25895..e4522091bb9d 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectWithoutClassTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectWithoutClassTypeMapper.php @@ -6,13 +6,13 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Generic\TemplateObjectWithoutClassType; use PHPStan\Type\ObjectWithoutClassType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; +use Rector\AttributeAwarePhpDoc\Ast\Type\EmptyGenericTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\PHPStanStaticTypeMapperAwareInterface; @@ -50,11 +50,11 @@ public function getNodeClass(): string public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { if ($type instanceof TemplateObjectWithoutClassType) { - $attributeAwareIdentifierTypeNode = new AttributeAwareIdentifierTypeNode($type->getName()); - return new AttributeAwareGenericTypeNode($attributeAwareIdentifierTypeNode, []); + $attributeAwareIdentifierTypeNode = new IdentifierTypeNode($type->getName()); + return new EmptyGenericTypeNode($attributeAwareIdentifierTypeNode); } - return new AttributeAwareIdentifierTypeNode('object'); + return new IdentifierTypeNode('object'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ParentStaticTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ParentStaticTypeMapper.php index 1892865cc21d..08492c904df7 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ParentStaticTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ParentStaticTypeMapper.php @@ -6,10 +6,10 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\StaticTypeMapper\ValueObject\Type\ParentStaticType; @@ -28,7 +28,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('parent'); + return new IdentifierTypeNode('parent'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ResourceTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ResourceTypeMapper.php index 424fb30b2807..191fe60b63b5 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ResourceTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ResourceTypeMapper.php @@ -5,11 +5,11 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper; use PhpParser\Node; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\ResourceType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class ResourceTypeMapper implements TypeMapperInterface @@ -27,7 +27,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('resource'); + return new IdentifierTypeNode('resource'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php index d36517e60f0c..952ec472cf69 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php @@ -6,10 +6,10 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; use Rector\StaticTypeMapper\ValueObject\Type\SelfObjectType; @@ -28,7 +28,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('self'); + return new IdentifierTypeNode('self'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/StaticTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/StaticTypeMapper.php index 222f2e0354a5..0f5ab7b112d1 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/StaticTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/StaticTypeMapper.php @@ -6,12 +6,12 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\StaticType; use PHPStan\Type\ThisType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareThisTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -44,7 +44,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareThisTypeNode(); + return new ThisTypeNode(); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php index a8cf36b47074..ff60db8b2c2a 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php @@ -6,10 +6,10 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\StrictMixedType; use PHPStan\Type\Type; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class StrictMixedTypeMapper implements TypeMapperInterface @@ -32,7 +32,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode(self::MIXED); + return new IdentifierTypeNode(self::MIXED); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/StringTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/StringTypeMapper.php index 6dd41552ebea..00d029775192 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/StringTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/StringTypeMapper.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\StringType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -40,7 +40,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('string'); + return new IdentifierTypeNode('string'); } public function mapToPhpParserNode(Type $type, ?string $kind = null): ?Node diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php index 29139329ed46..b7efa6978e30 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php @@ -6,11 +6,11 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\ThisType; use PHPStan\Type\Type; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareThisTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class ThisTypeMapper implements TypeMapperInterface @@ -28,7 +28,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareThisTypeNode(); + return new ThisTypeNode(); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/TypeWithClassNameTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/TypeWithClassNameTypeMapper.php index 07bad8af1cd8..dca20a2c990a 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/TypeWithClassNameTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/TypeWithClassNameTypeMapper.php @@ -5,11 +5,11 @@ namespace Rector\PHPStanStaticTypeMapper\TypeMapper; use PhpParser\Node; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; use PHPStan\Type\VerbosityLevel; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; final class TypeWithClassNameTypeMapper implements TypeMapperInterface @@ -37,7 +37,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode('string-class'); + return new IdentifierTypeNode('string-class'); } /** diff --git a/packages/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php b/packages/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php index 96058756f7a3..586cac23b896 100644 --- a/packages/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php +++ b/packages/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php @@ -6,10 +6,10 @@ use PhpParser\Node; use PhpParser\Node\Name; +use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\Type; use PHPStan\Type\VoidType; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\Core\Php\PhpVersionProvider; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -44,7 +44,7 @@ public function getNodeClass(): string */ public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode { - return new AttributeAwareIdentifierTypeNode(self::VOID); + return new IdentifierTypeNode(self::VOID); } /** diff --git a/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php b/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php index 62e8417585e2..ab59951b06ee 100644 --- a/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php +++ b/packages/StaticTypeMapper/PhpDocParser/IdentifierTypeMapper.php @@ -14,7 +14,6 @@ use PHPStan\Type\ObjectType; use PHPStan\Type\StaticType; use PHPStan\Type\Type; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareIdentifierTypeNode; use Rector\NodeCollector\ScopeResolver\ParentClassScopeResolver; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface; @@ -56,7 +55,7 @@ public function getNodeType(): string } /** - * @param AttributeAwareIdentifierTypeNode&IdentifierTypeNode $typeNode + * @param IdentifierTypeNode $typeNode */ public function mapToPHPStanType(TypeNode $typeNode, Node $node, NameScope $nameScope): Type { diff --git a/phpstan.neon b/phpstan.neon index fcbc7d4653a7..6b4c5e6403f8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -118,6 +118,7 @@ parameters: - message: '#Class cognitive complexity is \d+, keep it under \d+#' paths: + - packages/BetterPhpDocParser/Printer/PhpDocInfoPrinter.php - rules/Php70/EregToPcreTransformer.php - packages/NodeCollector/NodeCollector/NodeRepository.php - packages/NodeTypeResolver/NodeTypeResolver.php @@ -275,9 +276,6 @@ parameters: - rules/Php70/Rector/FuncCall/MultiDirnameRector.php - '#PHPDoc tag @param for parameter \$node with type float is incompatible with native type PhpParser\\Node#' - # intersection mess - - '#Parameter \#1 \$phpDocTagNodes of method Rector\\PHPUnit\\NodeFactory\\ExpectExceptionMethodCallFactory\:\:createFromTagValueNodes\(\) expects array, array given#' - # false postives - '#Parameter \#2 \$right of class PhpParser\\Node\\Expr\\BinaryOp\\Spaceship constructor expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|null given#' - '#Parameter \#1 \$stmts of class Rector\\Core\\PhpParser\\Node\\CustomNode\\FileWithoutNamespace constructor expects array, array given#' @@ -305,9 +303,6 @@ parameters: # unable to test, because the method is final - '#Class "Rector\\Nette\\Rector\\Class_\\MoveFinalGetUserToCheckRequirementsClassMethodRector" is missing @see annotation with test case class reference#' - # type juggling - - '#AttributeAwareNodeInterface#' - - message: '#Use `\$class\-\>namespaceName` instead of `\$class\-\>name` that only returns short class name#' paths: @@ -365,6 +360,7 @@ parameters: - '#Parameter \#1 \$nodes of method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findFirst\(\) expects array\|PhpParser\\Node, array\|null given#' - '#Parameter \#2 \$type of method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findInstanceOfName\(\) expects class\-string, string given#' - '#Method Rector\\Core\\PhpParser\\Node\\BetterNodeFinder\:\:findVariableOfName\(\) should return PhpParser\\Node\\Expr\\Variable\|null but returns T of PhpParser\\Node\|null#' + - '#Method Rector\\AttributeAwarePhpDoc\\AttributeAwareNodeFactory\\PhpDoc\\AttributeAwareTemplateTagValueNodeFactory\:\:create\(\) should return T of PHPStan\\PhpDocParser\\Ast\\Node but returns Rector\\AttributeAwarePhpDoc\\Ast\\PhpDoc\\AttributeAwareTemplateTagValueNode#' # fixed in php-parser master - '#Method Rector\\Symfony\\NodeFactory\\RouteNameClassFactory\:\:create\(\) should return PhpParser\\Node\\Stmt\\Namespace_ but returns PhpParser\\Node#' @@ -590,3 +586,15 @@ parameters: - message: '#Function "interface_exists\(\)" cannot be used/left in the code#' path: packages/Testing/PhpConfigPrinter/config/php-config-printer-config.php + + # generics fails + - '#Method Rector\\BetterPhpDocParser\\Attributes\\Ast\\AttributeAwareNodeFactory\:\:createFromNode\(\) should return T of PHPStan\\PhpDocParser\\Ast\\Node but returns PHPStan\\PhpDocParser\\Ast\\Node#' + - '#Method Rector\\AttributeAwarePhpDoc\\AttributeAwareNodeFactory\\Type\\AttributeAwareIntersectionTypeNodeFactory\:\:create\(\) should return T of PHPStan\\PhpDocParser\\Ast\\Node but returns Rector\\AttributeAwarePhpDoc\\Ast\\Type\\AttributeAwareIntersectionTypeNode#' + - '#Method Rector\\BetterPhpDocParser\\PhpDocInfo\\PhpDocInfo\:\:findAllByType\(\) should return array but returns array#' + + # PHP 7_4 literal syntax + - '#Property PhpParser\\Node\\Scalar\\DNumber\:\:\$value \(float\|int\) does not accept string#' + + - '#Cognitive complexity for "Rector\\BetterPhpDocParser\\Printer\\WhitespaceDetector\:\:detectOldWhitespaces\(\)" is 20, keep it under 9#' + - '#Method Rector\\PHPStanStaticTypeMapper\\TypeMapper\\ArrayTypeMapper\:\:narrowConstantArrayTypeOfUnionType\(\) should return PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode\|null but returns PHPStan\\PhpDocParser\\Ast\\Node#' + - '#Method Rector\\PHPStanStaticTypeMapper\\TypeMapper\\ObjectTypeMapper\:\:mapToPHPStanPhpDocTypeNode\(\) should return PHPStan\\PhpDocParser\\Ast\\Type\\TypeNode but returns PHPStan\\PhpDocParser\\Ast\\Node#' diff --git a/rector.php b/rector.php index eb4e22b89fcc..b3caa3cbefd8 100644 --- a/rector.php +++ b/rector.php @@ -14,6 +14,7 @@ use Rector\Restoration\Rector\ClassMethod\InferParamFromClassMethodReturnRector; use Rector\Restoration\ValueObject\InferParamFromClassMethodReturn; use Rector\Set\ValueObject\SetList; +use Rector\TypeDeclaration\Rector\FunctionLike\ReturnTypeDeclarationRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\SymfonyPhpConfig\ValueObjectInliner; @@ -74,6 +75,11 @@ PrivatizeLocalPropertyToPrivatePropertyRector::class => [__DIR__ . '/src/Rector/AbstractRector.php'], + ReturnTypeDeclarationRector::class => [ + __DIR__ . '/packages/PHPStanStaticTypeMapper/TypeMapper/ArrayTypeMapper.php', + __DIR__ . '/packages/PHPStanStaticTypeMapper/TypeMapper/ObjectTypeMapper.php', + ], + // test paths '*/Fixture/*', '*/Fixture/*', diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_union_array.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_union_array.php.inc index dde6b25154dc..41f9f13cae34 100644 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_union_array.php.inc +++ b/rules-tests/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector/Fixture/skip_union_array.php.inc @@ -3,16 +3,16 @@ namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\AddArrayReturnDocTypeRector\Fixture; use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; +use PHPStan\PhpDocParser\Ast\PhpDoc\TemplateTagValueNode; class SkipUnionArray { /** - * @return PhpDocTagNode[]|AttributeAwareNodeInterface[] + * @return PhpDocTagNode[]|TemplateTagValueNode[] */ public function getTags(array $tags): array { - /** @var PhpDocTagNode[]|AttributeAwareNodeInterface[] $tags */ + /** @var PhpDocTagNode[]|TemplateTagValueNode[] $tags */ return $tags; } } diff --git a/rules-tests/TypeDeclaration/Rector/FunctionLike/ParamTypeDeclarationRector/FixtureUnionType/undesired_int.php.inc b/rules-tests/TypeDeclaration/Rector/FunctionLike/ParamTypeDeclarationRector/FixtureUnionType/undesired_int.php.inc new file mode 100644 index 000000000000..0b9d61e74239 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/FunctionLike/ParamTypeDeclarationRector/FixtureUnionType/undesired_int.php.inc @@ -0,0 +1,24 @@ + +----- + diff --git a/rules/CodeQualityStrict/Rector/Stmt/VarInlineAnnotationToAssertRector.php b/rules/CodeQualityStrict/Rector/Stmt/VarInlineAnnotationToAssertRector.php index 76fe34e7af26..8750bd7b2013 100644 --- a/rules/CodeQualityStrict/Rector/Stmt/VarInlineAnnotationToAssertRector.php +++ b/rules/CodeQualityStrict/Rector/Stmt/VarInlineAnnotationToAssertRector.php @@ -109,12 +109,12 @@ public function refactor(Node $node): ?Node private function getVarDocVariableName(PhpDocInfo $phpDocInfo): ?string { - $attributeAwareVarTagValueNode = $phpDocInfo->getVarTagValueNode(); - if (! $attributeAwareVarTagValueNode instanceof VarTagValueNode) { + $varTagValueNode = $phpDocInfo->getVarTagValueNode(); + if (! $varTagValueNode instanceof VarTagValueNode) { return null; } - $variableName = $attributeAwareVarTagValueNode->variableName; + $variableName = $varTagValueNode->variableName; // no variable if ($variableName === '') { return null; diff --git a/rules/DeadDocBlock/DeadParamTagValueNodeAnalyzer.php b/rules/DeadDocBlock/DeadParamTagValueNodeAnalyzer.php index 54d032c16899..3e412f1bf684 100644 --- a/rules/DeadDocBlock/DeadParamTagValueNodeAnalyzer.php +++ b/rules/DeadDocBlock/DeadParamTagValueNodeAnalyzer.php @@ -7,7 +7,7 @@ use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; @@ -48,7 +48,7 @@ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $funct return false; } - if ($paramTagValueNode->type instanceof AttributeAwareGenericTypeNode) { + if ($paramTagValueNode->type instanceof GenericTypeNode) { return false; } diff --git a/rules/DeadDocBlock/DeadReturnTagValueNodeAnalyzer.php b/rules/DeadDocBlock/DeadReturnTagValueNodeAnalyzer.php index 5eee9fa80eeb..4abf53800399 100644 --- a/rules/DeadDocBlock/DeadReturnTagValueNodeAnalyzer.php +++ b/rules/DeadDocBlock/DeadReturnTagValueNodeAnalyzer.php @@ -6,7 +6,7 @@ use PhpParser\Node\FunctionLike; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use Rector\NodeTypeResolver\TypeComparator\TypeComparator; final class DeadReturnTagValueNodeAnalyzer @@ -34,7 +34,7 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, FunctionLike $fun return false; } - if ($returnTagValueNode->type instanceof AttributeAwareGenericTypeNode) { + if ($returnTagValueNode->type instanceof GenericTypeNode) { return false; } diff --git a/rules/DeadDocBlock/TagRemover/ReturnTagRemover.php b/rules/DeadDocBlock/TagRemover/ReturnTagRemover.php index 5ed9aea132df..abd5bbd85f9e 100644 --- a/rules/DeadDocBlock/TagRemover/ReturnTagRemover.php +++ b/rules/DeadDocBlock/TagRemover/ReturnTagRemover.php @@ -7,7 +7,6 @@ use PhpParser\Node\FunctionLike; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; use PHPStan\Type\Type; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\DeadDocBlock\DeadReturnTagValueNodeAnalyzer; @@ -26,15 +25,12 @@ public function __construct(DeadReturnTagValueNodeAnalyzer $deadReturnTagValueNo public function removeReturnTagIfUseless(PhpDocInfo $phpDocInfo, FunctionLike $functionLike): void { // remove existing type - $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if (! $attributeAwareReturnTagValueNode instanceof AttributeAwareReturnTagValueNode) { + $returnTagValueNode = $phpDocInfo->getReturnTagValue(); + if (! $returnTagValueNode instanceof ReturnTagValueNode) { return; } - $isReturnTagValueDead = $this->deadReturnTagValueNodeAnalyzer->isDead( - $attributeAwareReturnTagValueNode, - $functionLike - ); + $isReturnTagValueDead = $this->deadReturnTagValueNodeAnalyzer->isDead($returnTagValueNode, $functionLike); if (! $isReturnTagValueDead) { return; } diff --git a/rules/Doctrine/NodeFactory/EntityIdNodeFactory.php b/rules/Doctrine/NodeFactory/EntityIdNodeFactory.php index 6718219152a4..3aca4603ef93 100644 --- a/rules/Doctrine/NodeFactory/EntityIdNodeFactory.php +++ b/rules/Doctrine/NodeFactory/EntityIdNodeFactory.php @@ -67,8 +67,8 @@ private function decoratePropertyWithIdAnnotations(Property $property): void $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property); // add @var int - $attributeAwareVarTagValueNode = $this->phpDocTagNodeFactory->createVarTagIntValueNode(); - $phpDocInfo->addTagValueNode($attributeAwareVarTagValueNode); + $varTagValueNode = $this->phpDocTagNodeFactory->createVarTagIntValueNode(); + $phpDocInfo->addTagValueNode($varTagValueNode); // add @ORM\Id $idTagValueNode = new IdTagValueNode($this->arrayPartPhpDocTagPrinter, $this->tagValueNodePrinter); diff --git a/rules/Doctrine/PhpDocParser/Ast/PhpDoc/PhpDocTagNodeFactory.php b/rules/Doctrine/PhpDocParser/Ast/PhpDoc/PhpDocTagNodeFactory.php index 1a3a04625a9f..5175a08858b8 100644 --- a/rules/Doctrine/PhpDocParser/Ast/PhpDoc/PhpDocTagNodeFactory.php +++ b/rules/Doctrine/PhpDocParser/Ast/PhpDoc/PhpDocTagNodeFactory.php @@ -4,8 +4,8 @@ namespace Rector\Doctrine\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\PhpDoc\VarTagValueNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareVarTagValueNode; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Doctrine\Property_\ColumnTagValueNode; use Rector\BetterPhpDocParser\ValueObjectFactory\PhpDocNode\Doctrine\ColumnTagValueNodeFactory; @@ -21,10 +21,10 @@ public function __construct(ColumnTagValueNodeFactory $columnTagValueNodeFactory $this->columnTagValueNodeFactory = $columnTagValueNodeFactory; } - public function createVarTagIntValueNode(): AttributeAwareVarTagValueNode + public function createVarTagIntValueNode(): VarTagValueNode { $identifierTypeNode = new IdentifierTypeNode('int'); - return new AttributeAwareVarTagValueNode($identifierTypeNode, '', ''); + return new VarTagValueNode($identifierTypeNode, '', ''); } public function createIdColumnTagValueNode(): ColumnTagValueNode diff --git a/rules/DoctrineCodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php b/rules/DoctrineCodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php index bc1e56fc6c9e..b067dc2564de 100644 --- a/rules/DoctrineCodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php +++ b/rules/DoctrineCodeQuality/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php @@ -99,8 +99,8 @@ public function refactor(Node $node): ?Node return null; } - $attributeAwareVarTagValueNode = $phpDocInfo->getVarTagValueNode(); - if (! $attributeAwareVarTagValueNode instanceof VarTagValueNode) { + $varTagValueNode = $phpDocInfo->getVarTagValueNode(); + if (! $varTagValueNode instanceof VarTagValueNode) { return null; } diff --git a/rules/DoctrineCodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php b/rules/DoctrineCodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php index 31811b875954..49f1c1205eda 100644 --- a/rules/DoctrineCodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php +++ b/rules/DoctrineCodeQuality/Rector/Property/ImproveDoctrineCollectionDocTypeInEntityRector.php @@ -144,10 +144,10 @@ private function refactorProperty(Property $property): ?Property return null; } - $attributeAwareVarTagValueNode = $this->collectionVarTagValueNodeResolver->resolve($property); - if ($attributeAwareVarTagValueNode !== null) { + $varTagValueNode = $this->collectionVarTagValueNodeResolver->resolve($property); + if ($varTagValueNode !== null) { $collectionObjectType = $this->collectionTypeResolver->resolveFromTypeNode( - $attributeAwareVarTagValueNode->type, + $varTagValueNode->type, $property ); diff --git a/rules/NetteToSymfony/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php b/rules/NetteToSymfony/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php index 974f70865078..3c3f928e947f 100644 --- a/rules/NetteToSymfony/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php +++ b/rules/NetteToSymfony/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php @@ -17,8 +17,8 @@ use PhpParser\Node\Stmt\Return_; use PHPStan\Type\ObjectType; use Rector\Core\Rector\AbstractRector; -use Rector\NetteToSymfony\Event\EventInfosFactory; use Rector\NetteToSymfony\ValueObject\EventInfo; +use Rector\NetteToSymfony\ValueObjectFactory\EventInfosFactory; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; diff --git a/rules/NetteToSymfony/Event/EventInfosFactory.php b/rules/NetteToSymfony/ValueObjectFactory/EventInfosFactory.php similarity index 98% rename from rules/NetteToSymfony/Event/EventInfosFactory.php rename to rules/NetteToSymfony/ValueObjectFactory/EventInfosFactory.php index 1f38be9534f1..06c45d19809e 100644 --- a/rules/NetteToSymfony/Event/EventInfosFactory.php +++ b/rules/NetteToSymfony/ValueObjectFactory/EventInfosFactory.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\NetteToSymfony\Event; +namespace Rector\NetteToSymfony\ValueObjectFactory; use Rector\NetteToSymfony\ValueObject\EventInfo; diff --git a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php index ff6bad4e11de..b46cd31a65c4 100644 --- a/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php +++ b/rules/Php80/Rector/Class_/ClassPropertyAssignToConstructorPromotionRector.php @@ -173,11 +173,11 @@ private function removeClassMethodParam(ClassMethod $classMethod, string $paramN { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); - $attributeAwareParamTagValueNode = $phpDocInfo->getParamTagValueByName($paramName); - if (! $attributeAwareParamTagValueNode instanceof ParamTagValueNode) { + $paramTagValueByName = $phpDocInfo->getParamTagValueByName($paramName); + if (! $paramTagValueByName instanceof ParamTagValueNode) { return; } - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $attributeAwareParamTagValueNode); + $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $paramTagValueByName); } } diff --git a/rules/Privatization/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php b/rules/Privatization/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php index caaed4b32875..9eacb45f0f04 100644 --- a/rules/Privatization/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php +++ b/rules/Privatization/Rector/Property/PrivatizeLocalPropertyToPrivatePropertyRector.php @@ -8,9 +8,10 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; +use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocChildNode; use PHPStan\Type\ObjectType; use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\SymfonyRequiredTagNode; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\AttributeAwareNodeInterface; + use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\ApiPhpDocTagNode; use Rector\BetterPhpDocParser\ValueObject\PhpDocNode\Nette\NetteInjectTagNode; use Rector\Core\Rector\AbstractRector; @@ -25,7 +26,7 @@ final class PrivatizeLocalPropertyToPrivatePropertyRector extends AbstractRector { /** - * @var array> + * @var array> */ private const TAG_NODES_REQUIRING_PUBLIC = [ ApiPhpDocTagNode::class, diff --git a/rules/Renaming/NodeManipulator/ClassRenamer.php b/rules/Renaming/NodeManipulator/ClassRenamer.php index 7cea22cbbc23..9fa769af88e3 100644 --- a/rules/Renaming/NodeManipulator/ClassRenamer.php +++ b/rules/Renaming/NodeManipulator/ClassRenamer.php @@ -18,9 +18,9 @@ use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ObjectType; -use Rector\BetterPhpDocParser\Contract\PhpDocNode\TypeAwareTagValueNodeInterface; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocClassRenamer; +use Rector\BetterPhpDocParser\ValueObject\NodeTypes; use Rector\CodingStyle\Naming\ClassNaming; use Rector\Core\Configuration\Option; use Rector\Core\PhpParser\Node\BetterNodeFinder; @@ -144,7 +144,7 @@ public function renameNode(Node $node, array $oldToNewClasses): ?Node private function refactorPhpDoc(Node $node, array $oldToNewClasses): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); - if (! $phpDocInfo->hasByType(TypeAwareTagValueNodeInterface::class)) { + if (! $phpDocInfo->hasByTypes(NodeTypes::TYPE_AWARE_NODES)) { return; } diff --git a/rules/Renaming/Rector/Name/RenameClassRector.php b/rules/Renaming/Rector/Name/RenameClassRector.php index ada678327973..fa54de03b55f 100644 --- a/rules/Renaming/Rector/Name/RenameClassRector.php +++ b/rules/Renaming/Rector/Name/RenameClassRector.php @@ -113,6 +113,9 @@ public function refactor(Node $node): ?Node return $this->classRenamer->renameNode($node, $this->oldToNewClasses); } + /** + * @param array $configuration + */ public function configure(array $configuration): void { $this->oldToNewClasses = $configuration[self::OLD_TO_NEW_CLASSES] ?? []; diff --git a/rules/Restoration/Rector/Use_/RestoreFullyQualifiedNameRector.php b/rules/Restoration/Rector/Use_/RestoreFullyQualifiedNameRector.php index c40b65a7f0b7..a22b9f2d6023 100644 --- a/rules/Restoration/Rector/Use_/RestoreFullyQualifiedNameRector.php +++ b/rules/Restoration/Rector/Use_/RestoreFullyQualifiedNameRector.php @@ -10,10 +10,10 @@ use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Use_; +use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\MixedType; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\Core\Rector\AbstractRector; use Rector\Restoration\NameMatcher\FullyQualifiedNameMatcher; use Rector\Restoration\NameMatcher\PhpDocTypeNodeNameMatcher; @@ -149,8 +149,9 @@ private function refactorClassMethod(ClassMethod $classMethod): ?ClassMethod private function refactorReturnTagValueNode(ClassMethod $classMethod): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); - $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if (! $attributeAwareReturnTagValueNode instanceof AttributeAwareReturnTagValueNode) { + + $returnTagValueNode = $phpDocInfo->getReturnTagValue(); + if (! $returnTagValueNode instanceof ReturnTagValueNode) { return; } @@ -158,15 +159,15 @@ private function refactorReturnTagValueNode(ClassMethod $classMethod): void return; } - if ($attributeAwareReturnTagValueNode->type instanceof IdentifierTypeNode) { + if ($returnTagValueNode->type instanceof IdentifierTypeNode) { $fullyQualifiedTypeNode = $this->phpDocTypeNodeNameMatcher->matchIdentifier( - $attributeAwareReturnTagValueNode->type->name + $returnTagValueNode->type->name ); if (! $fullyQualifiedTypeNode instanceof TypeNode) { return; } - $attributeAwareReturnTagValueNode->type = $fullyQualifiedTypeNode; + $returnTagValueNode->type = $fullyQualifiedTypeNode; $phpDocInfo->markAsChanged(); } } diff --git a/rules/Symfony/TypeDeclaration/ReturnTypeDeclarationUpdater.php b/rules/Symfony/TypeDeclaration/ReturnTypeDeclarationUpdater.php new file mode 100644 index 000000000000..af9d7e75a9d5 --- /dev/null +++ b/rules/Symfony/TypeDeclaration/ReturnTypeDeclarationUpdater.php @@ -0,0 +1,94 @@ +staticTypeMapper = $staticTypeMapper; + $this->phpVersionProvider = $phpVersionProvider; + $this->nodeNameResolver = $nodeNameResolver; + $this->phpDocInfoFactory = $phpDocInfoFactory; + } + + public function updateClassMethod(ClassMethod $classMethod, string $className): void + { + $this->updatePhpDoc($classMethod, $className); + $this->updatePhp($classMethod, $className); + } + + private function updatePhpDoc(ClassMethod $classMethod, string $className): void + { + $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); + + $returnTagValueNode = $phpDocInfo->getReturnTagValue(); + if (! $returnTagValueNode instanceof ReturnTagValueNode) { + return; + } + + $returnStaticType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType( + $returnTagValueNode->type, + $classMethod + ); + + if ($returnStaticType instanceof ArrayType || $returnStaticType instanceof UnionType) { + $returnTagValueNode->type = new FullyQualifiedIdentifierTypeNode($className); + } + } + + private function updatePhp(ClassMethod $classMethod, string $className): void + { + if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) { + return; + } + + // change return type + if ($classMethod->returnType !== null) { + $returnTypeName = $this->nodeNameResolver->getName($classMethod->returnType); + if ($returnTypeName !== null && is_a($returnTypeName, $className, true)) { + return; + } + } + + $classMethod->returnType = new FullyQualified($className); + } +} diff --git a/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php b/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php index 048ef314b439..50d674057b93 100644 --- a/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php +++ b/rules/TypeDeclaration/PhpDocParser/NonInformativeReturnTagRemover.php @@ -24,7 +24,6 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VoidType; -use Rector\AttributeAwarePhpDoc\Ast\PhpDoc\AttributeAwareReturnTagValueNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; @@ -72,13 +71,13 @@ public function removeReturnTagIfNotUseful(FunctionLike $functionLike): void { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike); - $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if (! $attributeAwareReturnTagValueNode instanceof ReturnTagValueNode) { + $returnTagValueNode = $phpDocInfo->getReturnTagValue(); + if (! $returnTagValueNode instanceof ReturnTagValueNode) { return; } // useful - if ($attributeAwareReturnTagValueNode->description !== '') { + if ($returnTagValueNode->description !== '') { return; } @@ -90,15 +89,15 @@ public function removeReturnTagIfNotUseful(FunctionLike $functionLike): void return; } - $this->removeNonUniqueUselessDocNames($returnType, $attributeAwareReturnTagValueNode, $phpDocInfo); - $this->removeShortObjectType($returnType, $attributeAwareReturnTagValueNode, $phpDocInfo); - $this->removeNullableType($returnType, $attributeAwareReturnTagValueNode, $phpDocInfo); - $this->removeFullyQualifiedObjectType($returnType, $attributeAwareReturnTagValueNode, $phpDocInfo); + $this->removeNonUniqueUselessDocNames($returnType, $returnTagValueNode, $phpDocInfo); + $this->removeShortObjectType($returnType, $returnTagValueNode, $phpDocInfo); + $this->removeNullableType($returnType, $returnTagValueNode, $phpDocInfo); + $this->removeFullyQualifiedObjectType($returnType, $returnTagValueNode, $phpDocInfo); } private function removeNonUniqueUselessDocNames( Type $returnType, - AttributeAwareReturnTagValueNode $attributeAwareReturnTagValueNode, + ReturnTagValueNode $returnTagValueNode, PhpDocInfo $phpDocInfo ): void { foreach (self::USELESS_DOC_NAMES_BY_TYPE_CLASS as $typeClass => $uselessDocNames) { @@ -106,7 +105,7 @@ private function removeNonUniqueUselessDocNames( continue; } - if (! $this->isIdentifierWithValues($attributeAwareReturnTagValueNode->type, $uselessDocNames)) { + if (! $this->isIdentifierWithValues($returnTagValueNode->type, $uselessDocNames)) { continue; } @@ -117,14 +116,14 @@ private function removeNonUniqueUselessDocNames( private function removeShortObjectType( Type $returnType, - AttributeAwareReturnTagValueNode $attributeAwareReturnTagValueNode, + ReturnTagValueNode $returnTagValueNode, PhpDocInfo $phpDocInfo ): void { if (! $returnType instanceof ShortenedObjectType) { return; } - if (! $this->isIdentifierWithValues($attributeAwareReturnTagValueNode->type, [$returnType->getShortName()])) { + if (! $this->isIdentifierWithValues($returnTagValueNode->type, [$returnType->getShortName()])) { return; } @@ -133,7 +132,7 @@ private function removeShortObjectType( private function removeNullableType( Type $returnType, - AttributeAwareReturnTagValueNode $attributeAwareReturnTagValueNode, + ReturnTagValueNode $returnTagValueNode, PhpDocInfo $phpDocInfo ): void { $nullabledReturnType = $this->matchNullabledType($returnType); @@ -141,7 +140,7 @@ private function removeNullableType( return; } - $nullabledReturnTagValueNode = $this->matchNullabledReturnTagValueNode($attributeAwareReturnTagValueNode); + $nullabledReturnTagValueNode = $this->matchNullabledReturnTagValueNode($returnTagValueNode); if (! $nullabledReturnTagValueNode instanceof TypeNode) { return; } @@ -163,19 +162,19 @@ private function removeNullableType( private function removeFullyQualifiedObjectType( Type $returnType, - AttributeAwareReturnTagValueNode $attributeAwareReturnTagValueNode, + ReturnTagValueNode $returnTagValueNode, PhpDocInfo $phpDocInfo ): void { if (! $returnType instanceof FullyQualifiedObjectType) { return; } - if (! $attributeAwareReturnTagValueNode->type instanceof IdentifierTypeNode) { + if (! $returnTagValueNode->type instanceof IdentifierTypeNode) { return; } $className = $returnType->getClassName(); - $returnTagValueNodeType = (string) $attributeAwareReturnTagValueNode->type; + $returnTagValueNodeType = (string) $returnTagValueNode->type; if ($this->isClassNameAndPartMatch($className, $returnTagValueNodeType)) { $phpDocInfo->removeByType(ReturnTagValueNode::class); @@ -219,18 +218,17 @@ private function matchNullabledType(Type $returnType): ?Type return null; } - private function matchNullabledReturnTagValueNode( - AttributeAwareReturnTagValueNode $attributeAwareReturnTagValueNode - ): ?TypeNode { - if (! $attributeAwareReturnTagValueNode->type instanceof UnionTypeNode) { + private function matchNullabledReturnTagValueNode(ReturnTagValueNode $returnTagValueNode): ?TypeNode + { + if (! $returnTagValueNode->type instanceof UnionTypeNode) { return null; } - if (count($attributeAwareReturnTagValueNode->type->types) !== 2) { + if (count($returnTagValueNode->type->types) !== 2) { return null; } - foreach ($attributeAwareReturnTagValueNode->type->types as $unionedReturnTagValueNode) { + foreach ($returnTagValueNode->type->types as $unionedReturnTagValueNode) { if ($this->isIdentifierWithValues($unionedReturnTagValueNode, ['null'])) { continue; } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php index eccc1de1c893..8f997dc4dd0c 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AddArrayReturnDocTypeRector.php @@ -9,14 +9,13 @@ use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; use PHPStan\PhpDocParser\Ast\Type\ArrayTypeNode; +use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use PHPStan\Type\ArrayType; use PHPStan\Type\Generic\GenericObjectType; use PHPStan\Type\IterableType; use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\VoidType; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareArrayShapeNode; -use Rector\AttributeAwarePhpDoc\Ast\Type\AttributeAwareGenericTypeNode; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger; use Rector\Core\Rector\AbstractRector; @@ -254,24 +253,24 @@ private function hasArrayShapeNode(ClassMethod $classMethod): bool { $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); - $attributeAwareReturnTagValueNode = $phpDocInfo->getReturnTagValue(); - if (! $attributeAwareReturnTagValueNode instanceof ReturnTagValueNode) { + $returnTagValueNode = $phpDocInfo->getReturnTagValue(); + if (! $returnTagValueNode instanceof ReturnTagValueNode) { return false; } - if ($attributeAwareReturnTagValueNode->type instanceof AttributeAwareGenericTypeNode) { + if ($returnTagValueNode->type instanceof GenericTypeNode) { return true; } - if ($attributeAwareReturnTagValueNode->type instanceof AttributeAwareArrayShapeNode) { + if ($returnTagValueNode->type instanceof ArrayShapeNode) { return true; } - if (! $attributeAwareReturnTagValueNode->type instanceof ArrayTypeNode) { + if (! $returnTagValueNode->type instanceof ArrayTypeNode) { return false; } - return $attributeAwareReturnTagValueNode->type->type instanceof ArrayShapeNode; + return $returnTagValueNode->type->type instanceof ArrayShapeNode; } private function hasInheritDoc(ClassMethod $classMethod): bool diff --git a/src/Contract/Rector/ConfigurableRectorInterface.php b/src/Contract/Rector/ConfigurableRectorInterface.php index 0d838d61c3a5..aded037dda7e 100644 --- a/src/Contract/Rector/ConfigurableRectorInterface.php +++ b/src/Contract/Rector/ConfigurableRectorInterface.php @@ -9,7 +9,7 @@ interface ConfigurableRectorInterface extends ConfigurableRuleInterface { /** - * @param mixed[] $configuration + * @param array $configuration */ public function configure(array $configuration): void; }