Skip to content

Commit cfe3c78

Browse files
TomasVotrubaondrejmirtes
authored andcommitted
Allow nodes to have custom attributes
1 parent 37a74df commit cfe3c78

Some content is hidden

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

44 files changed

+243
-0
lines changed

Diff for: src/Ast/ConstExpr/ConstExprArrayItemNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprArrayItemNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var ConstExprNode|null */
913
public $key;
1014

Diff for: src/Ast/ConstExpr/ConstExprArrayNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprArrayNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var ConstExprArrayItemNode[] */
913
public $items;
1014

Diff for: src/Ast/ConstExpr/ConstExprFalseNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprFalseNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
public function __toString(): string
913
{
1014
return 'false';

Diff for: src/Ast/ConstExpr/ConstExprFloatNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprFloatNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string */
913
public $value;
1014

Diff for: src/Ast/ConstExpr/ConstExprIntegerNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprIntegerNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string */
913
public $value;
1014

Diff for: src/Ast/ConstExpr/ConstExprNullNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprNullNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
public function __toString(): string
913
{
1014
return 'null';

Diff for: src/Ast/ConstExpr/ConstExprStringNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprStringNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string */
913
public $value;
1014

Diff for: src/Ast/ConstExpr/ConstExprTrueNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstExprTrueNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
public function __toString(): string
913
{
1014
return 'true';

Diff for: src/Ast/ConstExpr/ConstFetchNode.php

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\ConstExpr;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class ConstFetchNode implements ConstExprNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string class name for class constants or empty string for non-class constants */
913
public $className;
1014

Diff for: src/Ast/Node.php

+14
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,18 @@ interface Node
77

88
public function __toString(): string;
99

10+
/**
11+
* @param string $key
12+
* @param mixed $value
13+
*/
14+
public function setAttribute(string $key, $value): void;
15+
16+
public function hasAttribute(string $key): bool;
17+
18+
/**
19+
* @param string $key
20+
* @return mixed
21+
*/
22+
public function getAttribute(string $key);
23+
1024
}

Diff for: src/Ast/NodeAttributes.php

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

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

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class DeprecatedTagValueNode implements PhpDocTagValueNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string (may be empty) */
913
public $description;
1014

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class ExtendsTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var GenericTypeNode */
1114
public $type;
1215

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

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class GenericTagValueNode implements PhpDocTagValueNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string (may be empty) */
913
public $value;
1014

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class ImplementsTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var GenericTypeNode */
1114
public $type;
1215

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

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class InvalidTagValueNode implements PhpDocTagValueNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string (may be empty) */
913
public $value;
1014

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class MethodTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var bool */
1114
public $isStatic;
1215

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

+3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode;
66
use PHPStan\PhpDocParser\Ast\Node;
7+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
78
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
89

910
class MethodTagValueParameterNode implements Node
1011
{
1112

13+
use NodeAttributes;
14+
1215
/** @var TypeNode|null */
1316
public $type;
1417

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class MixinTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var TypeNode */
1114
public $type;
1215

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class ParamTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var TypeNode */
1114
public $type;
1215

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

+3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

55
use PHPStan\PhpDocParser\Ast\Node;
6+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
67

78
class PhpDocNode implements Node
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var PhpDocChildNode[] */
1114
public $children;
1215

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

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class PhpDocTagNode implements PhpDocChildNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string */
913
public $name;
1014

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

+4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

5+
use PHPStan\PhpDocParser\Ast\NodeAttributes;
6+
57
class PhpDocTextNode implements PhpDocChildNode
68
{
79

10+
use NodeAttributes;
11+
812
/** @var string */
913
public $text;
1014

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class PropertyTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var TypeNode */
1114
public $type;
1215

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

+3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
namespace PHPStan\PhpDocParser\Ast\PhpDoc;
44

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

78
class ReturnTagValueNode implements PhpDocTagValueNode
89
{
910

11+
use NodeAttributes;
12+
1013
/** @var TypeNode */
1114
public $type;
1215

0 commit comments

Comments
 (0)