Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Report missing iterable value type for array part of array&callable…
… intersections in `MissingTypehintCheck`

- In `MissingTypehintCheck::getIterableTypesWithMissingValueTypehint()`, the
  special-case block for `array&callable` intersection types was skipping the
  array part entirely, never checking it for missing value types
- Added a check for the array inner type's iterable value type before skipping
  it, so `callable-array`, `callable&array`, and `array&callable(...)` now
  correctly report `missingType.iterableValue` when the array has no value type
- Updated test expectations for `doIntersection()` (gains a third error for the
  outer array) and `doFoo()` (now reports missing iterable value type)
- Added new test case `doBaz()` with explicit `callable&array` parameter
- All consumers of `MissingTypehintCheck` (method/function parameters, return
  types, properties, constants, @var tags, @phpstan-assert) are automatically
  fixed since they share the same check
  • Loading branch information
VincentLanglet committed May 5, 2026
commit d4dcc5cbc14ae57a040885bc3aa053cb021537df
4 changes: 4 additions & 0 deletions src/Rules/MissingTypehintCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function getIterableTypesWithMissingValueTypehint(Type $type): array
$nonArrayInner = [];
foreach ($type->getTypes() as $innerType) {
if ($innerType->isArray()->yes()) {
$iterableValue = $innerType->getIterableValueType();
if ($iterableValue instanceof MixedType && !$iterableValue->isExplicitMixed()) {
$iterablesWithMissingValueTypehint[] = $innerType;
}
continue;
}
$nonArrayInner[] = $innerType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ public function testBug7662(): void
public function testBug14549(): void
{
$this->analyse([__DIR__ . '/data/bug-14549.php'], [
[
'Method Bug14549\Foo::doFoo() has parameter $task with no value type specified in iterable type array.',
12,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'Method Bug14549\Foo::doFoo() has parameter $task with no signature specified for callable.',
12,
Expand All @@ -165,6 +170,20 @@ public function testBug14549(): void
46,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'Method Bug14549\Foo::doIntersection() has parameter $array with no value type specified in iterable type array.',
46,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'Method Bug14549\Foo::doBaz() has parameter $task with no value type specified in iterable type array.',
53,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'Method Bug14549\Foo::doBaz() has parameter $task with no signature specified for callable.',
53,
],
]);
}

Expand Down
7 changes: 7 additions & 0 deletions tests/PHPStan/Rules/Methods/data/bug-14549.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ public function doIntersection($array): void
{
}

/**
* @param callable&array $task
*/
public function doBaz(array $task): void
{
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the doBaz() method from bug-14549.php and its corresponding test expectation in MissingMethodParameterTypehintRuleTest.php. All 11,971 tests pass and make phpstan reports no errors.


}