@@ -61,10 +61,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61
61
{
62
62
$ tokens = $ phpcsFile ->getTokens ();
63
63
64
- $ numTokens = (count ($ tokens ) - 2 );
65
- $ currentLine = 0 ;
66
- $ indentLevel = 0 ;
67
- $ nested = false ;
64
+ $ numTokens = (count ($ tokens ) - 2 );
65
+ $ currentLine = 0 ;
66
+ $ indentLevel = 0 ;
67
+ $ nestingLevel = 0 ;
68
68
for ($ i = 1 ; $ i < $ numTokens ; $ i ++) {
69
69
if ($ tokens [$ i ]['code ' ] === T_COMMENT ) {
70
70
// Dont check the indent of comments.
@@ -74,12 +74,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
74
74
if ($ tokens [$ i ]['code ' ] === T_OPEN_CURLY_BRACKET ) {
75
75
$ indentLevel ++;
76
76
77
- // Check for nested style definitions as, for example, in @media style rules.
78
- $ found = $ phpcsFile ->findNext (T_OPEN_CURLY_BRACKET , ($ i + 1 ), $ tokens [$ i ]['bracket_closer ' ]);
79
- if ($ found === false ) {
80
- $ nested = false ;
81
- } else {
82
- $ nested = true ;
77
+ // Check for nested class definitions.
78
+ $ found = $ phpcsFile ->findNext (
79
+ T_OPEN_CURLY_BRACKET ,
80
+ ($ i + 1 ),
81
+ $ tokens [$ i ]['bracket_closer ' ]
82
+ );
83
+ if ($ found !== false ) {
84
+ $ nestingLevel = $ indentLevel ;
83
85
}
84
86
} else if ($ tokens [($ i + 1 )]['code ' ] === T_CLOSE_CURLY_BRACKET ) {
85
87
$ indentLevel --;
@@ -98,8 +100,9 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
98
100
}
99
101
100
102
$ expectedIndent = ($ indentLevel * 4 );
101
- if ($ expectedIndent > 0 && strpos ($ tokens [$ i ]['content ' ], $ phpcsFile ->eolChar ) !== false ) {
102
- if ($ nested === false ) {
103
+ if ($ expectedIndent > 0 && strpos ($ tokens [$ i ]['content ' ], $ phpcsFile ->eolChar ) !== false
104
+ ) {
105
+ if ($ nestingLevel !== $ indentLevel ) {
103
106
$ error = 'Blank lines are not allowed in class definitions ' ;
104
107
$ phpcsFile ->addError ($ error , $ i , 'BlankLine ' );
105
108
}
0 commit comments