Skip to content

Commit 9010cf4

Browse files
committed
Fixed bug #3003 : Squiz.Formatting.OperatorBracket autofix incorrect when assignment used with null coalescing operator
1 parent 7c5e889 commit 9010cf4

File tree

5 files changed

+10
-0
lines changed

5 files changed

+10
-0
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
7878
-- Thanks to Michael S for the patch
7979
- Fixed bug #2913 : Generic.WhiteSpace.ScopeIndent false positive when opening and closing tag on same line inside conditional
8080
- Fixed bug #2992 : Enabling caching using a ruleset produces invalid cache files when using --sniffs and --exclude CLI args
81+
- Fixed bug #3003 : Squiz.Formatting.OperatorBracket autofix incorrect when assignment used with null coalescing operator
8182
- Fixed bug #3145 : Autoloading of sniff fails when multiple classes declared in same file
8283
- Fixed bug #3157 : PSR2.ControlStructures.SwitchDeclaration.BreakIndent false positive when case keyword is not indented
8384
- Fixed bug #3163 : Undefined index error with pre-commit hook using husky on PHP 7.4

src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ public function addMissingBracketsError($phpcsFile, $stackPtr)
330330

331331
$before = $phpcsFile->findNext(Tokens::$emptyTokens, ($before + 1), null, true);
332332

333+
// A few extra tokens are allowed to be on the right side of the expression.
334+
$allowed[T_EQUAL] = true;
335+
$allowed[T_NEW] = true;
336+
333337
// Find the last token in the expression.
334338
for ($after = ($stackPtr + 1); $after < $phpcsFile->numTokens; $after++) {
335339
// Special case for plus operators because we can't tell if they are used

src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ $test = myfunc(1 * static::TEST);
173173

174174
$errorPos = $params[$x]?->getLine() + $commentStart;
175175

176+
$foo = $this->gmail ?? $this->gmail = new Google_Service_Gmail($this->google);
177+
176178
exit -1;

src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.inc.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,6 @@ $test = myfunc(1 * static::TEST);
173173

174174
$errorPos = ($params[$x]?->getLine() + $commentStart);
175175

176+
$foo = ($this->gmail ?? $this->gmail = new Google_Service_Gmail($this->google));
177+
176178
exit -1;

src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function getErrorList($testFile='OperatorBracketUnitTest.inc')
6767
165 => 2,
6868
169 => 1,
6969
174 => 1,
70+
176 => 1,
7071
];
7172
break;
7273
case 'OperatorBracketUnitTest.js':

0 commit comments

Comments
 (0)