Skip to content

Commit e964c77

Browse files
committed
bug #4327 TokensAnalyzer - add concat operator to list of binary operators (SpacePossum)
This PR was squashed before being merged into the 2.12 branch (closes #4327). Discussion ---------- TokensAnalyzer - add concat operator to list of binary operators Commits ------- 20699b5 TokensAnalyzer - add concat operator to list of binary operators
2 parents 701165b + 20699b5 commit e964c77

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

src/Fixer/ControlStructure/YodaStyleFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ private function isVariable(Tokens $tokens, $start, $end, $strict)
527527
if (
528528
$tokens[$index]->isCast()
529529
|| $tokens[$index]->isGivenKind(T_INSTANCEOF)
530-
|| $tokens[$index]->equalsAny(['.', '!'])
530+
|| $tokens[$index]->equals('!')
531531
|| $tokenAnalyzer->isBinaryOperator($index)
532532
) {
533533
return false;

src/Tokenizer/TokensAnalyzer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ public function isBinaryOperator($index)
504504
'>' => true,
505505
'|' => true,
506506
'^' => true,
507+
'.' => true,
507508
];
508509

509510
static $potentialUnaryNonArrayOperators = [

tests/Fixer/ControlStructure/YodaStyleFixerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,11 @@ function foo() {
445445
'<?php return $k === $myVar + 2;',
446446
['always_move_variable' => true],
447447
],
448+
[
449+
'<?php return $myVar . $b === $k;',
450+
'<?php return $k === $myVar . $b;',
451+
['always_move_variable' => true],
452+
],
448453
[
449454
'<?php return $myVar - 2 === $k;',
450455
'<?php return $k === $myVar - 2;',

tests/Tokenizer/TokensAnalyzerTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,26 @@ public function testIsBinaryOperator($source, array $expected)
890890
public function provideIsBinaryOperatorCases()
891891
{
892892
$cases = [
893+
[
894+
'<?php $a .= $b; ?>',
895+
[3 => true],
896+
],
897+
[
898+
'<?php $a . \'a\' ?>',
899+
[3 => true],
900+
],
901+
[
902+
'<?php $a &+ $b;',
903+
[3 => true],
904+
],
905+
[
906+
'<?php $a && $b;',
907+
[3 => true],
908+
],
909+
[
910+
'<?php $a & $b;',
911+
[3 => true],
912+
],
893913
[
894914
'<?php [] + [];',
895915
[4 => true],

0 commit comments

Comments
 (0)