/** * Extract dependency from call * * @param $n * @param TokenCollection $tokens * @return string * @throws \LogicException */ public function extract(&$n, TokenCollection $tokens) { $token = $tokens[$n]; $call = null; switch ($token->getType()) { case T_PAAMAYIM_NEKUDOTAYIM: $prev = $n - 1; $value = $this->searcher->getUnder(array('::'), $prev, $tokens); switch (true) { case $value == 'parent' && $this->currentClass: return $this->currentClass->getParent(); case $value == 'parent': // we try to get the name of the parent class $extendPosition = $this->searcher->getExtendPosition($tokens, $n); return $this->searcher->getFollowingName($extendPosition, $tokens); case ($value == 'static' || $value === 'self') && $this->currentClass: return $this->currentClass->getFullname(); case $value == 'static' || $value === 'self': $extendPosition = $this->searcher->getClassNamePosition($tokens); return $this->searcher->getFollowingName($extendPosition, $tokens); default: return $value; } case T_NEW: $call = $this->searcher->getFollowingName($n, $tokens); if (preg_match('!^(\\w+)!', $call, $matches)) { // fixes PHP 5.4: (new MyClass)->foo() $call = $matches[1]; } break; } if (null === $call) { throw new \LogicException('Classname of call not found'); } return $call; }