本文整理汇总了PHP中PhpCsFixer\Tokenizer\TokensAnalyzer::isBinaryOperator方法的典型用法代码示例。如果您正苦于以下问题:PHP TokensAnalyzer::isBinaryOperator方法的具体用法?PHP TokensAnalyzer::isBinaryOperator怎么用?PHP TokensAnalyzer::isBinaryOperator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhpCsFixer\Tokenizer\TokensAnalyzer
的用法示例。
在下文中一共展示了TokensAnalyzer::isBinaryOperator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
for ($index = $tokens->count() - 1; $index >= 0; --$index) {
if (!$tokensAnalyzer->isBinaryOperator($index)) {
continue;
}
if (!$tokens[$index + 1]->isWhitespace()) {
$tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
}
if (!$tokens[$index - 1]->isWhitespace()) {
$tokens->insertAt($index, new Token(array(T_WHITESPACE, ' ')));
}
}
}
示例2: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
// last and first tokens cannot be an operator
for ($index = $tokens->count() - 2; $index >= 0; --$index) {
if (!$tokensAnalyzer->isBinaryOperator($index)) {
continue;
}
$isDeclare = $this->isDeclareStatement($tokens, $index);
if (false !== $isDeclare) {
$index = $isDeclare;
// skip `declare(foo ==bar)`, see `declare_equal_normalize`
} else {
$this->fixWhiteSpaceAroundOperator($tokens, $index);
}
// previous of binary operator is now never an operator / previous of declare statement cannot be an operator
--$index;
}
}
示例3: fix
/**
* {@inheritdoc}
*/
public function fix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
for ($index = $tokens->count() - 1; $index >= 0; --$index) {
if (!$tokensAnalyzer->isBinaryOperator($index)) {
continue;
}
// skip `declare(foo ==bar)`
$prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($index);
if ($tokens[$prevMeaningfulIndex]->isGivenKind(T_STRING)) {
$prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulIndex);
if ($tokens[$prevMeaningfulIndex]->equals('(')) {
$prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulIndex);
if ($tokens[$prevMeaningfulIndex]->isGivenKind(T_DECLARE)) {
continue;
}
}
}
// fix white space after operator
if ($tokens[$index + 1]->isWhitespace()) {
$content = $tokens[$index + 1]->getContent();
if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) {
$tokens[$index + 1]->setContent(' ');
}
} else {
$tokens->insertAt($index + 1, new Token(array(T_WHITESPACE, ' ')));
}
// fix white space before operator
if ($tokens[$index - 1]->isWhitespace()) {
$content = $tokens[$index - 1]->getContent();
if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
$tokens[$index - 1]->setContent(' ');
}
} else {
$tokens->insertAt($index, new Token(array(T_WHITESPACE, ' ')));
}
--$index;
// skip check for binary operator on the whitespace token that is fixed.
}
}
示例4: testIsBinaryOperator70
/**
* @dataProvider provideIsBinaryOperator70
* @requires PHP 7.0
*/
public function testIsBinaryOperator70($source, array $expected)
{
$tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source));
foreach ($expected as $index => $isBinary) {
$this->assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index));
if ($isBinary) {
$this->assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index));
$this->assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index));
}
}
}