Skip to content

Commit f5dc023

Browse files
committed
Fixed bug #2632 : Incorrect indentation of lines starting with static inside closures
1 parent 52e9819 commit f5dc023

File tree

7 files changed

+29
-5
lines changed

7 files changed

+29
-5
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
4848
- Fixed bug #2624 : PSR12.Traits.UseDeclaration doesnt apply the correct indent during auto fixing
4949
- Fixed bug #2626 : PSR12.Files.FileHeader detects @var annotations as file docblocks
5050
- Fixed bug #2628 : PSR12.Traits.UseDeclaration does not allow comments above a USE declaration
51+
- Fixed bug #2632 : Incorrect indentation of lines starting with "static" inside closures
5152
- Fixed bug #2641 : PSR12.Functions.NullableTypeDeclaration false positive when using new static()
5253
</notes>
5354
<contents>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,10 @@ public function process(File $phpcsFile, $stackPtr)
844844
&& $tokens[($checkToken + 1)]['code'] !== T_DOUBLE_COLON
845845
) {
846846
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($checkToken + 1), null, true);
847-
if ($next === false || $tokens[$next]['code'] !== T_CLOSURE) {
847+
if ($next === false
848+
|| ($tokens[$next]['code'] !== T_CLOSURE
849+
&& $tokens[$next]['code'] !== T_VARIABLE)
850+
) {
848851
if ($this->debug === true) {
849852
$line = $tokens[$checkToken]['line'];
850853
$type = $tokens[$checkToken]['type'];

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ FOO
14291429
$a,
14301430
];
14311431

1432+
$query = Model::query()
1433+
->when($a, function () {
1434+
static $b = '';
1435+
});
1436+
14321437
?>
14331438

14341439
<?php

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ FOO
14291429
$a,
14301430
];
14311431

1432+
$query = Model::query()
1433+
->when($a, function () {
1434+
static $b = '';
1435+
});
1436+
14321437
?>
14331438

14341439
<?php

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ FOO
14291429
$a,
14301430
];
14311431

1432+
$query = Model::query()
1433+
->when($a, function () {
1434+
static $b = '';
1435+
});
1436+
14321437
?>
14331438

14341439
<?php

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,11 @@ FOO
14291429
$a,
14301430
];
14311431

1432+
$query = Model::query()
1433+
->when($a, function () {
1434+
static $b = '';
1435+
});
1436+
14321437
?>
14331438

14341439
<?php

src/Standards/Generic/Tests/WhiteSpace/ScopeIndentUnitTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ public function getErrorList($testFile='ScopeIndentUnitTest.inc')
178178
1340 => 1,
179179
1342 => 1,
180180
1345 => 1,
181-
1435 => 1,
182-
1436 => 1,
183-
1437 => 1,
184-
1438 => 1,
181+
1440 => 1,
182+
1441 => 1,
183+
1442 => 1,
184+
1443 => 1,
185185
];
186186

187187
}//end getErrorList()

0 commit comments

Comments
 (0)