Skip to content

Commit 13d6378

Browse files
committed
Do not report too-wide nested bool type in child class
1 parent 0ed3255 commit 13d6378

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,16 @@ private function narrowType(
466466
$usedTypes = [];
467467
foreach ($declaredType->getFiniteTypes() as $innerType) {
468468
if ($innerType->isSuperTypeOf($actualReturnType)->no()) {
469-
continue;
469+
if (!$checkDescendantClass) {
470+
continue;
471+
}
472+
if (
473+
!$actualReturnType->isTrue()->yes()
474+
&& !$actualReturnType->isFalse()->yes()
475+
&& !$actualReturnType->isNull()->yes()
476+
) {
477+
continue;
478+
}
470479
}
471480

472481
$usedTypes[] = $innerType;

tests/PHPStan/Rules/TooWideTypehints/data/nested-too-wide-method-return-type.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,31 @@ public function doFoo(): array
7777
}
7878

7979
}
80+
81+
class ParentClassBool
82+
{
83+
84+
/**
85+
* @return array<array{bool}>
86+
*/
87+
public function doFoo(): array
88+
{
89+
return [];
90+
}
91+
92+
}
93+
94+
class ChildClassTrue extends ParentClassBool
95+
{
96+
97+
/**
98+
* @return array<array{bool}>
99+
*/
100+
public function doFoo(): array
101+
{
102+
return [
103+
[true],
104+
];
105+
}
106+
107+
}

0 commit comments

Comments
 (0)