File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
src/Rules/TooWideTypehints
tests/PHPStan/Rules/TooWideTypehints/data Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments