Skip to content

Commit ed4dbfe

Browse files
committed
Merge branch 'feature/squiz-superfluouswhitespace-allow-for-nested-anon-classes' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 3be20d7 + 89b803e commit ed4dbfe

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/SuperfluousWhitespaceSniff.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ public function process(File $phpcsFile, $stackPtr)
228228
&& $tokens[($stackPtr - 1)]['line'] < $tokens[$stackPtr]['line']
229229
&& $tokens[($stackPtr - 2)]['line'] === $tokens[($stackPtr - 1)]['line']
230230
) {
231+
// Spacing around properties and functions in nested classes has their own rules.
232+
$conditions = $tokens[$stackPtr]['conditions'];
233+
$deepestScope = end($conditions);
234+
if ($deepestScope === T_ANON_CLASS) {
235+
return;
236+
}
237+
231238
// This is an empty line and the line before this one is not
232239
// empty, so this could be the start of a multiple empty
233240
// line block.

src/Standards/Squiz/Tests/WhiteSpace/SuperfluousWhitespaceUnitTest.1.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,23 @@ function myFunction2()
5252

5353
// Уберём из системных свойств все кроме информации об услугах
5454

55+
class Nested_Function {
56+
public function getAnonymousClass() {
57+
return new class() {
58+
59+
60+
static private final function _nested_function() {
61+
echo 'code here';
62+
63+
64+
echo 'code here';
65+
66+
}
67+
68+
69+
};
70+
}
71+
}
72+
5573
?>
5674

src/Standards/Squiz/Tests/WhiteSpace/SuperfluousWhitespaceUnitTest.1.inc.fixed

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,21 @@ function myFunction2()
4848

4949
// Уберём из системных свойств все кроме информации об услугах
5050

51+
class Nested_Function {
52+
public function getAnonymousClass() {
53+
return new class() {
54+
55+
56+
static private final function _nested_function() {
57+
echo 'code here';
58+
59+
echo 'code here';
60+
61+
}
62+
63+
64+
};
65+
}
66+
}
67+
5168
?>

src/Standards/Squiz/Tests/WhiteSpace/SuperfluousWhitespaceUnitTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public function getErrorList($testFile='SuperfluousWhitespaceUnitTest.inc')
4040
28 => 1,
4141
33 => 1,
4242
49 => 1,
43-
55 => 1,
43+
62 => 1,
44+
65 => 1,
45+
73 => 1,
4446
];
4547
break;
4648
case 'SuperfluousWhitespaceUnitTest.2.inc':

0 commit comments

Comments
 (0)