Skip to content

Commit f5586fd

Browse files
committed
Fixed bug #2479 : Generic.WhiteSpace.ScopeIndent error when using array destructuring with exact indent checking
1 parent 0137b38 commit f5586fd

File tree

5 files changed

+41
-16
lines changed

5 files changed

+41
-16
lines changed

package.xml

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,16 @@ http://pear.php.net/dtd/package-2.0.xsd">
1717
<date>2019-04-11</date>
1818
<time>09:34:00</time>
1919
<version>
20-
<release>3.4.2</release>
21-
<api>3.4.2</api>
20+
<release>3.5.0</release>
21+
<api>3.5.0</api>
2222
</version>
2323
<stability>
2424
<release>stable</release>
2525
<api>stable</api>
2626
</stability>
2727
<license uri="https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt">BSD 3-Clause License</license>
2828
<notes>
29-
- Squiz.Arrays.ArrayDeclaration now has improved handling of syntax errors
30-
- Fixed an issue where the PCRE JIT on PHP 7.3 caused PHPCS to die when using the parallel option
31-
-- PHPCS now disables the PCRE JIT before running
32-
- Fixed bug #2368 : MySource.PHP.AjaxNullComparison throws error when first function has no doc comment
33-
- Fixed bug #2414 : Indention false positive in switch/case/if combination
34-
- Fixed bug #2423 : Squiz.Formatting.OperatorBracket.MissingBrackets error with static
35-
- Fixed bug #2450 : Indentation false positive when closure containing nested IF conditions used as function argument
36-
- Fixed bug #2452 : LowercasePHPFunctions sniff failing on "new \File()"
37-
- Fixed bug #2453 : Squiz.CSS.SemicolonSpacingSniff false positive when style name proceeded by an asterisk
38-
-- Thanks to Juliette Reinders Folmer for the patch
39-
- Fixed bug #2464 : Fixer conflict between Generic.WhiteSpace.ScopeIndent and Squiz.WhiteSpace.ScopeClosingBrace when class indented 1 space
40-
- Fixed bug #2465 : Excluding a sniff by path is not working
41-
- Fixed bug #2467 : PHP open/close tags inside CSS files are replaced with internal PHPCS token strings when auto fixing
29+
- Fixed bug #2479 : Generic.WhiteSpace.ScopeIndent error when using array destructuring with exact indent checking
4230
</notes>
4331
<contents>
4432
<dir name="/">

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Config
2323
*
2424
* @var string
2525
*/
26-
const VERSION = '3.4.2';
26+
const VERSION = '3.5.0';
2727

2828
/**
2929
* Package stability; either stable, beta or alpha.

src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,24 @@ public function process(File $phpcsFile, $stackPtr)
231231

232232
if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
233233
$disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
234+
if ($this->debug === true) {
235+
$line = $tokens[$i]['line'];
236+
$type = $tokens[$disableExactEnd]['type'];
237+
echo "Opening short array bracket found on line $line".PHP_EOL;
238+
echo "\t=> disabling exact indent checking until $disableExactEnd ($type)".PHP_EOL;
239+
}
234240
}
235241

236242
if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS
237243
&& isset($tokens[$i]['parenthesis_closer']) === true
238244
) {
239245
$disableExactEnd = max($disableExactEnd, $tokens[$i]['parenthesis_closer']);
246+
if ($this->debug === true) {
247+
$line = $tokens[$i]['line'];
248+
$type = $tokens[$disableExactEnd]['type'];
249+
echo "Opening parenthesis found on line $line".PHP_EOL;
250+
echo "\t=> disabling exact indent checking until $disableExactEnd ($type)".PHP_EOL;
251+
}
240252
}
241253

242254
if ($exact === true && $i < $disableExactEnd) {
@@ -977,6 +989,17 @@ public function process(File $phpcsFile, $stackPtr)
977989
$i = $checkToken;
978990
}
979991

992+
// Don't check indents exactly between arrays as they tend to have custom rules.
993+
if ($tokens[$i]['code'] === T_OPEN_SHORT_ARRAY) {
994+
$disableExactEnd = max($disableExactEnd, $tokens[$i]['bracket_closer']);
995+
if ($this->debug === true) {
996+
$line = $tokens[$i]['line'];
997+
$type = $tokens[$disableExactEnd]['type'];
998+
echo "Opening short array bracket found on line $line".PHP_EOL;
999+
echo "\t=> disabling exact indent checking until $disableExactEnd ($type)".PHP_EOL;
1000+
}
1001+
}
1002+
9801003
// Completely skip here/now docs as the indent is a part of the
9811004
// content itself.
9821005
if ($tokens[$i]['code'] === T_START_HEREDOC

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.3.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ function test()
1515
'test3'
1616
);
1717
}
18+
19+
if ($foo) {
20+
[
21+
'enabled' => $enabled,
22+
'compression' => $compression,
23+
] = $options;
24+
}

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.3.inc.fixed

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,10 @@ function test()
1515
'test3'
1616
);
1717
}
18+
19+
if ($foo) {
20+
[
21+
'enabled' => $enabled,
22+
'compression' => $compression,
23+
] = $options;
24+
}

0 commit comments

Comments
 (0)