@@ -165,6 +165,24 @@ public function processNode(Node $node, Scope $scope): array
165
165
return $ this ->processNode ($ node ->getOriginalStatement (), $ scope );
166
166
}
167
167
168
+ if ($ node instanceof Node \FunctionLike) {
169
+ return $ this ->processFunction ($ node , $ scope );
170
+ }
171
+
172
+ $ method = $ scope ->getFunction ();
173
+ $ isMethodWhitelisted = $ method instanceof MethodReflection && $ this ->isWhitelistedMethod ($ method );
174
+ if ($ node instanceof FunctionEnd) {
175
+ if ($ isMethodWhitelisted && $ method instanceof MethodReflection) {
176
+ return $ this ->processWhitelistedMethod ($ method );
177
+ }
178
+
179
+ return $ this ->processFunctionEnd ($ scope );
180
+ }
181
+
182
+ if ($ isMethodWhitelisted ) {
183
+ return [];
184
+ }
185
+
168
186
if ($ node instanceof TryCatch) {
169
187
return $ this ->processTryCatch ($ node );
170
188
}
@@ -193,20 +211,6 @@ public function processNode(Node $node, Scope $scope): array
193
211
return $ this ->processExprTraversing ($ node ->expr , $ scope , true );
194
212
}
195
213
196
- if ($ node instanceof Node \FunctionLike) {
197
- return $ this ->processFunction ($ node , $ scope );
198
- }
199
-
200
- if ($ node instanceof FunctionEnd) {
201
- $ method = $ scope ->getFunction ();
202
-
203
- if ($ method instanceof MethodReflection && $ this ->isWhitelistedMethod ($ method )) {
204
- return $ this ->processWhitelistedMethod ($ method );
205
- }
206
-
207
- return $ this ->processFunctionEnd ($ scope );
208
- }
209
-
210
214
if ($ node instanceof Catch_) {
211
215
return $ this ->processCatch ($ node );
212
216
}
@@ -305,22 +309,8 @@ private function processTryCatchTryEnd(): array
305
309
private function processThrow (Throw_ $ node , Scope $ scope ): array
306
310
{
307
311
$ exceptionType = $ scope ->getType ($ node ->expr );
308
- $ exceptionClassNames = TypeUtils::getDirectClassNames ($ exceptionType );
309
- $ exceptionClassNames = $ this ->throwsScope ->filterExceptionsByUncaught ($ exceptionClassNames );
310
- $ exceptionClassNames = $ this ->checkedExceptionService ->filterCheckedExceptions ($ exceptionClassNames );
311
-
312
- $ isInGlobalScope = $ this ->throwsScope ->isInGlobalScope ();
313
- if (!$ this ->reportCheckedThrowsInGlobalScope && $ isInGlobalScope ) {
314
- return [];
315
- }
316
-
317
- return array_map (static function (string $ exceptionClassName ) use ($ isInGlobalScope ): string {
318
- if ($ isInGlobalScope ) {
319
- return sprintf ('Throwing checked exception %s in global scope is prohibited ' , $ exceptionClassName );
320
- }
321
312
322
- return sprintf ('Missing @throws %s annotation ' , $ exceptionClassName );
323
- }, $ exceptionClassNames );
313
+ return $ this ->processThrowsTypes ($ exceptionType );
324
314
}
325
315
326
316
/**
@@ -798,8 +788,17 @@ private function processThrowsTypes(Type $targetThrowType): array
798
788
$ targetExceptionClasses = $ this ->throwsScope ->filterExceptionsByUncaught ($ targetExceptionClasses );
799
789
$ targetExceptionClasses = $ this ->checkedExceptionService ->filterCheckedExceptions ($ targetExceptionClasses );
800
790
801
- return array_map (static function (string $ targetExceptionClass ): string {
802
- return sprintf ('Missing @throws %s annotation ' , $ targetExceptionClass );
791
+ $ isInGlobalScope = $ this ->throwsScope ->isInGlobalScope ();
792
+ if (!$ this ->reportCheckedThrowsInGlobalScope && $ isInGlobalScope ) {
793
+ return [];
794
+ }
795
+
796
+ return array_map (static function (string $ exceptionClassName ) use ($ isInGlobalScope ): string {
797
+ if ($ isInGlobalScope ) {
798
+ return sprintf ('Throwing checked exception %s in global scope is prohibited ' , $ exceptionClassName );
799
+ }
800
+
801
+ return sprintf ('Missing @throws %s annotation ' , $ exceptionClassName );
803
802
}, $ targetExceptionClasses );
804
803
}
805
804
0 commit comments