diff --git a/src/Ast/ConstExpr/ConstExprArrayItemNode.php b/src/Ast/ConstExpr/ConstExprArrayItemNode.php index 9456e95d..d0695f82 100644 --- a/src/Ast/ConstExpr/ConstExprArrayItemNode.php +++ b/src/Ast/ConstExpr/ConstExprArrayItemNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprArrayItemNode implements ConstExprNode { + use NodeAttributes; + /** @var ConstExprNode|null */ public $key; diff --git a/src/Ast/ConstExpr/ConstExprArrayNode.php b/src/Ast/ConstExpr/ConstExprArrayNode.php index 215c5a37..82135efc 100644 --- a/src/Ast/ConstExpr/ConstExprArrayNode.php +++ b/src/Ast/ConstExpr/ConstExprArrayNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprArrayNode implements ConstExprNode { + use NodeAttributes; + /** @var ConstExprArrayItemNode[] */ public $items; diff --git a/src/Ast/ConstExpr/ConstExprFalseNode.php b/src/Ast/ConstExpr/ConstExprFalseNode.php index fae8af1b..e6811277 100644 --- a/src/Ast/ConstExpr/ConstExprFalseNode.php +++ b/src/Ast/ConstExpr/ConstExprFalseNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprFalseNode implements ConstExprNode { + use NodeAttributes; + public function __toString(): string { return 'false'; diff --git a/src/Ast/ConstExpr/ConstExprFloatNode.php b/src/Ast/ConstExpr/ConstExprFloatNode.php index 0f81c418..a4192fba 100644 --- a/src/Ast/ConstExpr/ConstExprFloatNode.php +++ b/src/Ast/ConstExpr/ConstExprFloatNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprFloatNode implements ConstExprNode { + use NodeAttributes; + /** @var string */ public $value; diff --git a/src/Ast/ConstExpr/ConstExprIntegerNode.php b/src/Ast/ConstExpr/ConstExprIntegerNode.php index 949ba5cb..5339bb5a 100644 --- a/src/Ast/ConstExpr/ConstExprIntegerNode.php +++ b/src/Ast/ConstExpr/ConstExprIntegerNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprIntegerNode implements ConstExprNode { + use NodeAttributes; + /** @var string */ public $value; diff --git a/src/Ast/ConstExpr/ConstExprNullNode.php b/src/Ast/ConstExpr/ConstExprNullNode.php index 1d51eb80..b6e22771 100644 --- a/src/Ast/ConstExpr/ConstExprNullNode.php +++ b/src/Ast/ConstExpr/ConstExprNullNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprNullNode implements ConstExprNode { + use NodeAttributes; + public function __toString(): string { return 'null'; diff --git a/src/Ast/ConstExpr/ConstExprStringNode.php b/src/Ast/ConstExpr/ConstExprStringNode.php index d9c720a0..fa44c262 100644 --- a/src/Ast/ConstExpr/ConstExprStringNode.php +++ b/src/Ast/ConstExpr/ConstExprStringNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprStringNode implements ConstExprNode { + use NodeAttributes; + /** @var string */ public $value; diff --git a/src/Ast/ConstExpr/ConstExprTrueNode.php b/src/Ast/ConstExpr/ConstExprTrueNode.php index b0e3c003..ec980320 100644 --- a/src/Ast/ConstExpr/ConstExprTrueNode.php +++ b/src/Ast/ConstExpr/ConstExprTrueNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstExprTrueNode implements ConstExprNode { + use NodeAttributes; + public function __toString(): string { return 'true'; diff --git a/src/Ast/ConstExpr/ConstFetchNode.php b/src/Ast/ConstExpr/ConstFetchNode.php index a432741d..3f20363b 100644 --- a/src/Ast/ConstExpr/ConstFetchNode.php +++ b/src/Ast/ConstExpr/ConstFetchNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\ConstExpr; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ConstFetchNode implements ConstExprNode { + use NodeAttributes; + /** @var string class name for class constants or empty string for non-class constants */ public $className; diff --git a/src/Ast/Node.php b/src/Ast/Node.php index 8c4ccb57..faa3f7ee 100644 --- a/src/Ast/Node.php +++ b/src/Ast/Node.php @@ -7,4 +7,18 @@ interface Node public function __toString(): string; + /** + * @param string $key + * @param mixed $value + */ + public function setAttribute(string $key, $value): void; + + public function hasAttribute(string $key): bool; + + /** + * @param string $key + * @return mixed + */ + public function getAttribute(string $key); + } diff --git a/src/Ast/NodeAttributes.php b/src/Ast/NodeAttributes.php new file mode 100644 index 00000000..711d6baf --- /dev/null +++ b/src/Ast/NodeAttributes.php @@ -0,0 +1,38 @@ + */ + private $attributes = []; + + /** + * @param string $key + * @param mixed $value + */ + public function setAttribute(string $key, $value): void + { + $this->attributes[$key] = $value; + } + + public function hasAttribute(string $key): bool + { + return array_key_exists($key, $this->attributes); + } + + /** + * @param string $key + * @return mixed + */ + public function getAttribute(string $key) + { + if ($this->hasAttribute($key)) { + return $this->attributes[$key]; + } + + return null; + } + +} diff --git a/src/Ast/PhpDoc/DeprecatedTagValueNode.php b/src/Ast/PhpDoc/DeprecatedTagValueNode.php index 315d902b..b05368e1 100644 --- a/src/Ast/PhpDoc/DeprecatedTagValueNode.php +++ b/src/Ast/PhpDoc/DeprecatedTagValueNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class DeprecatedTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var string (may be empty) */ public $description; diff --git a/src/Ast/PhpDoc/ExtendsTagValueNode.php b/src/Ast/PhpDoc/ExtendsTagValueNode.php index 513f2975..4ee842f7 100644 --- a/src/Ast/PhpDoc/ExtendsTagValueNode.php +++ b/src/Ast/PhpDoc/ExtendsTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; class ExtendsTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var GenericTypeNode */ public $type; diff --git a/src/Ast/PhpDoc/GenericTagValueNode.php b/src/Ast/PhpDoc/GenericTagValueNode.php index 97518ab6..026aa153 100644 --- a/src/Ast/PhpDoc/GenericTagValueNode.php +++ b/src/Ast/PhpDoc/GenericTagValueNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class GenericTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var string (may be empty) */ public $value; diff --git a/src/Ast/PhpDoc/ImplementsTagValueNode.php b/src/Ast/PhpDoc/ImplementsTagValueNode.php index 7691d93a..e2b11635 100644 --- a/src/Ast/PhpDoc/ImplementsTagValueNode.php +++ b/src/Ast/PhpDoc/ImplementsTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; class ImplementsTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var GenericTypeNode */ public $type; diff --git a/src/Ast/PhpDoc/InvalidTagValueNode.php b/src/Ast/PhpDoc/InvalidTagValueNode.php index 150acae5..a496e8ee 100644 --- a/src/Ast/PhpDoc/InvalidTagValueNode.php +++ b/src/Ast/PhpDoc/InvalidTagValueNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class InvalidTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var string (may be empty) */ public $value; diff --git a/src/Ast/PhpDoc/MethodTagValueNode.php b/src/Ast/PhpDoc/MethodTagValueNode.php index 8f5035c3..ec509a17 100644 --- a/src/Ast/PhpDoc/MethodTagValueNode.php +++ b/src/Ast/PhpDoc/MethodTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class MethodTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var bool */ public $isStatic; diff --git a/src/Ast/PhpDoc/MethodTagValueParameterNode.php b/src/Ast/PhpDoc/MethodTagValueParameterNode.php index f7409f3e..7c17e44c 100644 --- a/src/Ast/PhpDoc/MethodTagValueParameterNode.php +++ b/src/Ast/PhpDoc/MethodTagValueParameterNode.php @@ -4,11 +4,14 @@ use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode; use PHPStan\PhpDocParser\Ast\Node; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class MethodTagValueParameterNode implements Node { + use NodeAttributes; + /** @var TypeNode|null */ public $type; diff --git a/src/Ast/PhpDoc/MixinTagValueNode.php b/src/Ast/PhpDoc/MixinTagValueNode.php index 8290181d..8761ca43 100644 --- a/src/Ast/PhpDoc/MixinTagValueNode.php +++ b/src/Ast/PhpDoc/MixinTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class MixinTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/PhpDoc/ParamTagValueNode.php b/src/Ast/PhpDoc/ParamTagValueNode.php index 04710a7b..eb88cd9b 100644 --- a/src/Ast/PhpDoc/ParamTagValueNode.php +++ b/src/Ast/PhpDoc/ParamTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class ParamTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/PhpDoc/PhpDocNode.php b/src/Ast/PhpDoc/PhpDocNode.php index ace03b1f..a690cee3 100644 --- a/src/Ast/PhpDoc/PhpDocNode.php +++ b/src/Ast/PhpDoc/PhpDocNode.php @@ -3,10 +3,13 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; use PHPStan\PhpDocParser\Ast\Node; +use PHPStan\PhpDocParser\Ast\NodeAttributes; class PhpDocNode implements Node { + use NodeAttributes; + /** @var PhpDocChildNode[] */ public $children; diff --git a/src/Ast/PhpDoc/PhpDocTagNode.php b/src/Ast/PhpDoc/PhpDocTagNode.php index be3043bf..f847d190 100644 --- a/src/Ast/PhpDoc/PhpDocTagNode.php +++ b/src/Ast/PhpDoc/PhpDocTagNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class PhpDocTagNode implements PhpDocChildNode { + use NodeAttributes; + /** @var string */ public $name; diff --git a/src/Ast/PhpDoc/PhpDocTextNode.php b/src/Ast/PhpDoc/PhpDocTextNode.php index 2a4f8a4c..0bca3c99 100644 --- a/src/Ast/PhpDoc/PhpDocTextNode.php +++ b/src/Ast/PhpDoc/PhpDocTextNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class PhpDocTextNode implements PhpDocChildNode { + use NodeAttributes; + /** @var string */ public $text; diff --git a/src/Ast/PhpDoc/PropertyTagValueNode.php b/src/Ast/PhpDoc/PropertyTagValueNode.php index bca55a7e..b2cdbb16 100644 --- a/src/Ast/PhpDoc/PropertyTagValueNode.php +++ b/src/Ast/PhpDoc/PropertyTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class PropertyTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/PhpDoc/ReturnTagValueNode.php b/src/Ast/PhpDoc/ReturnTagValueNode.php index 254d3f87..2b8a1842 100644 --- a/src/Ast/PhpDoc/ReturnTagValueNode.php +++ b/src/Ast/PhpDoc/ReturnTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class ReturnTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/PhpDoc/TemplateTagValueNode.php b/src/Ast/PhpDoc/TemplateTagValueNode.php index 5847df22..4a8f4150 100644 --- a/src/Ast/PhpDoc/TemplateTagValueNode.php +++ b/src/Ast/PhpDoc/TemplateTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class TemplateTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var string */ public $name; diff --git a/src/Ast/PhpDoc/ThrowsTagValueNode.php b/src/Ast/PhpDoc/ThrowsTagValueNode.php index 32ae12d2..67d05900 100644 --- a/src/Ast/PhpDoc/ThrowsTagValueNode.php +++ b/src/Ast/PhpDoc/ThrowsTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class ThrowsTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/PhpDoc/TypeAliasImportTagValueNode.php b/src/Ast/PhpDoc/TypeAliasImportTagValueNode.php index 923eb628..819f05ba 100644 --- a/src/Ast/PhpDoc/TypeAliasImportTagValueNode.php +++ b/src/Ast/PhpDoc/TypeAliasImportTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; class TypeAliasImportTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var string */ public $importedAlias; diff --git a/src/Ast/PhpDoc/TypeAliasTagValueNode.php b/src/Ast/PhpDoc/TypeAliasTagValueNode.php index 4a4ac617..21fbb066 100644 --- a/src/Ast/PhpDoc/TypeAliasTagValueNode.php +++ b/src/Ast/PhpDoc/TypeAliasTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class TypeAliasTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var string */ public $alias; diff --git a/src/Ast/PhpDoc/UsesTagValueNode.php b/src/Ast/PhpDoc/UsesTagValueNode.php index 20b19390..0a641d1b 100644 --- a/src/Ast/PhpDoc/UsesTagValueNode.php +++ b/src/Ast/PhpDoc/UsesTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; class UsesTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var GenericTypeNode */ public $type; diff --git a/src/Ast/PhpDoc/VarTagValueNode.php b/src/Ast/PhpDoc/VarTagValueNode.php index 2965ce7c..dc06202f 100644 --- a/src/Ast/PhpDoc/VarTagValueNode.php +++ b/src/Ast/PhpDoc/VarTagValueNode.php @@ -2,11 +2,14 @@ namespace PHPStan\PhpDocParser\Ast\PhpDoc; +use PHPStan\PhpDocParser\Ast\NodeAttributes; use PHPStan\PhpDocParser\Ast\Type\TypeNode; class VarTagValueNode implements PhpDocTagValueNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/Type/ArrayShapeItemNode.php b/src/Ast/Type/ArrayShapeItemNode.php index b4996e90..e8a78f32 100644 --- a/src/Ast/Type/ArrayShapeItemNode.php +++ b/src/Ast/Type/ArrayShapeItemNode.php @@ -4,10 +4,13 @@ use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode; use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode; +use PHPStan\PhpDocParser\Ast\NodeAttributes; class ArrayShapeItemNode implements TypeNode { + use NodeAttributes; + /** @var ConstExprIntegerNode|ConstExprStringNode|IdentifierTypeNode|null */ public $keyName; diff --git a/src/Ast/Type/ArrayShapeNode.php b/src/Ast/Type/ArrayShapeNode.php index 74df4ab3..094aaa11 100644 --- a/src/Ast/Type/ArrayShapeNode.php +++ b/src/Ast/Type/ArrayShapeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ArrayShapeNode implements TypeNode { + use NodeAttributes; + /** @var ArrayShapeItemNode[] */ public $items; diff --git a/src/Ast/Type/ArrayTypeNode.php b/src/Ast/Type/ArrayTypeNode.php index b01d083c..90cb9f08 100644 --- a/src/Ast/Type/ArrayTypeNode.php +++ b/src/Ast/Type/ArrayTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ArrayTypeNode implements TypeNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/Type/CallableTypeNode.php b/src/Ast/Type/CallableTypeNode.php index 2f4bf7c5..6faa4cd9 100644 --- a/src/Ast/Type/CallableTypeNode.php +++ b/src/Ast/Type/CallableTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class CallableTypeNode implements TypeNode { + use NodeAttributes; + /** @var IdentifierTypeNode */ public $identifier; diff --git a/src/Ast/Type/CallableTypeParameterNode.php b/src/Ast/Type/CallableTypeParameterNode.php index 3503318d..2badb7c2 100644 --- a/src/Ast/Type/CallableTypeParameterNode.php +++ b/src/Ast/Type/CallableTypeParameterNode.php @@ -3,10 +3,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; use PHPStan\PhpDocParser\Ast\Node; +use PHPStan\PhpDocParser\Ast\NodeAttributes; class CallableTypeParameterNode implements Node { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/Type/ConstTypeNode.php b/src/Ast/Type/ConstTypeNode.php index ee9f14da..0096055b 100644 --- a/src/Ast/Type/ConstTypeNode.php +++ b/src/Ast/Type/ConstTypeNode.php @@ -3,10 +3,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode; +use PHPStan\PhpDocParser\Ast\NodeAttributes; class ConstTypeNode implements TypeNode { + use NodeAttributes; + /** @var ConstExprNode */ public $constExpr; diff --git a/src/Ast/Type/GenericTypeNode.php b/src/Ast/Type/GenericTypeNode.php index 4dcc9c8f..399e5620 100644 --- a/src/Ast/Type/GenericTypeNode.php +++ b/src/Ast/Type/GenericTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class GenericTypeNode implements TypeNode { + use NodeAttributes; + /** @var IdentifierTypeNode */ public $type; diff --git a/src/Ast/Type/IdentifierTypeNode.php b/src/Ast/Type/IdentifierTypeNode.php index 9ca389cc..29bac308 100644 --- a/src/Ast/Type/IdentifierTypeNode.php +++ b/src/Ast/Type/IdentifierTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class IdentifierTypeNode implements TypeNode { + use NodeAttributes; + /** @var string */ public $name; diff --git a/src/Ast/Type/IntersectionTypeNode.php b/src/Ast/Type/IntersectionTypeNode.php index 60341187..e9ebf528 100644 --- a/src/Ast/Type/IntersectionTypeNode.php +++ b/src/Ast/Type/IntersectionTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class IntersectionTypeNode implements TypeNode { + use NodeAttributes; + /** @var TypeNode[] */ public $types; diff --git a/src/Ast/Type/NullableTypeNode.php b/src/Ast/Type/NullableTypeNode.php index 98c73647..73f438cd 100644 --- a/src/Ast/Type/NullableTypeNode.php +++ b/src/Ast/Type/NullableTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class NullableTypeNode implements TypeNode { + use NodeAttributes; + /** @var TypeNode */ public $type; diff --git a/src/Ast/Type/ThisTypeNode.php b/src/Ast/Type/ThisTypeNode.php index 06a3537e..d94e6f83 100644 --- a/src/Ast/Type/ThisTypeNode.php +++ b/src/Ast/Type/ThisTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class ThisTypeNode implements TypeNode { + use NodeAttributes; + public function __toString(): string { return '$this'; diff --git a/src/Ast/Type/UnionTypeNode.php b/src/Ast/Type/UnionTypeNode.php index 235b6d5a..58195c6d 100644 --- a/src/Ast/Type/UnionTypeNode.php +++ b/src/Ast/Type/UnionTypeNode.php @@ -2,9 +2,13 @@ namespace PHPStan\PhpDocParser\Ast\Type; +use PHPStan\PhpDocParser\Ast\NodeAttributes; + class UnionTypeNode implements TypeNode { + use NodeAttributes; + /** @var TypeNode[] */ public $types; diff --git a/tests/PHPStan/Ast/Attributes/AttributesTest.php b/tests/PHPStan/Ast/Attributes/AttributesTest.php new file mode 100644 index 00000000..a20747ec --- /dev/null +++ b/tests/PHPStan/Ast/Attributes/AttributesTest.php @@ -0,0 +1,45 @@ +tokenize($input)); + $this->phpDocNode = $phpDocParser->parse($tokens); + } + + public function testGetAttribute(): void + { + $unKnownValue = $this->phpDocNode->getAttribute('unknown'); + $this->assertNull($unKnownValue); + } + + public function testSetAttribute(): void + { + $this->phpDocNode->setAttribute('key', 'value'); + + $attributeValue = $this->phpDocNode->getAttribute('key'); + $this->assertSame('value', $attributeValue); + } + +}