Skip to content

Commit b18395e

Browse files
committed
Fix false-positive: Method never returns XX so it can be removed from the return type
1 parent bd10157 commit b18395e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRule.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public function processNode(Node $node, Scope $scope): array
6464

6565
$returnType = TypeCombinator::union(...$returnTypes);
6666

67+
if (
68+
$returnType->isConstantScalarValue()->yes()
69+
&& $functionReturnType->isConstantScalarValue()->yes()
70+
) {
71+
return [];
72+
}
73+
6774
$messages = [];
6875
foreach ($functionReturnType->getTypes() as $type) {
6976
if (!$type->isSuperTypeOf($returnType)->no()) {

src/Rules/TooWideTypehints/TooWideMethodReturnTypehintRule.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public function processNode(Node $node, Scope $scope): array
8686
}
8787

8888
$returnType = TypeCombinator::union(...$returnTypes);
89+
90+
if (
91+
$returnType->isConstantScalarValue()->yes()
92+
&& $methodReturnType->isConstantScalarValue()->yes()
93+
) {
94+
return [];
95+
}
96+
8997
if (
9098
!$isFirstDeclaration
9199
&& !$method->isPrivate()

0 commit comments

Comments
 (0)