Skip to content

Commit 255e988

Browse files
committed
Merge branch '2.15' into 2.16
* 2.15: YodaStyleFixer - fix precedence for T_MOD_EQUAL and T_COALESCE_EQUAL TernaryToNullCoalescingFixer - handle yield from
2 parents 3e81b7b + d51dd1e commit 255e988

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-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 = [

src/Fixer/Operator/TernaryToNullCoalescingFixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ private function hasChangingContent(Tokens $tokens)
201201
T_INC,
202202
T_STRING,
203203
T_YIELD,
204+
T_YIELD_FROM,
204205
];
205206

206207
foreach ($tokens as $token) {

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
}

tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function provideFixCases()
6262
['<?php $x = isset($a[foo()]) ? $a[foo()] : null;'],
6363
['<?php $x = isset($a[$callback()]) ? $a[$callback()] : null;'],
6464
['<?php $y = isset($a) ? 2**3 : 3**2;'],
65+
['<?php $x = function(){isset($a[yield from $a]) ? $a[yield from $a] : null;};'],
6566
// Fix cases.
6667
'Common fix case (I).' => [
6768
'<?php $x = $a ?? null;',

0 commit comments

Comments
 (0)