Skip to content

Commit 28a6503

Browse files
committed
ParameterTypeHintSniff: Fixed false positive
1 parent e7c273a commit 28a6503

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/ParameterTypeHintSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,16 @@ private function checkTypeHints(File $phpcsFile, int $functionPointer, array $pa
168168
continue;
169169
}
170170

171+
$isTraversable = TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $typeHint), $this->getTraversableTypeHints());
172+
173+
if (!$isTraversable && count($traversableTypeHints) > 0) {
174+
continue 2;
175+
}
176+
171177
if (
172178
!$typeNode instanceof ArrayTypeNode
173179
&& !$typeNode instanceof ArrayShapeNode
174-
&& TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $typeHint), $this->getTraversableTypeHints())
180+
&& $isTraversable
175181
) {
176182
$traversableTypeHints[] = $typeHint;
177183
}

tests/Sniffs/TypeHints/data/parameterTypeHintNoErrors.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,11 @@ public function moreTraverasableTypes($a)
183183
{
184184
}
185185

186+
/**
187+
* @param mixed[]|array|SomethingThatLooksAsArray $a
188+
*/
189+
public function moreDifferentTypes($a)
190+
{
191+
}
192+
186193
}

0 commit comments

Comments
 (0)