Skip to content

Commit 25fa900

Browse files
committed
bug #4829 YodaStyleFixer - fix precedence for T_MOD_EQUAL and T_COALESCE_EQUAL (SpacePossum)
This PR was squashed before being merged into the 2.15 branch (closes #4829). Discussion ---------- YodaStyleFixer - fix precedence for T_MOD_EQUAL and T_COALESCE_EQUAL Commits ------- e8d6ed8 YodaStyleFixer - fix precedence for T_MOD_EQUAL and T_COALESCE_EQUAL
2 parents f212ab4 + e8d6ed8 commit 25fa900

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/Fixer/ControlStructure/YodaStyleFixer.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -459,32 +459,34 @@ private function isOfLowerPrecedence(Token $token)
459459
T_CONCAT_EQUAL, // .=
460460
T_DIV_EQUAL, // /=
461461
T_DOUBLE_ARROW, // =>
462+
T_ECHO, // echo
462463
T_GOTO, // goto
463464
T_LOGICAL_AND, // and
464465
T_LOGICAL_OR, // or
465466
T_LOGICAL_XOR, // xor
466467
T_MINUS_EQUAL, // -=
468+
T_MOD_EQUAL, // %=
467469
T_MUL_EQUAL, // *=
470+
T_OPEN_TAG, // <?php
471+
T_OPEN_TAG_WITH_ECHO,
468472
T_OR_EQUAL, // |=
469473
T_PLUS_EQUAL, // +=
474+
T_POW_EQUAL, // **=
475+
T_PRINT, // print
470476
T_RETURN, // return
471-
T_SL_EQUAL, // <<
477+
T_SL_EQUAL, // <<=
472478
T_SR_EQUAL, // >>=
473479
T_THROW, // throw
474480
T_XOR_EQUAL, // ^=
475-
T_ECHO,
476-
T_PRINT,
477-
T_OPEN_TAG,
478-
T_OPEN_TAG_WITH_ECHO,
479481
];
480482

481-
if (\defined('T_POW_EQUAL')) {
482-
$tokens[] = T_POW_EQUAL; // **=
483-
}
484-
485483
if (\defined('T_COALESCE')) {
486484
$tokens[] = T_COALESCE; // ??
487485
}
486+
487+
if (\defined('T_COALESCE_EQUAL')) {
488+
$tokens[] = T_COALESCE_EQUAL; // ??=
489+
}
488490
}
489491

490492
static $otherTokens = [

tests/Fixer/ControlStructure/YodaStyleFixerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,10 @@ function foo() {
590590
'<?php $a **= 4 === $b ? 2 : 3;',
591591
'<?php $a **= $b === 4 ? 2 : 3;',
592592
],
593+
[
594+
'<?php $a %= 4 === $b ? 2 : 3;',
595+
'<?php $a %= $b === 4 ? 2 : 3;',
596+
],
593597
];
594598
}
595599

@@ -928,6 +932,10 @@ public function providePHP74Cases()
928932
'less_and_greater' => false,
929933
],
930934
],
935+
[
936+
'<?php $a ??= 4 === $b ? 2 : 3;',
937+
'<?php $a ??= $b === 4 ? 2 : 3;',
938+
],
931939
];
932940
}
933941
}

0 commit comments

Comments
 (0)