private function replaceNameOccurrences(Tokens $tokens, $name, $startIndex, $endIndex) { for ($i = $startIndex; $i < $endIndex; ++$i) { $token = $tokens[$i]; if ($token->isGivenKind(T_FUNCTION) && $tokens->isLambda($i)) { $i = $tokens->getNextTokenOfKind($i, array('{')); $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i); continue; } if (!$token->equals(array(T_STRING, $name), false)) { continue; } $prevToken = $tokens[$tokens->getPrevMeaningfulToken($i)]; $nextToken = $tokens[$tokens->getNextMeaningfulToken($i)]; if ($prevToken->isGivenKind(T_NS_SEPARATOR) || $nextToken->isGivenKind(T_NS_SEPARATOR)) { continue; } if ( $prevToken->isGivenKind(array(T_INSTANCEOF, T_NEW)) || $nextToken->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM) ) { $token->setContent('self'); } } }
private function fixLambdas(Tokens $tokens) { for ($index = $tokens->count() - 1; 0 <= $index; --$index) { $token = $tokens[$index]; if (!$token->isGivenKind(T_FUNCTION) || !$tokens->isLambda($index)) { continue; } $nextIndex = $tokens->getNextTokenOfKind($index, array('{')); $tokens->ensureWhitespaceAtIndex($nextIndex - 1, 1, ' '); } }
private function fixLambdas(Tokens $tokens) { for ($index = $tokens->count() - 1; 0 <= $index; --$index) { $token = $tokens[$index]; if (!$token->isGivenKind(T_FUNCTION) || !$tokens->isLambda($index)) { continue; } $braceIndex = $tokens->getNextTokenOfKind($index, array('{')); $commentIndex = $tokens->getPrevNonWhitespace($braceIndex); $comment = $tokens[$commentIndex]; if ($comment->isGivenKind(T_COMMENT) && '/*' !== substr($comment->getContent(), 0, 2)) { $commentPrototype = $comment->getPrototype(); $commentPrototype[1] = rtrim($commentPrototype[1]); $tokens[$commentIndex]->override($tokens[$braceIndex]->getPrototype()); $tokens[$braceIndex]->override($commentPrototype); $braceIndex = $commentIndex; if ($tokens[$commentIndex + 1]->isWhitespace()) { $tokens[$commentIndex + 1]->clear(); } } $tokens->ensureWhitespaceAtIndex($braceIndex - 1, 1, ' '); } }