Skip to content

Commit d303c9b

Browse files
committed
add AbstractNode with attributes and make all nodes extend it
1 parent 35c6094 commit d303c9b

40 files changed

+136
-41
lines changed

Diff for: src/Ast/AbstractNode.php

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

Diff for: 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\AbstractNode;
6+
7+
class ConstExprArrayItemNode extends AbstractNode implements ConstExprNode
68
{
79

810
/** @var ConstExprNode|null */

Diff for: 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\AbstractNode;
6+
7+
class ConstExprArrayNode extends AbstractNode implements ConstExprNode
68
{
79

810
/** @var ConstExprArrayItemNode[] */

Diff for: 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\AbstractNode;
6+
7+
class ConstExprFalseNode extends AbstractNode implements ConstExprNode
68
{
79

810
public function __toString(): string

Diff for: 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\AbstractNode;
6+
7+
class ConstExprFloatNode extends AbstractNode implements ConstExprNode
68
{
79

810
/** @var string */

Diff for: 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\AbstractNode;
6+
7+
class ConstExprIntegerNode extends AbstractNode implements ConstExprNode
68
{
79

810
/** @var string */

Diff for: 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\AbstractNode;
6+
7+
class ConstExprNullNode extends AbstractNode implements ConstExprNode
68
{
79

810
public function __toString(): string

Diff for: 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\AbstractNode;
6+
7+
class ConstExprStringNode extends AbstractNode implements ConstExprNode
68
{
79

810
/** @var string */

Diff for: 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\AbstractNode;
6+
7+
class ConstExprTrueNode extends AbstractNode implements ConstExprNode
68
{
79

810
public function __toString(): string

Diff for: 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\AbstractNode;
6+
7+
class ConstFetchNode extends AbstractNode implements ConstExprNode
68
{
79

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

Diff for: 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\AbstractNode;
6+
7+
class DeprecatedTagValueNode extends AbstractNode implements PhpDocTagValueNode
68
{
79

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

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
67

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

1011
/** @var GenericTypeNode */

Diff for: 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\AbstractNode;
6+
7+
class GenericTagValueNode extends AbstractNode implements PhpDocTagValueNode
68
{
79

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

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
67

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

1011
/** @var GenericTypeNode */

Diff for: src/Ast/PhpDoc/InvalidTagValueNode.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5-
class InvalidTagValueNode implements PhpDocTagValueNode
5+
use PHPStan\PhpDocParser\Ast\AbstractNode;
6+
use PHPStan\PhpDocParser\Parser\ParserException;
7+
8+
class InvalidTagValueNode extends AbstractNode implements PhpDocTagValueNode
69
{
710

811
/** @var string (may be empty) */
912
public $value;
1013

11-
/** @var \PHPStan\PhpDocParser\Parser\ParserException */
14+
/** @var ParserException */
1215
public $exception;
1316

14-
public function __construct(string $value, \PHPStan\PhpDocParser\Parser\ParserException $exception)
17+
public function __construct(string $value, ParserException $exception)
1518
{
1619
$this->value = $value;
1720
$this->exception = $exception;

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var bool */

Diff for: 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\AbstractNode;
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 AbstractNode implements Node
1011
{
1112

1213
/** @var TypeNode|null */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var TypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var TypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Node;
67

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

1011
/** @var PhpDocChildNode[] */

Diff for: 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\AbstractNode;
6+
7+
class PhpDocTagNode extends AbstractNode implements PhpDocChildNode
68
{
79

810
/** @var string */

Diff for: 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\AbstractNode;
6+
7+
class PhpDocTextNode extends AbstractNode implements PhpDocChildNode
68
{
79

810
/** @var string */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var TypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var TypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var string */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var TypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode;
67

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

1011
/** @var GenericTypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
67

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

1011
/** @var TypeNode */

Diff for: 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\AbstractNode;
56
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
67
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprStringNode;
78

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

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

Diff for: 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\AbstractNode;
6+
7+
class ArrayShapeNode extends AbstractNode implements TypeNode
68
{
79

810
/** @var ArrayShapeItemNode[] */

Diff for: 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\AbstractNode;
6+
7+
class ArrayTypeNode extends AbstractNode implements TypeNode
68
{
79

810
/** @var TypeNode */

0 commit comments

Comments
 (0)