Skip to content

Commit 090e3cc

Browse files
committed
wip
1 parent 3fa104d commit 090e3cc

5 files changed

Lines changed: 60 additions & 2 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

src/Results/Nodes/ClassDefinitionNode.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Permafrost\PhpCodeSearch\Results\Nodes\Traits\BootsTraits;
66
use Permafrost\PhpCodeSearch\Results\Nodes\Traits\HasLocation;
77
use Permafrost\PhpCodeSearch\Results\Nodes\Traits\HasName;
8-
use Permafrost\PhpCodeSearch\Support\Collections\Collection;
98
use Permafrost\PhpCodeSearch\Support\NameResolver;
109
use Permafrost\PhpCodeSearch\Support\StatementTransformer;
1110
use 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
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

src/Support/NameResolver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

src/Support/StatementTransformer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Permafrost\PhpCodeSearch\Support;
44

5+
use Permafrost\PhpCodeSearch\Results\Nodes\ClassConstantNode;
56
use Permafrost\PhpCodeSearch\Results\Nodes\ClassMethodNode;
67
use Permafrost\PhpCodeSearch\Results\Nodes\ClassPropertyNode;
78
use 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) {

0 commit comments

Comments
 (0)