/**
  * @param \PHP\Manipulator\TokenContainer $container
  * @param \PHP\Manipulator\Token $targetToken
  * @param \PHP\Manipulator\Token $newToken
  */
 protected function _insertToken(Token $newToken, Iterator $iterator)
 {
     $this->_container->insertTokenAfter($iterator->current(), $newToken);
 }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
0
 /**
  * @param  \PHP\Manipulator\TokenContainer\Iterator $iterator
  * @param  \Closure $closure
  * @param  \PHP\Manipulator\Token $token
  *
  * @dataProvider getNextMatchingTokenProvider
  * @covers \PHP\Manipulator\AHelper::getNextMatchingToken
  */
 public function testGetNextMatchingToken($iterator, $closure, $token)
 {
     $ahelper = new AHelper();
     $start = $iterator->current();
     $matchingToken = $ahelper->getNextMatchingToken($iterator, $closure);
     $this->assertTrue($iterator->valid(), 'Iterator is not valid');
     $this->assertSame($start, $iterator->current(), 'Iterator is not at starting-position');
     $this->assertSame($token, $matchingToken);
 }
Exemplo n.º 4
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]);
 }
Exemplo n.º 5
0
 protected function _init()
 {
     parent::_init();
     $this->_keys = array_reverse($this->_keys);
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 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;
 }
Exemplo n.º 8
0
 /**
  * @param \PHP\Manipulator\Token $token
  * @var boolean
  */
 protected function _isConstant(Iterator $iterator)
 {
     return $this->isType($iterator->current(), T_STRING) && (true === $this->_isConstant || $this->_notInsideClassFunctionMethodUseOrNamespace() && !$this->isFollowedByTokenValue($iterator, '::') && !$this->isFollowedByTokenValue($iterator, '('));
 }