Skip to content
Permalink
Browse files

Merge pull request #53 from goaop/fix/resolve-self-constants-properly

Change logic of collecting self constants, resolves #49
  • Loading branch information...
lisachenko committed Dec 12, 2016
2 parents ab5fb45 + 640aa5b commit 579c677a9092dc870dfdcb5c569f58fc10200d4c
Showing with 7 additions and 11 deletions.
  1. +7 −11 src/Traits/ReflectionClassLikeTrait.php
@@ -208,12 +208,10 @@ public function getConstant($name)
public function getConstants()
{
if (!isset($this->constants)) {
$directConstants = $this->findConstants();
$parentConstants = $this->recursiveCollect(function (array &$result, \ReflectionClass $instance) {
$this->constants = $this->recursiveCollect(function (array &$result, \ReflectionClass $instance) {
$result += $instance->getConstants();
});
$this->constants = $directConstants + $parentConstants;
$this->collectSelfConstants();
}
return $this->constants;
@@ -927,13 +925,12 @@ private function recursiveCollect(\Closure $collector)
}
/**
* Returns list of constants from the class
*
* @return array
* Collects list of constants from the class itself
*/
private function findConstants()
private function collectSelfConstants()
{
$expressionSolver = new NodeExpressionResolver($this);
$localConstants = [];
// constants can be only top-level nodes in the class, so we can scan them directly
foreach ($this->classLikeNode->stmts as $classLevelNode) {
@@ -942,12 +939,11 @@ private function findConstants()
if (!empty($nodeConstants)) {
foreach ($nodeConstants as $nodeConstant) {
$expressionSolver->process($nodeConstant->value);
$this->constants[$nodeConstant->name] = $expressionSolver->getValue();
$localConstants[$nodeConstant->name] = $expressionSolver->getValue();
$this->constants = $localConstants + $this->constants;
}
}
}
}
return $this->constants ?: [];
}
}

0 comments on commit 579c677

Please sign in to comment.
You can’t perform that action at this time.