예제 #1
0
 /**
  * @param \PHP\Manipulator\TokenContainer\Iterator $iterator
  */
 protected function _seekToPhpdoc(Iterator $iterator)
 {
     $token = $iterator->current();
     // travel reverse as long as there is only whitespace and stuff
     $iterator->previous();
     while ($iterator->valid()) {
         if (!$this->isType($iterator->current(), array(T_WHITESPACE, T_PUBLIC, T_COMMENT, T_DOC_COMMENT, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC))) {
             $iterator->next();
             while ($iterator->valid()) {
                 if (!$this->isType($iterator->current(), array(T_DOC_COMMENT, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_FUNCTION))) {
                     $iterator->next();
                 } else {
                     break;
                 }
             }
             break;
         }
         $iterator->previous();
     }
     // didn't find anything
     if (!$iterator->valid()) {
         $iterator->seekToToken($token);
     }
 }
예제 #2
0
 /**
  * @param integer|null $type
  * @param \PHP\Manipulator\TokenContainer\Iterator $iterator
  * @return boolean
  */
 protected function _isOpeningBraceAfterType($type, Iterator $iterator)
 {
     $token = $iterator->current();
     if (!$this->isOpeningCurlyBrace($token)) {
         return false;
     }
     $breakTokens = array(T_CLASS, T_FUNCTION, T_IF, T_ELSE, T_ELSEIF);
     $filterCallback = function ($tokentype) use($type) {
         return $tokentype === $type ? false : true;
     };
     $breakTokens = array_filter($breakTokens, $filterCallback);
     $result = false;
     while ($iterator->valid()) {
         $iterator->previous();
         if ($iterator->valid() === false) {
             $result = false;
             break;
         }
         $current = $iterator->current();
         if ($this->isType($current, $breakTokens)) {
             $result = false;
             break;
         }
         if ($this->isType($current, $type)) {
             $result = true;
             break;
         }
         $iterator->previous();
     }
     $iterator->seekToToken($token);
     return $result;
 }
예제 #3
0
 /**
  * @covers \PHP\Manipulator\TokenContainer\Iterator::update
  */
 public function testUpdateWithSeek()
 {
     $container = $this->getTestContainerWithHoles();
     $iterator = new Iterator($container);
     $iterator->seekToToken($container[5]);
     $this->assertSame($iterator->current(), $container[5]);
     $iterator->update($container[5]);
     $this->assertSame($iterator->current(), $container[5]);
 }
예제 #4
0
 /**
  * @param \PHP\Manipulator\TokenContainer\Iterator $iterator
  * @param \Closure $isSearchedToken
  * @param \Closure $isAllowedToken
  * @param \PHP\Manipulator\Token $found
  * @return boolean
  */
 public function isFollowed(Iterator $iterator, \Closure $isSearchedToken, \Closure $isAllowedToken, Token &$found = null)
 {
     $token = $iterator->current();
     $result = false;
     $iterator->next();
     while ($iterator->valid()) {
         $currentToken = $iterator->current();
         if ($isSearchedToken($currentToken)) {
             $found = $currentToken;
             $result = true;
             break;
         }
         if (!$isAllowedToken($currentToken)) {
             break;
         }
         $iterator->next();
     }
     $iterator->seekToToken($token);
     return $result;
 }