Skip to content

Commit 3c0ae90

Browse files
committed
SlevomatCodingStandard.TypeHints.PropertyTypeHint: Fixed false positive for object shape as item in travesable type
1 parent 5cc68dc commit 3c0ae90

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

SlevomatCodingStandard/Helpers/AnnotationTypeHelper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ public static function containsItemsSpecificationForTraversable(
190190
return true;
191191
}
192192

193-
if ($typeNode instanceof ArrayShapeNode) {
194-
foreach ($typeNode->items as $arrayShapeItemNode) {
193+
if ($typeNode instanceof ArrayShapeNode || $typeNode instanceof ObjectShapeNode) {
194+
foreach ($typeNode->items as $innerItemNode) {
195195
if (!self::containsItemsSpecificationForTraversable(
196-
$arrayShapeItemNode->valueType,
196+
$innerItemNode->valueType,
197197
$phpcsFile,
198198
$pointer,
199199
$traversableTypeHints,

tests/Sniffs/TypeHints/data/propertyTypeHintEnabledNativeNoErrors.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ class Whatever
168168
/** @var \Foo::INTEGER $a */
169169
public $constTypeNode;
170170

171+
/**
172+
* @var WeakMap<static, object{a: int}> https://phpstan.org/writing-php-code/phpdoc-types#object-shapes
173+
*/
174+
public WeakMap $objectShapeInItems;
175+
171176
public function __construct(private $propertyPromotion)
172177
{
173178
}

0 commit comments

Comments
 (0)