Skip to content

Commit 1b06182

Browse files
committed
bug #4461 IsNullFixer - fix null coalescing operator handling (linniksa)
This PR was merged into the 2.12 branch. Discussion ---------- IsNullFixer - fix null coalescing operator handling Commits ------- 5b3112c IsNullFixer - fix null coalescing operator handling
2 parents b21d9db + 5b3112c commit 1b06182

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/Fixer/LanguageConstruct/IsNullFixer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
123123
$referenceEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $matches[1]);
124124
$isContainingDangerousConstructs = false;
125125
for ($paramTokenIndex = $matches[1]; $paramTokenIndex <= $referenceEnd; ++$paramTokenIndex) {
126-
if (\in_array($tokens[$paramTokenIndex]->getContent(), ['?', '?:', '='], true)) {
126+
if (\in_array($tokens[$paramTokenIndex]->getContent(), ['?', '?:', '=', '??'], true)) {
127127
$isContainingDangerousConstructs = true;
128128

129129
break;

tests/Fixer/LanguageConstruct/IsNullFixerTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,17 @@ public function provideNonYodaFixCases()
280280
];
281281
}
282282

283+
/**
284+
* @requires PHP 7.0
285+
*/
286+
public function testFix70()
287+
{
288+
$this->doTest(
289+
'<?php null !== ($a ?? null);',
290+
'<?php !is_null($a ?? null);'
291+
);
292+
}
293+
283294
/**
284295
* @param string $expected
285296
* @param string $input

0 commit comments

Comments
 (0)