Skip to content

Commit c8f2e2b

Browse files
committed
PropertyTypeHintSniff: Fixed false positive
1 parent 16f856e commit c8f2e2b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/PropertyTypeHintSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,16 @@ private function checkTypeHint(
170170
continue;
171171
}
172172

173+
$isTraversable = TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $propertyPointer, $typeHint), $this->getTraversableTypeHints());
174+
175+
if (!$isTraversable && count($traversableTypeHints) > 0) {
176+
return;
177+
}
178+
173179
if (
174180
!$innerTypeNode instanceof ArrayTypeNode
175181
&& !$innerTypeNode instanceof ArrayShapeNode
176-
&& TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $propertyPointer, $typeHint), $this->getTraversableTypeHints())
182+
&& $isTraversable
177183
) {
178184
$traversableTypeHints[] = $typeHint;
179185
}

tests/Sniffs/TypeHints/data/propertyTypeHintEnabledNativeNoErrors.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,9 @@ class Whatever
121121
/** @var mixed[]|array|Traversable */
122122
public $moreTraverasableTypes;
123123

124+
/**
125+
* @var mixed[]|array|SomethingThatLooksAsArray
126+
*/
127+
public $moreDifferentTypes;
128+
124129
}

0 commit comments

Comments
 (0)