Skip to content

Commit

Permalink
Improve missing iterable value type check in lists
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 3, 2023
1 parent be4ebac commit e705f09
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Rules/MissingTypehintCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ public function getIterableTypesWithMissingValueTypehint(Type $type): array
if ($iterableValue instanceof MixedType && !$iterableValue->isExplicitMixed()) {
$iterablesWithMissingValueTypehint[] = $type;
}
if (!$type instanceof IntersectionType) {
return $traverse($type);
if ($type instanceof IntersectionType && !$type->isList()->yes()) {
return $type;
}

return $type;
}
return $traverse($type);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function testRule(): void
'Property MissingPropertyTypehint\CallableSignature::$cb type has no signature specified for callable.',
93,
],
[
'Property MissingPropertyTypehint\NestedArrayInProperty::$args type has no value type specified in iterable type array.',
103,
MissingTypehintCheck::MISSING_ITERABLE_VALUE_TYPE_TIP,
],
]);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/PHPStan/Rules/Properties/data/missing-property-typehint.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,13 @@ class CallableSignature
private $cb;

}

class NestedArrayInProperty
{

/**
* @var list<array{string, array|self|null, bool}>|null
*/
public $args;

}

0 comments on commit e705f09

Please sign in to comment.