Exemplo n.º 1
0
 /**
  * @param TokenStream\AbstractToken $token
  * @param array<array<string|integer>> $tokens
  */
 public function insertAllBefore(AbstractToken $token, array $tokens)
 {
     $newTokens = array();
     $line = $token->getLine();
     foreach ($tokens as $rawToken) {
         $newTokens[] = array($rawToken[0], isset($rawToken[1]) ? $rawToken[1] : null, $line);
         if (isset($rawToken[1])) {
             $line += substr_count($rawToken[1], "\n");
         }
     }
     $this->insertAllTokensBefore($token, $newTokens);
 }
 private function isSafeEndToken(AbstractToken $token)
 {
     $nextNoWhitespace = $token->findNextToken('NO_WHITESPACE')->get();
     // If the end token is followed by a comment on the same same line,
     // we consider it unsafe for rewriting.
     if ($nextNoWhitespace->matches('COMMENT') && $token->getLine() === $nextNoWhitespace->getLine()) {
         return false;
     }
     return true;
 }
 private function checkLeftCurlyPlacement(AbstractToken $startToken, AbstractToken $endToken, AbstractToken $curlyToken, $config)
 {
     if ('new line on wrap' === $config) {
         $config = $startToken->getLine() === $endToken->getLine() ? 'same line' : 'new line';
     }
     switch ($config) {
         case 'same line':
             if ($endToken->getLine() !== $curlyToken->getLine()) {
                 $this->phpFile->addComment($curlyToken->getLine(), Comment::warning('coding_style.token_should_be_on_same_line', '``%token%`` should probably be on the same line like ``%end_token%``.', array('token' => $curlyToken->getContent(), 'end_token' => $endToken->getContent()))->varyIn(array()));
             }
             break;
         case 'new line':
             if ($endToken->getLine() + 1 !== $curlyToken->getLine()) {
                 $this->phpFile->addComment($curlyToken->getLine(), Comment::warning('coding_style.token_should_be_on_new_line', '``%token`` should probably be on a new line after ``%end_token%``.', array('token' => $curlyToken->getContent(), 'end_token' => $endToken->getContent()))->varyIn(array()));
             }
             break;
         default:
             throw new \InvalidArgumentException(sprintf('Unknown left curly setting "%s".', $config));
     }
 }