Skip to content

Commit a739358

Browse files
committed
Squiz.Formatting.OperatorBracket now correctly fixes statements containing short array syntax
1 parent 77b2aa7 commit a739358

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
6262
- Squiz.Formatting.OperatorBracket no longer throws errors for PHP 7.1 multi catch exceptions
6363
- Squiz.Commenting.LongConditionClosingComment now supports finally statements
6464
- Squiz.Formatting.OperatorBracket now correctly fixes pipe separated flags
65+
- Squiz.Formatting.OperatorBracket now correctly fixes statements containing short array syntax
6566
- Squiz.PHP.EmbeddedPhp now properly fixes cases where the only content in an embedded PHP block is a comment
6667
-- Thanks to Juliette Reinders Folmer for the patch
6768
- Squiz.WhiteSpace.ControlStructureSpacing now ignores comments when checking blank lines at the top of control structures

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

+10
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ public function addMissingBracketsError($phpcsFile, $stackPtr)
317317
continue;
318318
}
319319

320+
if ($tokens[$before]['code'] === T_CLOSE_SHORT_ARRAY) {
321+
$before = $tokens[$before]['bracket_opener'];
322+
continue;
323+
}
324+
320325
break;
321326
}//end for
322327

@@ -348,6 +353,11 @@ public function addMissingBracketsError($phpcsFile, $stackPtr)
348353
continue;
349354
}
350355

356+
if ($tokens[$after]['code'] === T_OPEN_SHORT_ARRAY) {
357+
$after = $tokens[$after]['bracket_closer'];
358+
continue;
359+
}
360+
351361
break;
352362
}//end for
353363

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

+2
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,5 @@ if (empty($foo[-1]) === true) {
157157
try {
158158
} catch (AException | BException $e) {
159159
}
160+
161+
$var = $foo['blah'] + [];

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

+2
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,5 @@ if (empty($foo[-1]) === true) {
157157
try {
158158
} catch (AException | BException $e) {
159159
}
160+
161+
$var = ($foo['blah'] + []);

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

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public function getErrorList($testFile='OperatorBracketUnitTest.inc')
6262
137 => 1,
6363
139 => 1,
6464
150 => 1,
65+
161 => 1,
6566
);
6667
break;
6768
case 'OperatorBracketUnitTest.js':

0 commit comments

Comments
 (0)