Skip to content

Commit d9ce9f6

Browse files
committed
add AbstractNode with attributes and make all nodes extend it
1 parent 2e17e4a commit d9ce9f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+170
-39
lines changed

src/Ast/BaseNode.php

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\PhpDocParser\Ast;
4+
5+
abstract class BaseNode implements Node
6+
{
7+
8+
/** @var array<string, mixed> */
9+
private $attributes = [];
10+
11+
/**
12+
* @param mixed $value
13+
*/
14+
public function setAttribute(string $key, $value): void
15+
{
16+
$this->attributes[$key] = $value;
17+
}
18+
19+
public function hasAttribute(string $key): bool
20+
{
21+
return array_key_exists($key, $this->attributes);
22+
}
23+
24+
/**
25+
* @param mixed|null $default
26+
* @return mixed|null
27+
*/
28+
public function getAttribute(string $key, $default = null)
29+
{
30+
if ($this->hasAttribute($key)) {
31+
return $this->attributes[$key];
32+
}
33+
34+
return $default;
35+
}
36+
37+
}

src/Ast/ConstExpr/ConstExprArrayItemNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprArrayItemNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprArrayItemNode extends BaseNode implements ConstExprNode
68
{
79

810
/** @var ConstExprNode|null */

src/Ast/ConstExpr/ConstExprArrayNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprArrayNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprArrayNode extends BaseNode implements ConstExprNode
68
{
79

810
/** @var ConstExprArrayItemNode[] */

src/Ast/ConstExpr/ConstExprFalseNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprFalseNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprFalseNode extends BaseNode implements ConstExprNode
68
{
79

810
public function __toString(): string

src/Ast/ConstExpr/ConstExprFloatNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprFloatNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprFloatNode extends BaseNode implements ConstExprNode
68
{
79

810
/** @var string */

src/Ast/ConstExpr/ConstExprIntegerNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprIntegerNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprIntegerNode extends BaseNode implements ConstExprNode
68
{
79

810
/** @var string */

src/Ast/ConstExpr/ConstExprNullNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprNullNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprNullNode extends BaseNode implements ConstExprNode
68
{
79

810
public function __toString(): string

src/Ast/ConstExpr/ConstExprStringNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprStringNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprStringNode extends BaseNode implements ConstExprNode
68
{
79

810
/** @var string */

src/Ast/ConstExpr/ConstExprTrueNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstExprTrueNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstExprTrueNode extends BaseNode implements ConstExprNode
68
{
79

810
public function __toString(): string

src/Ast/ConstExpr/ConstFetchNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5-
class ConstFetchNode implements ConstExprNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ConstFetchNode extends BaseNode implements ConstExprNode
68
{
79

810
/** @var string class name for class constants or empty string for non-class constants */

src/Ast/PhpDoc/DeprecatedTagValueNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5-
class DeprecatedTagValueNode implements PhpDocTagValueNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class DeprecatedTagValueNode extends BaseNode implements PhpDocTagValueNode
68
{
79

810
/** @var string (may be empty) */

src/Ast/PhpDoc/ExtendsTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
67

7-
class ExtendsTagValueNode implements PhpDocTagValueNode
8+
class ExtendsTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var GenericTypeNode */

src/Ast/PhpDoc/GenericTagValueNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5-
class GenericTagValueNode implements PhpDocTagValueNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class GenericTagValueNode extends BaseNode implements PhpDocTagValueNode
68
{
79

810
/** @var string (may be empty) */

src/Ast/PhpDoc/ImplementsTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
67

7-
class ImplementsTagValueNode implements PhpDocTagValueNode
8+
class ImplementsTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var GenericTypeNode */

src/Ast/PhpDoc/InvalidTagValueNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5-
class InvalidTagValueNode implements PhpDocTagValueNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class InvalidTagValueNode extends BaseNode implements PhpDocTagValueNode
68
{
79

810
/** @var string (may be empty) */

src/Ast/PhpDoc/MethodTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class MethodTagValueNode implements PhpDocTagValueNode
8+
class MethodTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var bool */

src/Ast/PhpDoc/MethodTagValueParameterNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode;
67
use PHPStan\PhpDocParser\Ast\Node;
78
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
89

9-
class MethodTagValueParameterNode implements Node
10+
class MethodTagValueParameterNode extends BaseNode implements Node
1011
{
1112

1213
/** @var TypeNode|null */

src/Ast/PhpDoc/MixinTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class MixinTagValueNode implements PhpDocTagValueNode
8+
class MixinTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var TypeNode */

src/Ast/PhpDoc/ParamTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class ParamTagValueNode implements PhpDocTagValueNode
8+
class ParamTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var TypeNode */

src/Ast/PhpDoc/PhpDocNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Node;
67

7-
class PhpDocNode implements Node
8+
class PhpDocNode extends BaseNode implements Node
89
{
910

1011
/** @var PhpDocChildNode[] */

src/Ast/PhpDoc/PhpDocTagNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5-
class PhpDocTagNode implements PhpDocChildNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class PhpDocTagNode extends BaseNode implements PhpDocChildNode
68
{
79

810
/** @var string */

src/Ast/PhpDoc/PhpDocTextNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5-
class PhpDocTextNode implements PhpDocChildNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class PhpDocTextNode extends BaseNode implements PhpDocChildNode
68
{
79

810
/** @var string */

src/Ast/PhpDoc/PropertyTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class PropertyTagValueNode implements PhpDocTagValueNode
8+
class PropertyTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var TypeNode */

src/Ast/PhpDoc/ReturnTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class ReturnTagValueNode implements PhpDocTagValueNode
8+
class ReturnTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var TypeNode */

src/Ast/PhpDoc/TemplateTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class TemplateTagValueNode implements PhpDocTagValueNode
8+
class TemplateTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var string */

src/Ast/PhpDoc/ThrowsTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class ThrowsTagValueNode implements PhpDocTagValueNode
8+
class ThrowsTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var TypeNode */

src/Ast/PhpDoc/UsesTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
67

7-
class UsesTagValueNode implements PhpDocTagValueNode
8+
class UsesTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var GenericTypeNode */

src/Ast/PhpDoc/VarTagValueNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

7-
class VarTagValueNode implements PhpDocTagValueNode
8+
class VarTagValueNode extends BaseNode implements PhpDocTagValueNode
89
{
910

1011
/** @var TypeNode */

src/Ast/Type/ArrayShapeItemNode.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
namespace PHPStan\PhpDocParser\Ast\Type;
44

5+
use PHPStan\PhpDocParser\Ast\BaseNode;
56
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
67
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
78

8-
class ArrayShapeItemNode implements TypeNode
9+
class ArrayShapeItemNode extends BaseNode implements TypeNode
910
{
1011

1112
/** @var ConstExprIntegerNode|ConstExprStringNode|IdentifierTypeNode|null */

src/Ast/Type/ArrayShapeNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\Type;
44

5-
class ArrayShapeNode implements TypeNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ArrayShapeNode extends BaseNode implements TypeNode
68
{
79

810
/** @var ArrayShapeItemNode[] */

src/Ast/Type/ArrayTypeNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\Type;
44

5-
class ArrayTypeNode implements TypeNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class ArrayTypeNode extends BaseNode implements TypeNode
68
{
79

810
/** @var TypeNode */

src/Ast/Type/CallableTypeNode.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PHPStan\PhpDocParser\Ast\Type;
44

5-
class CallableTypeNode implements TypeNode
5+
use PHPStan\PhpDocParser\Ast\BaseNode;
6+
7+
class CallableTypeNode extends BaseNode implements TypeNode
68
{
79

810
/** @var IdentifierTypeNode */

0 commit comments

Comments
 (0)