Skip to content

Commit 7e8629b

Browse files
authored
Check unused @throws annotations on functions (#55)
Cherry-picked from #54
1 parent 602f44b commit 7e8629b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Rules/ThrowsPhpDocRule.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,13 @@ private function processFunctionEnd(Scope $scope): array
370370
$usedThrowsAnnotations = $this->throwsScope->exitFromThrowsAnnotationBlock();
371371
$usedThrowsAnnotations = $this->checkedExceptionService->filterCheckedExceptions($usedThrowsAnnotations);
372372

373-
$classReflection = $scope->getClassReflection();
374373
$methodReflection = $scope->getFunction();
375-
if ($classReflection === null || $methodReflection === null) {
374+
if ($methodReflection === null) {
376375
return [];
377376
}
378377

379-
if ($classReflection->isInterface() || $classReflection->isAbstract()) {
378+
$classReflection = $scope->getClassReflection();
379+
if ($classReflection !== null && ($classReflection->isInterface() || $classReflection->isAbstract())) {
380380
return [];
381381
}
382382

tests/src/Rules/data/unused-throws.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
class FooException extends RuntimeException {}
99
class BarException extends RuntimeException {}
1010

11+
/**
12+
* @throws RuntimeException
13+
*/
14+
function foo() { // error: Unused @throws RuntimeException annotation
15+
16+
}
17+
1118
class UnusedThrows
1219
{
1320

0 commit comments

Comments
 (0)