@@ -85,6 +85,12 @@ public function process(File $phpcsFile, $stackPtr)
85
85
&& ($ tokens [($ nextCase + 1 )]['code ' ] !== T_WHITESPACE
86
86
|| $ tokens [($ nextCase + 1 )]['content ' ] !== ' ' )
87
87
) {
88
+ if ($ tokens [($ nextCase + 1 )]['code ' ] === T_WHITESPACE ) {
89
+ $ phpcsFile ->recordMetric ($ nextCase , 'Spaces following the "case" keyword ' , $ tokens [($ nextCase + 1 )]['length ' ]);
90
+ } else {
91
+ $ phpcsFile ->recordMetric ($ nextCase , 'Spaces following the "case" keyword ' , 'none ' );
92
+ }
93
+
88
94
$ error = 'CASE keyword must be followed by a single space ' ;
89
95
$ fix = $ phpcsFile ->addFixableError ($ error , $ nextCase , 'SpacingAfterCase ' );
90
96
if ($ fix === true ) {
@@ -94,17 +100,24 @@ public function process(File $phpcsFile, $stackPtr)
94
100
$ phpcsFile ->fixer ->replaceToken (($ nextCase + 1 ), ' ' );
95
101
}
96
102
}
103
+ } else if ($ type === 'case ' ) {
104
+ $ phpcsFile ->recordMetric ($ nextCase , 'Spaces following the "case" keyword ' , 1 );
97
105
}
98
106
99
107
$ opener = $ tokens [$ nextCase ]['scope_opener ' ];
100
108
$ nextCloser = $ tokens [$ nextCase ]['scope_closer ' ];
101
109
if ($ tokens [$ opener ]['code ' ] === T_COLON ) {
110
+ $ phpcsFile ->recordMetric ($ opener , 'Default/case statement followed by colon ' , 'yes ' );
111
+
102
112
if ($ tokens [($ opener - 1 )]['code ' ] === T_WHITESPACE ) {
113
+ $ phpcsFile ->recordMetric ($ opener , 'Spaces before colon after case/default keyword ' , $ tokens [($ opener - 1 )]['length ' ]);
103
114
$ error = 'There must be no space before the colon in a ' .strtoupper ($ type ).' statement ' ;
104
115
$ fix = $ phpcsFile ->addFixableError ($ error , $ nextCase , 'SpaceBeforeColon ' .strtoupper ($ type ));
105
116
if ($ fix === true ) {
106
117
$ phpcsFile ->fixer ->replaceToken (($ opener - 1 ), '' );
107
118
}
119
+ } else {
120
+ $ phpcsFile ->recordMetric ($ opener , 'Spaces before colon after case/default keyword ' , 0 );
108
121
}
109
122
110
123
for ($ next = ($ opener + 1 ); $ next < $ nextCloser ; $ next ++) {
@@ -116,6 +129,8 @@ public function process(File $phpcsFile, $stackPtr)
116
129
}
117
130
}
118
131
132
+ $ phpcsFile ->recordMetric ($ opener , 'Blank lines at start of case/default body ' , ($ tokens [$ next ]['line ' ] - ($ tokens [$ opener ]['line ' ] + 1 )));
133
+
119
134
if ($ tokens [$ next ]['line ' ] !== ($ tokens [$ opener ]['line ' ] + 1 )) {
120
135
$ error = 'The ' .strtoupper ($ type ).' body must start on the line following the statement ' ;
121
136
$ fix = $ phpcsFile ->addFixableError ($ error , $ nextCase , 'BodyOnNextLine ' .strtoupper ($ type ));
@@ -158,6 +173,7 @@ public function process(File $phpcsFile, $stackPtr)
158
173
} else {
159
174
$ diff = ($ tokens [$ nextCase ]['column ' ] + $ this ->indent - $ tokens [$ nextCloser ]['column ' ]);
160
175
if ($ diff !== 0 ) {
176
+ $ phpcsFile ->recordMetric ($ nextCloser , 'Terminating statement aligned with body of case ' , 'no ' );
161
177
$ error = 'Terminating statement must be indented to the same level as the CASE body ' ;
162
178
$ fix = $ phpcsFile ->addFixableError ($ error , $ nextCloser , 'BreakIndent ' );
163
179
if ($ fix === true ) {
@@ -167,10 +183,13 @@ public function process(File $phpcsFile, $stackPtr)
167
183
$ phpcsFile ->fixer ->substrToken (($ nextCloser - 1 ), 0 , $ diff );
168
184
}
169
185
}
186
+ } else {
187
+ $ phpcsFile ->recordMetric ($ nextCloser , 'Terminating statement aligned with body of case ' , 'yes ' );
170
188
}
171
189
}//end if
172
190
}//end if
173
191
} else {
192
+ $ phpcsFile ->recordMetric ($ opener , 'Default/case statement followed by colon ' , 'no ' );
174
193
$ error = strtoupper ($ type ).' statements must be defined using a colon ' ;
175
194
$ phpcsFile ->addError ($ error , $ nextCase , 'WrongOpener ' .$ type );
176
195
}//end if
@@ -193,11 +212,16 @@ public function process(File $phpcsFile, $stackPtr)
193
212
if (isset (Tokens::$ commentTokens [$ tokens [$ prevCode ]['code ' ]]) === false
194
213
&& $ this ->findNestedTerminator ($ phpcsFile , ($ opener + 1 ), $ nextCode ) === false
195
214
) {
215
+ $ phpcsFile ->recordMetric ($ nextCode , 'Case falls through to next ' , 'yes, without comment ' );
196
216
$ error = 'There must be a comment when fall-through is intentional in a non-empty case body ' ;
197
217
$ phpcsFile ->addError ($ error , $ nextCase , 'TerminatingComment ' );
218
+ } else {
219
+ $ phpcsFile ->recordMetric ($ nextCode , 'Case falls through to next ' , 'yes, with comment ' );
198
220
}
221
+ } else {
222
+ $ phpcsFile ->recordMetric ($ nextCode , 'Case falls through to next ' , 'no ' );
199
223
}
200
- }
224
+ }//end if
201
225
}//end while
202
226
203
227
}//end process()
0 commit comments