File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Permafrost \PhpCodeSearch \Results \Nodes ;
4+
5+ use Permafrost \PhpCodeSearch \Results \Nodes \Traits \BootsTraits ;
6+ use Permafrost \PhpCodeSearch \Results \Nodes \Traits \HasLocation ;
7+ use Permafrost \PhpCodeSearch \Results \Nodes \Traits \HasName ;
8+ use Permafrost \PhpCodeSearch \Results \Nodes \Traits \HasValue ;
9+ use Permafrost \PhpCodeSearch \Results \Nodes \Traits \HasVisibility ;
10+ use PhpParser \Node ;
11+
12+ class ClassConstantNode implements ResultNode
13+ {
14+ use BootsTraits;
15+ use HasLocation;
16+ use HasName;
17+ use HasValue;
18+ use HasVisibility;
19+
20+ public function __construct (Node \Stmt \ClassConst $ node )
21+ {
22+ $ this ->bootTraits ($ node );
23+ $ this ->bootHasValue ($ node ->consts [0 ]);
24+ }
25+ }
Original file line number Diff line number Diff line change 55use Permafrost \PhpCodeSearch \Results \Nodes \Traits \BootsTraits ;
66use Permafrost \PhpCodeSearch \Results \Nodes \Traits \HasLocation ;
77use Permafrost \PhpCodeSearch \Results \Nodes \Traits \HasName ;
8- use Permafrost \PhpCodeSearch \Support \Collections \Collection ;
98use Permafrost \PhpCodeSearch \Support \NameResolver ;
109use Permafrost \PhpCodeSearch \Support \StatementTransformer ;
1110use PhpParser \Node ;
@@ -22,10 +21,13 @@ class ClassDefinitionNode implements ResultNode
2221 /** @var array|ResultNode[]|ValueNode[] */
2322 public $ methods ;
2423
25- public $ implements ;
24+ public $ implements = [] ;
2625
2726 public $ extends ;
2827
28+ /** @var array|ResultNode[]|ValueNode[] */
29+ public $ constants = [];
30+
2931 public function __construct (Node \Stmt \Class_ $ node )
3032 {
3133 $ this ->bootTraits ($ node );
@@ -34,5 +36,6 @@ public function __construct(Node\Stmt\Class_ $node)
3436 $ this ->implements = NameResolver::resolveAll ($ node ->implements );
3537 $ this ->properties = StatementTransformer::parserNodesToResultNode ($ node ->getProperties ());
3638 $ this ->methods = StatementTransformer::parserNodesToResultNode ($ node ->getMethods ());
39+ $ this ->constants = StatementTransformer::parserNodesToResultNode ($ node ->getConstants ());
3740 }
3841}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Permafrost \PhpCodeSearch \Results \Nodes \Traits ;
4+
5+ use Permafrost \PhpCodeSearch \Results \Nodes \Scalar \StringNode ;
6+ use Permafrost \PhpCodeSearch \Support \ExpressionTransformer ;
7+
8+ trait HasValue
9+ {
10+ /** @var string|StringNode */
11+ public $ value ;
12+
13+ public function value ()
14+ {
15+ return $ this ->value ;
16+ }
17+
18+ protected function bootHasValue ($ node ): void
19+ {
20+ if (property_exists ($ node , 'value ' )) {
21+ $ this ->value = ExpressionTransformer::parserNodeToResultNode ($ node ->value );
22+ }
23+ }
24+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,10 @@ public static function resolve($node)
2424 return $ node ->props [0 ]->name ;
2525 }
2626
27+ if ($ node instanceof Node \Stmt \ClassConst) {
28+ return $ node ->consts [0 ]->name ;
29+ }
30+
2731 if (self ::propertiesExist ($ node , ['class ' , 'name ' ])) {
2832 $ class = static ::resolve ($ node ->class );
2933 $ name = static ::resolve ($ node ->name );
Original file line number Diff line number Diff line change 22
33namespace Permafrost \PhpCodeSearch \Support ;
44
5+ use Permafrost \PhpCodeSearch \Results \Nodes \ClassConstantNode ;
56use Permafrost \PhpCodeSearch \Results \Nodes \ClassMethodNode ;
67use Permafrost \PhpCodeSearch \Results \Nodes \ClassPropertyNode ;
78use Permafrost \PhpCodeSearch \Results \Nodes \ParameterNode ;
@@ -15,6 +16,7 @@ public static function parserNodeToResultNode(Node $node)
1516 Node \Param::class => ParameterNode::class,
1617 Node \Stmt \Property::class => ClassPropertyNode::class,
1718 Node \Stmt \ClassMethod::class => ClassMethodNode::class,
19+ Node \Stmt \ClassConst::class => ClassConstantNode::class,
1820 ];
1921
2022 foreach ($ map as $ parserNodeClass => $ resultNodeClass ) {
You can’t perform that action at this time.
0 commit comments