Skip to content

Commit da3790e

Browse files
committed
Fix overriding throw point with void
1 parent dca48f3 commit da3790e

File tree

4 files changed

+70
-1
lines changed

4 files changed

+70
-1
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,12 @@ private function getOverridingThrowPoints(Node\Stmt $statement, MutatingScope $s
14421442

14431443
$throwsTag = $resolvedPhpDoc->getThrowsTag();
14441444
if ($throwsTag !== null) {
1445-
return [ThrowPoint::createExplicit($scope, $throwsTag->getType(), $statement, false)];
1445+
$throwsType = $throwsTag->getType();
1446+
if ($throwsType instanceof VoidType) {
1447+
return [];
1448+
}
1449+
1450+
return [ThrowPoint::createExplicit($scope, $throwsType, $statement, false)];
14461451
}
14471452
}
14481453

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Rules\Exceptions;
4+
5+
use PHPStan\Testing\RuleTestCase;
6+
7+
/**
8+
* @extends RuleTestCase<MissingCheckedExceptionInMethodThrowsRule>
9+
*/
10+
class Bug5364Test extends RuleTestCase
11+
{
12+
13+
protected function getRule(): \PHPStan\Rules\Rule
14+
{
15+
return new MissingCheckedExceptionInMethodThrowsRule(
16+
new MissingCheckedExceptionInThrowsCheck(new DefaultExceptionTypeResolver(
17+
$this->createReflectionProvider(),
18+
[],
19+
[],
20+
[],
21+
[]
22+
))
23+
);
24+
}
25+
26+
public function testRule(): void
27+
{
28+
$this->analyse([__DIR__ . '/data/bug-5364.php'], []);
29+
}
30+
31+
public static function getAdditionalConfigFiles(): array
32+
{
33+
return [
34+
__DIR__ . '/bug-5364.neon',
35+
];
36+
}
37+
38+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
implicitThrows: false
3+
exceptions:
4+
check:
5+
missingCheckedExceptionInThrows: true
6+
tooWideThrowType: true
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Bug5364;
4+
5+
class Foo
6+
{
7+
8+
/**
9+
* @throws \Exception
10+
*/
11+
function test(): void {
12+
throw new \Exception();
13+
}
14+
15+
function call_test(): void {
16+
/** @throws void */
17+
$this->test();
18+
}
19+
20+
}

0 commit comments

Comments
 (0)