本文整理汇总了PHP中PhpCsFixer\Tokenizer\TokensAnalyzer::isArrayMultiLine方法的典型用法代码示例。如果您正苦于以下问题:PHP TokensAnalyzer::isArrayMultiLine方法的具体用法?PHP TokensAnalyzer::isArrayMultiLine怎么用?PHP TokensAnalyzer::isArrayMultiLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpCsFixer\Tokenizer\TokensAnalyzer
的用法示例。
在下文中一共展示了TokensAnalyzer::isArrayMultiLine方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fixArray
private function fixArray(Tokens $tokens, $index)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
if ($tokensAnalyzer->isArrayMultiLine($index)) {
return;
}
$startIndex = $index;
if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
$startIndex = $tokens->getNextTokenOfKind($startIndex, array('('));
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
} else {
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
}
$beforeEndIndex = $tokens->getPrevMeaningfulToken($endIndex);
$beforeEndToken = $tokens[$beforeEndIndex];
if ($beforeEndToken->equals(',')) {
$tokens->removeTrailingWhitespace($beforeEndIndex);
$beforeEndToken->clear();
}
}
示例2: fixArray
private function fixArray(Tokens $tokens, $index)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
if (!$tokensAnalyzer->isArrayMultiLine($index)) {
return;
}
$startIndex = $index;
if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
$startIndex = $tokens->getNextTokenOfKind($startIndex, array('('));
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
} else {
$endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
}
$beforeEndIndex = $tokens->getPrevMeaningfulToken($endIndex);
$beforeEndToken = $tokens[$beforeEndIndex];
// if there is some item between braces then add `,` after it
if ($startIndex !== $beforeEndIndex && !$beforeEndToken->equalsAny(array(',', array(T_END_HEREDOC)))) {
$tokens->insertAt($beforeEndIndex + 1, new Token(','));
$endToken = $tokens[$endIndex];
if (!$endToken->isComment() && !$endToken->isWhitespace()) {
$tokens->ensureWhitespaceAtIndex($endIndex, 1, ' ');
}
}
}
示例3: testIsMultiLineArrayException
/**
* @expectedException \InvalidArgumentException
* @dataProvider provideArrayExceptions
*/
public function testIsMultiLineArrayException($source, $tokenIndex)
{
$tokens = Tokens::fromCode($source);
$tokensAnalyzer = new TokensAnalyzer($tokens);
$tokensAnalyzer->isArrayMultiLine($tokenIndex);
}