Skip to content

Commit c7e9230

Browse files
committed
still check callables parameter/return type, even if we skip the array
1 parent 6bb6930 commit c7e9230

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

src/Rules/MissingTypehintCheck.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,22 @@ public function getIterableTypesWithMissingValueTypehint(Type $type): array
7373
if ($type instanceof AccessoryType) {
7474
return $type;
7575
}
76-
if ($type->isCallable()->yes() && $type->isArray()->yes()) {
77-
return $type;
76+
if (
77+
$type instanceof IntersectionType
78+
&& $type->isCallable()->yes()
79+
&& $type->isArray()->yes()
80+
) {
81+
$nonArrayInner = [];
82+
foreach ($type->getTypes() as $innerType) {
83+
if ($innerType->isArray()->yes()) {
84+
continue;
85+
}
86+
$nonArrayInner[] = $innerType;
87+
}
88+
if (count($nonArrayInner) === 1) {
89+
return $traverse($nonArrayInner[0]);
90+
}
91+
return $traverse(new IntersectionType($nonArrayInner));
7892
}
7993
if ($type instanceof ConditionalType || $type instanceof ConditionalTypeForParameter) {
8094
$iterablesWithMissingValueTypehint = array_merge(

tests/PHPStan/Rules/Methods/MissingMethodParameterTypehintRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,16 @@ public function testBug14549(): void
155155
'Method Bug14549\Foo::doFoo() has parameter $task with no signature specified for callable.',
156156
12,
157157
],
158+
[
159+
'Method Bug14549\Foo::doIntersection() has parameter $array with no value type specified in iterable type array.',
160+
46,
161+
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
162+
],
163+
[
164+
'Method Bug14549\Foo::doIntersection() has parameter $array with no value type specified in iterable type array.',
165+
46,
166+
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
167+
],
158168
]);
159169
}
160170

tests/PHPStan/Rules/Methods/data/bug-14549.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public function doBar(array $list): void
3939
}
4040
}
4141
}
42+
43+
/**
44+
* @param (array&callable(array): array) $array
45+
*/
46+
public function doIntersection($array): void
47+
{
48+
}
49+
4250
}
4351

4452

0 commit comments

Comments
 (0)