Skip to content

Commit

Permalink
bug: Fix BinaryOperatorSpacesFixer adding whitespace outside PHP bloc…
Browse files Browse the repository at this point in the history
…ks (#6476)

Do not treat `[T_INLINE_HTML, '-']` as operator
  • Loading branch information
jrmajor committed Jul 13, 2022
1 parent b957583 commit 93beae7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Tokenizer/TokensAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ public function isBinaryOperator(int $index): bool
$tokens = $this->tokens;
$token = $tokens[$index];

if ($token->isGivenKind([T_ENCAPSED_AND_WHITESPACE, CT::T_TYPE_INTERSECTION])) {
if ($token->isGivenKind([T_INLINE_HTML, T_ENCAPSED_AND_WHITESPACE, CT::T_TYPE_INTERSECTION])) {
return false;
}

Expand Down
1 change: 1 addition & 0 deletions tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,7 @@ public function provideFixCases(): array
$b;
',
],
['<a href="test-<?=$path?>-<?=$id?>.html">Test</a>'],
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Tokenizer/TokensAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,10 @@ public function provideIsBinaryOperatorCases(): iterable
[9 => false],
'<?php $a = "{$value}-{$theSwitch}";',
],
[
[3 => false],
'<?=$path?>-<?=$id?>',
],
];

$operators = [
Expand Down

0 comments on commit 93beae7

Please sign in to comment.