1 | <?php |
||
21 | class StaticVariablesCollector extends NodeVisitorAbstract |
||
22 | { |
||
23 | /** |
||
24 | * Reflection context, eg. ReflectionClass, ReflectionMethod, etc |
||
25 | * |
||
26 | * @var mixed |
||
27 | */ |
||
28 | private $context; |
||
29 | |||
30 | private $staticVariables = []; |
||
31 | |||
32 | /** |
||
33 | * Default constructor |
||
34 | * |
||
35 | * @param mixed $context Reflection context, eg. ReflectionClass, ReflectionMethod, etc |
||
36 | */ |
||
37 | 2 | public function __construct($context) |
|
41 | |||
42 | /** |
||
43 | * {@inheritDoc} |
||
44 | */ |
||
45 | 2 | public function enterNode(Node $node) |
|
46 | { |
||
47 | // There may be internal closures, we do not need to look at them |
||
48 | 2 | if ($node instanceof Node\Expr\Closure) { |
|
49 | 2 | return NodeTraverser::DONT_TRAVERSE_CHILDREN; |
|
50 | } |
||
51 | |||
52 | 2 | if ($node instanceof Node\Stmt\Static_) { |
|
53 | 2 | $expressionSolver = new NodeExpressionResolver($this->context); |
|
54 | 2 | $staticVariables = $node->vars; |
|
55 | 2 | foreach ($staticVariables as $staticVariable) { |
|
56 | 2 | $expr = $staticVariable->default; |
|
57 | 2 | if ($expr) { |
|
58 | 2 | $expressionSolver->process($expr); |
|
59 | 2 | $value = $expressionSolver->getValue(); |
|
60 | } else { |
||
61 | $value = null; |
||
62 | } |
||
63 | |||
64 | 2 | $this->staticVariables[$staticVariable->name] = $value; |
|
65 | } |
||
66 | } |
||
67 | |||
68 | 2 | return null; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Returns an associative map of static variables in the method/function body |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | 2 | public function getStaticVariables() |
|
80 | } |
||
81 |