Skip to content

Commit abeda2d

Browse files
committed
Constructor does not have to respect parent @throws annotations
1 parent 8106608 commit abeda2d

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/Rules/ThrowsPhpDocInheritanceRule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public function processNode(Node $node, Scope $scope): array
6868
return [];
6969
}
7070

71+
$methodName = $node->name->toString();
72+
if ($methodName === '__construct') {
73+
return [];
74+
}
75+
7176
$traitReflection = $scope->getTraitReflection();
7277
$traitName = $traitReflection !== null ? $traitReflection->getName() : null;
7378

@@ -84,8 +89,6 @@ public function processNode(Node $node, Scope $scope): array
8489
}
8590

8691
$throwType = $throwsTag->getType();
87-
$methodName = $node->name->toString();
88-
8992
$parentClasses = $classReflection->getInterfaces();
9093
$parentClass = $classReflection->getParentClass();
9194
if ($parentClass !== false) {

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public function correct(): void;
2020
*/
2121
public function wrong(): void;
2222

23+
public function __construct();
24+
2325
public function parentWithoutThrows(): void;
2426

2527
}
@@ -37,6 +39,11 @@ public function correct(): void;
3739
*/
3840
public function wrong(): void; // error: PHPDoc tag @throws with type Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\BaseException is not compatible with parent Pepakriz\PHPStanExceptionRules\Rules\Data\InheritanceInterfaces\ConcreteException
3941

42+
/**
43+
* @throws BaseException
44+
*/
45+
public function __construct();
46+
4047
/**
4148
* @throws BaseException
4249
*/
@@ -63,6 +70,14 @@ public function wrong(): void // error: PHPDoc tag @throws with type Pepakriz\PH
6370

6471
}
6572

73+
/**
74+
* @throws BaseException
75+
*/
76+
public function __construct()
77+
{
78+
79+
}
80+
6681
/**
6782
* @throws BaseException
6883
*/

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public function wrong(): void
3636

3737
}
3838

39+
public function __construct()
40+
{
41+
42+
}
43+
3944
public function parentWithoutThrows(): void
4045
{
4146

@@ -79,6 +84,14 @@ public function wrong(): void // error: PHPDoc tag @throws with type Pepakriz\PH
7984

8085
}
8186

87+
/**
88+
* @throws BaseException
89+
*/
90+
public function __construct()
91+
{
92+
93+
}
94+
8295
/**
8396
* @throws BaseException
8497
*/

0 commit comments

Comments
 (0)