@@ -82,12 +82,12 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
82
82
// Is this a magic method. i.e., is prefixed with "__" ?
83
83
if (preg_match ('|^__[^_]| ' , $ methodName ) !== 0 ) {
84
84
$ magicPart = strtolower (substr ($ methodName , 2 ));
85
- if (isset ($ this ->magicMethods [$ magicPart ]) === false ) {
86
- $ error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore ' ;
87
- $ phpcsFile ->addError ($ error , $ stackPtr , 'MethodDoubleUnderscore ' , $ errorData );
85
+ if (isset ($ this ->magicMethods [$ magicPart ]) === true ) {
86
+ return ;
88
87
}
89
88
90
- return ;
89
+ $ error = 'Method name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore ' ;
90
+ $ phpcsFile ->addError ($ error , $ stackPtr , 'MethodDoubleUnderscore ' , $ errorData );
91
91
}
92
92
93
93
// PHP4 constructors are allowed to break our rules.
@@ -116,7 +116,6 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
116
116
$ error = 'Private method name "%s" must be prefixed with an underscore ' ;
117
117
$ phpcsFile ->addError ($ error , $ stackPtr , 'PrivateNoUnderscore ' , $ errorData );
118
118
$ phpcsFile ->recordMetric ($ stackPtr , 'Private method prefixed with underscore ' , 'no ' );
119
- return ;
120
119
} else {
121
120
$ phpcsFile ->recordMetric ($ stackPtr , 'Private method prefixed with underscore ' , 'yes ' );
122
121
}
@@ -130,20 +129,11 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
130
129
$ errorData [0 ],
131
130
];
132
131
$ phpcsFile ->addError ($ error , $ stackPtr , 'PublicUnderscore ' , $ data );
133
- return ;
134
132
}
135
133
136
- // If the scope was specified on the method, then the method must be
137
- // camel caps and an underscore should be checked for. If it wasn't
138
- // specified, treat it like a public method and remove the underscore
139
- // prefix if there is one because we cant determine if it is private or
140
- // public.
141
- $ testMethodName = $ methodName ;
142
- if ($ scopeSpecified === false && $ methodName {0 } === '_ ' ) {
143
- $ testMethodName = substr ($ methodName , 1 );
144
- }
134
+ $ testMethodName = ltrim ($ methodName , '_ ' );
145
135
146
- if (Common::isCamelCaps ($ testMethodName , false , $ isPublic , false ) === false ) {
136
+ if (Common::isCamelCaps ($ testMethodName , false , true , false ) === false ) {
147
137
if ($ scopeSpecified === true ) {
148
138
$ error = '%s method name "%s" is not in camel caps format ' ;
149
139
$ data = [
@@ -155,8 +145,6 @@ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScop
155
145
$ error = 'Method name "%s" is not in camel caps format ' ;
156
146
$ phpcsFile ->addError ($ error , $ stackPtr , 'NotCamelCaps ' , $ errorData );
157
147
}
158
-
159
- return ;
160
148
}
161
149
162
150
}//end processTokenWithinScope()
@@ -189,12 +177,12 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
189
177
// Is this a magic function. i.e., it is prefixed with "__".
190
178
if (preg_match ('|^__[^_]| ' , $ functionName ) !== 0 ) {
191
179
$ magicPart = strtolower (substr ($ functionName , 2 ));
192
- if (isset ($ this ->magicFunctions [$ magicPart ]) === false ) {
193
- $ error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore ' ;
194
- $ phpcsFile ->addError ($ error , $ stackPtr , 'FunctionDoubleUnderscore ' , $ errorData );
180
+ if (isset ($ this ->magicFunctions [$ magicPart ]) === true ) {
181
+ return ;
195
182
}
196
183
197
- return ;
184
+ $ error = 'Function name "%s" is invalid; only PHP magic methods should be prefixed with a double underscore ' ;
185
+ $ phpcsFile ->addError ($ error , $ stackPtr , 'FunctionDoubleUnderscore ' , $ errorData );
198
186
}
199
187
200
188
// Function names can be in two parts; the package name and
@@ -216,13 +204,11 @@ protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
216
204
if ($ functionName {0 } === '_ ' ) {
217
205
$ error = 'Function name "%s" is invalid; only private methods should be prefixed with an underscore ' ;
218
206
$ phpcsFile ->addError ($ error , $ stackPtr , 'FunctionUnderscore ' , $ errorData );
219
- return ;
220
207
}
221
208
222
209
if ($ functionName {0 } !== strtoupper ($ functionName {0 })) {
223
210
$ error = 'Function name "%s" is prefixed with a package name but does not begin with a capital letter ' ;
224
211
$ phpcsFile ->addError ($ error , $ stackPtr , 'FunctionNoCapital ' , $ errorData );
225
- return ;
226
212
}
227
213
}
228
214
0 commit comments