/**
  * @covers \PHP\Manipulator\Action\RemoveIndention::run
  * @dataProvider actionProvider
  */
 public function testAction($input, $expectedTokens)
 {
     $action = new RemoveIndention();
     $action->run($input);
     $this->assertTokenContainerMatch($expectedTokens, $input, false, 'Wrong output');
 }
示例#2
0
 /**
  * Unindents all Code and then indent it right
  *
  * @param \PHP\Manipulator\TokenContainer $container
  * @param mixed $params
  */
 public function run(TokenContainer $container)
 {
     $this->_reset();
     $this->_container = $container;
     $removeIndention = new RemoveIndention();
     $removeIndention->run($container);
     $iterator = $container->getIterator();
     $previous = null;
     while ($iterator->valid()) {
         $token = $iterator->current();
         $this->_checkAndChangeIndentionLevel($token);
         $this->_checkForMultilineCommentAndIndent($token);
         $this->_useIndentionCheck($token);
         $this->_switchIndentionCheck($token);
         if (null !== $previous && $this->evaluateConstraint('IsSinglelineComment', $previous) && !$this->_isWhitespaceWithBreak($token)) {
             $newToken = new Token('', T_WHITESPACE);
             $this->_indentWhitespace($newToken);
             $container->insertTokenAfter($previous, $newToken);
             $iterator = $container->getIterator();
             $iterator->seekToToken($token);
         } elseif ($this->_isWhitespaceWithBreak($token)) {
             $iterator->next();
             if (!$iterator->valid()) {
                 break;
             }
             $nextToken = $iterator->current();
             $this->_checkAndChangeIndentionLevelDecreasment($nextToken);
             $this->_indentWhitespace($token);
             if ($this->isClosingCurlyBrace($nextToken) && true === $this->_insideSwitch && true === $this->_insideCase) {
                 if ($this->_isSwitchClosingCurlyBrace($nextToken)) {
                     $this->_removeLastIndention($token);
                 }
             }
             $this->_checkForMultilineCommentAndIndent($nextToken);
             $this->_checkAndChangeIndentionLevelIncreasment($nextToken);
             $this->_useIndentionCheck($nextToken);
             $this->_switchIndentionCheck($nextToken);
         }
         $previous = $iterator->current();
         $iterator->next();
     }
     $container->retokenize();
 }