-
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathSemanticAnalyzer.php
More file actions
44 lines (36 loc) · 1.38 KB
/
SemanticAnalyzer.php
File metadata and controls
44 lines (36 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace Go\Aop\Pointcut\DNF;
use Go\Aop\Pointcut\DNF\AST\Node;
use Go\Aop\Pointcut\DNF\AST\NodeType;
use Go\ParserReflection\ReflectionFileNamespace;
class SemanticAnalyzer implements SemanticAnalyzerInterface
{
public function verifyTree(?Node $tree, \ReflectionClass|ReflectionFileNamespace $val)
{
if ($tree !== null && $tree->type === NodeType::IDENTIFIER && $tree->identifier !== null) {
$parentClasses = $this->getParentClasses($val);
return in_array($tree->identifier, $parentClasses, true)
|| $val->implementsInterface($tree->identifier);
}
if ($tree?->type === NodeType::AND) {
return $this->verifyTree($tree->left, $val) && $this->verifyTree($tree->right, $val);
}
if ($tree->type === NodeType::OR) {
return $this->verifyTree($tree->left, $val) || $this->verifyTree($tree->right, $val);
}
}
/**
* @param ReflectionFileNamespace|\ReflectionClass $val
*
* @return array
*/
public function getParentClasses(ReflectionFileNamespace|\ReflectionClass $val): array
{
$parentClasses = [];
while ($val->getParentClass()) {
$parentClasses[] = $val->getParentClass()->getName();
$val = $val->getParentClass();
}
return $parentClasses;
}
}