Skip to content

Commit 9c2036e

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

39 files changed

+134
-40
lines changed

src/Ast/AbstractNode.php

Lines changed: 32 additions & 0 deletions
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+
}

src/Ast/ConstExpr/ConstExprArrayItemNode.php

Lines changed: 3 additions & 1 deletion
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 */

src/Ast/ConstExpr/ConstExprArrayNode.php

Lines changed: 3 additions & 1 deletion
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[] */

src/Ast/ConstExpr/ConstExprFalseNode.php

Lines changed: 3 additions & 1 deletion
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

src/Ast/ConstExpr/ConstExprFloatNode.php

Lines changed: 3 additions & 1 deletion
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 */

src/Ast/ConstExpr/ConstExprIntegerNode.php

Lines changed: 3 additions & 1 deletion
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 */

src/Ast/ConstExpr/ConstExprNullNode.php

Lines changed: 3 additions & 1 deletion
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

src/Ast/ConstExpr/ConstExprStringNode.php

Lines changed: 3 additions & 1 deletion
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 */

src/Ast/ConstExpr/ConstExprTrueNode.php

Lines changed: 3 additions & 1 deletion
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

src/Ast/ConstExpr/ConstFetchNode.php

Lines changed: 3 additions & 1 deletion
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 */

0 commit comments

Comments
 (0)