/** * 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; }
/** * @param ReflectedClass|ReflectedInterface|ReflectedTrait $class * @return array */ protected function processClassData($class, $includeFile = false) { $data = []; // $data['namespace'] = $class->getNamespace(); $data['namespace'] = ltrim($class->getNamespace(), '\\'); $data['name'] = $class->getName(); $data['extends'] = $class->getParent(); $data['dependencies'] = $class->getDependencies(); $data['methods'] = $this->processMethods($class); try { if ($includeFile) { include_once $includeFile; } $reflection = new \ReflectionClass($class->getFullname()); //$data['constants'] = $this->processConstants($reflection); $data['constants'] = $this->processConstants($reflection); $data['properties'] = $this->processProperties($reflection); } catch (\Exception $e) { } return $data; }