Skip to content

Commit 9ffe7b7

Browse files
authored
ForbidCheckedExceptionInYieldingMethodRule: ignore implicit throw points (#114)
1 parent 4567a9c commit 9ffe7b7

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/Rule/ForbidCheckedExceptionInYieldingMethodRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public function processNode(
4444
$errors = [];
4545

4646
foreach ($node->getStatementResult()->getThrowPoints() as $throwPoint) {
47+
if (!$throwPoint->isExplicit()) {
48+
continue;
49+
}
50+
4751
foreach ($throwPoint->getType()->getObjectClassNames() as $exceptionClass) {
4852
if ($this->exceptionTypeResolver->isCheckedException($exceptionClass, $throwPoint->getScope())) {
4953
$errors[] = RuleErrorBuilder::message("Throwing checked exception $exceptionClass in yielding method is denied as it gets thrown upon Generator iteration")

tests/Rule/ForbidCheckedExceptionInYieldingMethodRuleTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace ShipMonk\PHPStan\Rule;
44

5+
use ForbidCheckedExceptionInYieldingMethodRule\CheckedException;
56
use PHPStan\Rules\Exceptions\DefaultExceptionTypeResolver;
67
use PHPStan\Rules\Rule;
78
use ShipMonk\PHPStan\RuleTestCase;
9+
use Throwable;
810

911
/**
1012
* @extends RuleTestCase<ForbidCheckedExceptionInYieldingMethodRule>
@@ -19,7 +21,7 @@ protected function getRule(): Rule
1921
->expects(self::any())
2022
->method('isCheckedException')
2123
->willReturnCallback(static function (string $className): bool {
22-
return $className === 'ForbidCheckedExceptionInYieldingMethodRule\CheckedException';
24+
return $className === CheckedException::class || $className === Throwable::class;
2325
});
2426

2527
return new ForbidCheckedExceptionInYieldingMethodRule($exceptionTypeResolverMock);

0 commit comments

Comments
 (0)