Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d9ce9f6

Browse files
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‎

Lines changed: 37 additions & 0 deletions
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‎

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\BaseNode;
6+
7+
class ConstExprArrayItemNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprArrayNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprFalseNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprFloatNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprIntegerNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprNullNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprStringNode extends BaseNode 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\BaseNode;
6+
7+
class ConstExprTrueNode extends BaseNode 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\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 */

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /