Skip to content

Commit 5bc34ce

Browse files
committed
Merge branch '2.12' into 2.13
2 parents 38d31f7 + 75797f6 commit 5bc34ce

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/Fixer/LanguageConstruct/IsNullFixer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
136136
$parentOperations = [T_IS_EQUAL, T_IS_NOT_EQUAL, T_IS_IDENTICAL, T_IS_NOT_IDENTICAL];
137137
$wrapIntoParentheses = $parentLeftToken->isGivenKind($parentOperations) || $parentRightToken->isGivenKind($parentOperations);
138138

139+
// possible trailing comma removed
140+
$prevIndex = $tokens->getPrevMeaningfulToken($referenceEnd);
141+
if ($tokens[$prevIndex]->equals(',')) {
142+
$tokens->clearTokenAndMergeSurroundingWhitespace($prevIndex);
143+
}
144+
139145
if (!$isContainingDangerousConstructs) {
140146
// closing parenthesis removed with leading spaces
141-
$prevIndex = $tokens->getPrevMeaningfulToken($referenceEnd);
142-
if ($tokens[$prevIndex]->equals(',')) {
143-
$tokens->clearTokenAndMergeSurroundingWhitespace($prevIndex);
144-
}
145147
$tokens->removeLeadingWhitespace($referenceEnd);
146148
$tokens->clearAt($referenceEnd);
147149

tests/Fixer/LanguageConstruct/IsNullFixerTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public function provideFixCases()
224224
'<?php if ((is_null($u) or $v) and ($w || is_null($x)) xor (!is_null($y) and $z)) echo "foo"; ?>',
225225
],
226226

227-
// edge cases: contains dangerous constructs, wrapped into parentheses
227+
// edge cases: $isContainingDangerousConstructs, $wrapIntoParentheses
228228
[
229229
'<?php null === ($a ? $x : $y);',
230230
'<?php is_null($a ? $x : $y);',
@@ -311,6 +311,20 @@ public function provideFix73Cases()
311311
'<?php if ((null === $u or $v) and ($w || null === $x) xor (null !== $y and $z)) echo "foo"; ?>',
312312
'<?php if ((is_null($u, ) or $v) and ($w || is_null($x, )) xor (!is_null($y, ) and $z)) echo "foo"; ?>',
313313
],
314+
315+
// edge cases: $isContainingDangerousConstructs, $wrapIntoParentheses
316+
[
317+
'<?php null === ($a ? $x : $y );',
318+
'<?php is_null($a ? $x : $y, );',
319+
],
320+
[
321+
'<?php $a === (null === $x);',
322+
'<?php $a === is_null($x, );',
323+
],
324+
[
325+
'<?php $a === (null === ($a ? $x : $y ));',
326+
'<?php $a === is_null($a ? $x : $y, );',
327+
],
314328
];
315329
}
316330
}

0 commit comments

Comments
 (0)