Пример #1
0
 /**
  * Extract class from position
  *
  * @param $n
  * @param TokenCollection $tokens
  * @return ReflectedClass
  */
 public function extract(&$n, TokenCollection $tokens)
 {
     // is PHP7 ?
     $previous = $tokens->get($n - 2);
     if ($previous && T_NEW === $previous->getType()) {
         // anonymous class
         $class = new ReflectedAnonymousClass($this->namespace, 'class@anonymous');
         return $class;
     }
     // is abstract ?
     $prev = $this->searcher->getPrevious($n, $tokens);
     $isAbstract = $prev && T_ABSTRACT === $prev->getType();
     $classname = $this->searcher->getFollowingName($n, $tokens);
     $class = new ReflectedClass($this->namespace, trim($classname));
     $class->setAbstract($isAbstract);
     return $class;
 }
Пример #2
0
 public function getPositionOfPrevious($tokenType, $n, TokenCollection $tokens)
 {
     for ($i = $n; $i > 0; $i--) {
         if ($tokenType == $tokens->get($i)->getType()) {
             return $i;
         }
     }
     return null;
 }