Skip to content

Commit 0788491

Browse files
phpstan-botclaude
andcommitted
Add test cases for @throws void constructors on interfaces and abstract classes
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 88be42e commit 0788491

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

tests/PHPStan/Rules/Exceptions/CatchWithUnthrownExceptionRuleTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,15 @@ public function testBug6574(): void
799799
$this->analyse([__DIR__ . '/data/bug-6574.php'], [
800800
[
801801
'Dead catch - Exception is never thrown in the try block.',
802-
83,
802+
97,
803+
],
804+
[
805+
'Dead catch - Exception is never thrown in the try block.',
806+
106,
807+
],
808+
[
809+
'Dead catch - Exception is never thrown in the try block.',
810+
115,
803811
],
804812
]);
805813
}

tests/PHPStan/Rules/Exceptions/data/bug-6574.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ final class FinalClass
3030
{
3131
}
3232

33+
interface ThrowsVoidInterface
34+
{
35+
/** @throws void */
36+
public function __construct();
37+
}
38+
39+
abstract class AbstractThrowsVoid
40+
{
41+
/** @throws void */
42+
public function __construct()
43+
{
44+
}
45+
}
46+
3347
/** @param class-string<FooInterface> $class */
3448
function interfaceWithoutConstructor(string $class): void
3549
{
@@ -83,3 +97,21 @@ function finalClassWithoutConstructor(string $class): void
8397
} catch (\Exception $e) { // dead catch - final class with no constructor
8498
}
8599
}
100+
101+
/** @param class-string<ThrowsVoidInterface> $class */
102+
function interfaceWithThrowsVoidConstructor(string $class): void
103+
{
104+
try {
105+
new $class();
106+
} catch (\Exception $e) { // dead catch - constructor is @throws void
107+
}
108+
}
109+
110+
/** @param class-string<AbstractThrowsVoid> $class */
111+
function abstractClassWithThrowsVoidConstructor(string $class): void
112+
{
113+
try {
114+
new $class();
115+
} catch (\Exception $e) { // dead catch - constructor is @throws void
116+
}
117+
}

0 commit comments

Comments
 (0)