Skip to content

Commit 02dfed0

Browse files
Handle throws void (#123)
1 parent 043cea2 commit 02dfed0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Rules/ThrowsPhpDocInheritanceRule.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function processNode(Node $node, Scope $scope): array
134134
$parentThrowType = $methodReflection->getThrowType();
135135
}
136136

137-
if ($parentThrowType === null) {
137+
if ($parentThrowType === null || $parentThrowType instanceof VoidType) {
138138
$messages[] = sprintf(
139139
'PHPDoc tag @throws with type %s is not compatible with parent',
140140
$throwType->describe(VerbosityLevel::typeOnly())

tests/src/Rules/data/throws-inheritance-interfaces.php

+18
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public function __construct();
2424

2525
public function parentWithoutThrows(): void;
2626

27+
/**
28+
* @throws void
29+
*/
30+
public function parentWithThrowsVoid(): void;
31+
2732
}
2833

2934
interface ThrowsAnnotations extends BaseThrowsAnnotations
@@ -49,6 +54,11 @@ public function __construct();
4954
*/
5055
public function parentWithoutThrows(): void; // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent
5156

57+
/**
58+
* @throws BaseException
59+
*/
60+
public function parentWithThrowsVoid(): void; // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent
61+
5262
}
5363

5464
class Implementation implements BaseThrowsAnnotations
@@ -86,4 +96,12 @@ public function parentWithoutThrows(): void // error: PHPDoc tag @throws with ty
8696

8797
}
8898

99+
/**
100+
* @throws BaseException
101+
*/
102+
public function parentWithThrowsVoid(): void // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent
103+
{
104+
105+
}
106+
89107
}

0 commit comments

Comments
 (0)