26
26
* @SuppressWarnings checkUnusedPrivateFunctions functionMaxParameters
27
27
*/
28
28
class PHPCheckstyle {
29
+
29
30
// The class used to export the result
30
31
public $ _reporter ;
31
32
@@ -78,13 +79,15 @@ class PHPCheckstyle {
78
79
".svn " , // SVN directory
79
80
".git* "
80
81
);
82
+
81
83
// Accounts for .git, .gitignore .gitmodules etc
82
84
83
85
//
84
86
// variables used while processing control structure
85
87
//
86
88
// Left parenthesis opened in control statement or function statement
87
89
private $ _csLeftParenthesis = 0 ;
90
+
88
91
// Left parenthesis opened in function call
89
92
private $ _fcLeftParenthesis = 0 ;
90
93
@@ -93,8 +96,10 @@ class PHPCheckstyle {
93
96
private $ token = false ;
94
97
95
98
private $ lineNumber = 0 ;
99
+
96
100
// Store the current line number
97
101
private $ _isLineStart = true ;
102
+
98
103
// Start of a line (just after a return)
99
104
100
105
// Indicate if we are in a control statement declaration (for, if, while, ...)
@@ -108,54 +113,78 @@ class PHPCheckstyle {
108
113
private $ _beforeArrayDeclaration = false ;
109
114
110
115
private $ _inClassStatement = false ;
116
+
111
117
// We are in a class statement (declaration)
112
118
private $ _inInterfaceStatement = false ;
119
+
113
120
// We are in an interface statement (declaration)
114
121
private $ _inFunctionStatement = false ;
122
+
115
123
// We are in a function statement (declaration)
116
124
private $ _inFuncCall = false ;
125
+
117
126
// We are in a function call
118
127
private $ _inFunction = false ;
128
+
119
129
// We are inside a function
120
130
private $ _inClass = false ;
131
+
121
132
// We are inside a class
122
133
private $ _inInterface = false ;
134
+
123
135
// We are inside an interface
124
136
private $ _privateFunctions = array ();
137
+
125
138
// The list of private functions in the class
126
139
private $ _privateFunctionsStartLines = array ();
127
140
128
141
private $ _functionParameters = array ();
142
+
129
143
// The list of function parameters
130
144
private $ _currentFuncCall = [];
145
+
131
146
// The stack of function calls
132
147
private $ _usedFunctions = array ();
148
+
133
149
// The list of functions that are used in the class
134
150
private $ _variables = array ();
151
+
135
152
// The variables used. Array of VariableInfo.
136
153
private $ _nbFunctionParameters = 0 ;
154
+
137
155
// Count the number of parameters of the current function
138
156
private $ _justAfterFuncStmt = false ;
157
+
139
158
// We are just after a control statement (last } )
140
159
private $ _justAfterControlStmt = false ;
160
+
141
161
// We are just after a function statement (last } )
142
162
private $ _functionStartLine = 0 ;
163
+
143
164
// Starting line of the current function
144
165
private $ _switchStartLine = 0 ;
166
+
145
167
// Starting line of the current switch statement
146
168
private $ _functionReturns = false ;
169
+
147
170
// Does the function return a value ?
148
171
private $ _functionThrows = false ;
172
+
149
173
// Does the function throw an exception ?
150
174
private $ _functionLevel = 0 ;
175
+
151
176
// Level of Nesting of the function
152
177
private $ _functionVisibility = 'PUBLIC ' ;
178
+
153
179
// PUBLIC, PRIVATE or PROTECTED or ANONYMOUS
154
180
private $ _functionStatic = false ;
181
+
155
182
// Is the function static
156
183
private $ _classLevel = 0 ;
184
+
157
185
// Level of Nesting of the class
158
186
private $ _interfaceLevel = 0 ;
187
+
159
188
// Level of Nesting of the interface
160
189
private $ _constantDef = false ;
161
190
@@ -171,28 +200,33 @@ class PHPCheckstyle {
171
200
172
201
private $ _currentFunctionName = null ;
173
202
174
-
175
203
// Number of @params in the docblock of a function
176
204
private $ _docblocNbParams = 0 ;
205
+
177
206
// Number of @return in the docblock of a function
178
207
private $ _docblocNbReturns = 0 ;
208
+
179
209
// Number of @throw in the docblock of a function
180
210
private $ _docblocNbThrows = 0 ;
211
+
181
212
// Does the function inherits its doc
182
213
private $ _docblocInheritDoc = false ;
183
214
184
-
185
215
private $ _cyclomaticComplexity = 0 ;
186
216
187
217
private $ _npathComplexity = 0 ;
188
218
189
219
private $ _fileSuppressWarnings = array ();
220
+
190
221
// List of warnings to ignore for this file
191
222
private $ _classSuppressWarnings = array ();
223
+
192
224
// List of warnings to ignore for this class
193
225
private $ _interfaceSuppressWarnings = array ();
226
+
194
227
// List of warnings to ignore for this interface
195
228
private $ _functionSuppressWarnings = array ();
229
+
196
230
// List of warnings to ignore for this function
197
231
198
232
// For MVC frameworks
@@ -1246,7 +1280,6 @@ private function _processSquareBracketOpen($token) {
1246
1280
$ stackitem ->name = 'square_bracket_open ' ;
1247
1281
1248
1282
$ this ->statementStack ->push ($ stackitem );
1249
-
1250
1283
}
1251
1284
}
1252
1285
@@ -1259,8 +1292,7 @@ private function _processSquareBracketOpen($token) {
1259
1292
private function _processSquareBracketClose ($ token ) {
1260
1293
1261
1294
// We are in a array declaration, we unstack
1262
- if ($ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_ARRAY
1263
- && $ this ->statementStack ->getCurrentStackItem ()->name === 'square_bracket_open ' ) {
1295
+ if ($ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_ARRAY && $ this ->statementStack ->getCurrentStackItem ()->name === 'square_bracket_open ' ) {
1264
1296
$ this ->statementStack ->pop ();
1265
1297
}
1266
1298
}
@@ -1346,8 +1378,7 @@ private function _processParenthesisClose($token) {
1346
1378
if ($ this ->statementStack ->getCurrentStackItem ()->openParentheses === 0 ) {
1347
1379
1348
1380
// We are in a array declaration, we unstack
1349
- if ($ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_ARRAY AND
1350
- $ this ->statementStack ->getCurrentStackItem ()->name !== 'square_bracket_open ' ) {
1381
+ if ($ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_ARRAY and $ this ->statementStack ->getCurrentStackItem ()->name !== 'square_bracket_open ' ) {
1351
1382
$ this ->statementStack ->pop ();
1352
1383
}
1353
1384
}
@@ -1464,9 +1495,7 @@ private function _processBracesClose($token) {
1464
1495
if (!is_String ($ currentStackItem )) {
1465
1496
1466
1497
// Test for the end of a switch bloc
1467
- if ($ currentStackItem ->type === StatementItem::TYPE_SWITCH
1468
- || $ currentStackItem ->type === StatementItem::TYPE_DEFAULT
1469
- || $ currentStackItem ->type === StatementItem::TYPE_CASE ) {
1498
+ if ($ currentStackItem ->type === StatementItem::TYPE_SWITCH || $ currentStackItem ->type === StatementItem::TYPE_DEFAULT || $ currentStackItem ->type === StatementItem::TYPE_CASE ) {
1470
1499
$ this ->_processSwitchStop ();
1471
1500
}
1472
1501
@@ -1546,7 +1575,7 @@ private function _checkVariableNaming($text) {
1546
1575
if ($ this ->_inFunctionStatement || $ this ->_inInterfaceStatement ) {
1547
1576
$ this ->_checkScopedVariableNaming ($ text , 'functionParameterNaming ' , 'FUNCTION_PARAMETER_NAMING ' );
1548
1577
} else if ($ this ->_inFunction ) {
1549
- if (in_array ($ text , $ this ->_functionParameters )) {
1578
+ if (array_key_exists ($ text , $ this ->_functionParameters )) {
1550
1579
$ this ->_checkScopedVariableNaming ($ text , 'functionParameterNaming ' , 'FUNCTION_PARAMETER_NAMING ' );
1551
1580
} else {
1552
1581
$ this ->_checkScopedVariableNaming ($ text , 'localVariableNaming ' , 'LOCAL_VARIABLE_NAMING ' );
@@ -2088,10 +2117,7 @@ private function _checkDocBlockParameters() {
2088
2117
// For anonymous functions, we don't check the docblock
2089
2118
$ isAnonymous = $ this ->statementStack ->getCurrentStackItem ()->visibility === 'ANONYMOUS ' ;
2090
2119
2091
- if ($ this ->_isActive ('docBlocks ' )
2092
- && !$ isAnonymous
2093
- && !$ this ->_config ->isException ('docBlocks ' , $ this ->_currentFunctionName )
2094
- && !$ this ->_docblocInheritDoc ) {
2120
+ if ($ this ->_isActive ('docBlocks ' ) && !$ isAnonymous && !$ this ->_config ->isException ('docBlocks ' , $ this ->_currentFunctionName ) && !$ this ->_docblocInheritDoc ) {
2095
2121
2096
2122
// If the function is not private and we check the doc
2097
2123
$ isPrivateExcluded = $ this ->_config ->getTestProperty ('docBlocks ' , 'excludePrivateMembers ' );
@@ -2352,8 +2378,7 @@ private function _processSwitchStart() {
2352
2378
*/
2353
2379
private function _processSwitchStop () {
2354
2380
// If we already are in a "case", we remove it from the stack
2355
- if ($ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_CASE
2356
- || $ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_DEFAULT ) {
2381
+ if ($ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_CASE || $ this ->statementStack ->getCurrentStackItem ()->type === StatementItem::TYPE_DEFAULT ) {
2357
2382
2358
2383
// Test if the previous case had a break
2359
2384
$ this ->_checkSwitchCaseNeedBreak ();
@@ -2588,8 +2613,7 @@ private function _checkEmptyBlock() {
2588
2613
* This function is launched when the current token is T_ENCAPSED_AND_WHITESPACE.
2589
2614
*/
2590
2615
private function _checkEncapsedVariablesInsideString () {
2591
- if ($ this ->_isActive ('encapsedVariablesInsideString ' ) AND (!$ this ->statementStack ->getCurrentStackItem ()->inHeredoc
2592
- OR ($ this ->_inFuncCall AND !$ this ->_config ->isException ('encapsedVariablesInsideString ' , end ($ this ->_currentFuncCall ))))) {
2616
+ if ($ this ->_isActive ('encapsedVariablesInsideString ' ) and (!$ this ->statementStack ->getCurrentStackItem ()->inHeredoc or ($ this ->_inFuncCall and !$ this ->_config ->isException ('encapsedVariablesInsideString ' , end ($ this ->_currentFuncCall ))))) {
2593
2617
$ this ->_writeError ('encapsedVariablesInsideString ' , $ this ->_getMessage ('VARIABLE_INSIDE_STRING ' ));
2594
2618
}
2595
2619
}
@@ -2730,7 +2754,6 @@ private function _checkUnusedFunctionParameters() {
2730
2754
$ this ->_writeError ('checkUnusedFunctionParameters ' , $ msg );
2731
2755
}
2732
2756
}
2733
-
2734
2757
}
2735
2758
}
2736
2759
}
@@ -2979,7 +3002,8 @@ private function _checkWhiteSpaceAfter($text) {
2979
3002
/**
2980
3003
* Check for the absence of a white space after the text.
2981
3004
*
2982
- * @param TokenInfo $token the token
3005
+ * @param TokenInfo $token
3006
+ * the token
2983
3007
*/
2984
3008
private function _checkNoWhiteSpaceAfter ($ token ) {
2985
3009
if ($ this ->_isActive ('noSpaceAfterToken ' )) {
@@ -3113,14 +3137,7 @@ private function _checkIndentationLevel($token) {
3113
3137
}
3114
3138
3115
3139
// don't check empty lines, when we are inside a control statement, when the next token is a object opérator, ...
3116
- if ($ this ->_inControlStatement
3117
- || $ this ->_inFuncCall
3118
- || !isset ($ this ->lineNumber )
3119
- || $ this ->tokenizer ->checkNextToken (T_NEW_LINE )
3120
- || $ this ->tokenizer ->checkNextValidToken (T_PARENTHESIS_CLOSE )
3121
- || $ this ->tokenizer ->checkNextValidToken (T_BOOLEAN_AND )
3122
- || $ this ->tokenizer ->checkNextValidToken (T_BOOLEAN_OR )
3123
- || $ this ->tokenizer ->checkNextValidToken (T_OBJECT_OPERATOR )) {
3140
+ if ($ this ->_inControlStatement || $ this ->_inFuncCall || !isset ($ this ->lineNumber ) || $ this ->tokenizer ->checkNextToken (T_NEW_LINE ) || $ this ->tokenizer ->checkNextValidToken (T_PARENTHESIS_CLOSE ) || $ this ->tokenizer ->checkNextValidToken (T_BOOLEAN_AND ) || $ this ->tokenizer ->checkNextValidToken (T_BOOLEAN_OR ) || $ this ->tokenizer ->checkNextValidToken (T_OBJECT_OPERATOR )) {
3124
3141
return ;
3125
3142
}
3126
3143
0 commit comments