Skip to content

Commit 16f856e

Browse files
committed
ReturnTypeHintSniff: Fixed false positive
1 parent 28a6503 commit 16f856e

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/ReturnTypeHintSniff.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,16 @@ private function checkFunctionTypeHint(
202202
continue;
203203
}
204204

205+
$isTraversable = TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $typeHint), $this->getTraversableTypeHints());
206+
207+
if (!$isTraversable && count($traversableTypeHints) > 0) {
208+
return;
209+
}
210+
205211
if (
206212
!$typeNode instanceof ArrayTypeNode
207213
&& !$typeNode instanceof ArrayShapeNode
208-
&& TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $typeHint), $this->getTraversableTypeHints())
214+
&& $isTraversable
209215
) {
210216
$traversableTypeHints[] = $typeHint;
211217
}

tests/Sniffs/TypeHints/data/returnTypeHintNoErrors.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,11 @@ public function moreTraverasableTypes()
200200
{
201201
}
202202

203+
/**
204+
* @return mixed[]|array|SomethingThatLooksAsArray
205+
*/
206+
public function moreDifferentTypes()
207+
{
208+
}
209+
203210
}

0 commit comments

Comments
 (0)