/** * @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(); }
/** * @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); } }
/** * @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'); } }
/** * @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; }
/** * @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; }