예제 #1
0
 /**
  * @param \PHP\Manipulator\TokenContainerIterator $iterator
  */
 protected function _setNext(TokenContainer\Iterator $iterator)
 {
     $iterator->next();
     $iterator->next();
     if ($iterator->valid()) {
         $this->_next = $iterator->current();
     } else {
         $this->_next = null;
     }
     $iterator->previous();
     $iterator->previous();
 }
 /**
  * @param Iterator $iterator
  */
 protected function _moveIteratorBackFromTagetToken(Iterator $iterator)
 {
     $iterator->next();
 }
 /**
  * @param Iterator $iterator
  */
 protected function _moveIteratorToTargetToken(Iterator $iterator)
 {
     $iterator->next();
 }
예제 #4
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);
     }
 }
예제 #5
0
 /**
  * @covers \PHP\Manipulator\TokenContainer\Iterator::current
  * @covers \PHP\Manipulator\TokenContainer\Iterator::<protected>
  */
 public function testCurrentThrowsOutOfBoundsExceptionIfIteratorIsNotValid()
 {
     $container = $this->getTestContainerWithHoles();
     $iterator = new Iterator($container);
     $iterator->seek(6);
     $iterator->next();
     try {
         $iterator->current();
         $this->fail('Expected exception not thrown');
     } catch (\OutOfBoundsException $e) {
         $this->assertEquals('Position not valid', $e->getMessage(), 'Wrong exception message');
     }
 }
예제 #6
0
 /**
  * @param \PHP\Manipulator\TokenContainer\Iterator $iterator
  * @return boolean
  */
 protected function _isPrecededByWrongWhitespace(Iterator $iterator)
 {
     $iterator->previous();
     $newToken = $iterator->current();
     $iterator->next();
     if ($this->isType($newToken, T_WHITESPACE) && $newToken->getValue() !== ' ') {
         return true;
     }
     return false;
 }
예제 #7
0
 /**
  * @param \PHP\Manipulator\TokenContainer\Iterator $iterator
  * @param \Closure $closure
  * @return \PHP\Manipulator\Token
  */
 public function getNextMatchingToken(Iterator $iterator, \Closure $closure)
 {
     $token = $iterator->current();
     $foundToken = null;
     while ($iterator->valid()) {
         $currentToken = $iterator->current();
         if ($closure($currentToken)) {
             $foundToken = $currentToken;
             break;
         }
         $iterator->next();
     }
     $iterator->update($token);
     return $foundToken;
 }