Skip to content

Commit fdab228

Browse files
committed
TypeHintDeclarationSniff: Fixed false positive
1 parent ecb6084 commit fdab228

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/TypeHintDeclarationSniff.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ private function checkParametersTypeHints(File $phpcsFile, int $functionPointer)
240240

241241
$possibleParameterTypeHint = $this->getTraversableTypeHintFromType($parameterTypeNode);
242242
$nullableParameterTypeHint = false;
243+
244+
if (!$this->isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleParameterTypeHint))) {
245+
continue;
246+
}
243247
}
244248
}
245249

@@ -464,6 +468,10 @@ private function checkReturnTypeHints(File $phpcsFile, int $functionPointer): vo
464468

465469
$possibleReturnTypeHint = $this->getTraversableTypeHintFromType($returnTypeNode);
466470
$nullableReturnTypeHint = false;
471+
472+
if (!$this->isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleReturnTypeHint))) {
473+
return;
474+
}
467475
}
468476
}
469477

tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,21 @@ public function hasGenericReturnAnnotation(): \Traversable
677677
{
678678
}
679679

680+
/**
681+
* @param mixed[]|string $parameter
682+
*/
683+
public function parameterArrayOrString($parameter): void
684+
{
685+
}
686+
687+
/**
688+
* @return mixed[]|string
689+
*/
690+
public function returnsArrayOrString()
691+
{
692+
return [];
693+
}
694+
680695
}
681696

682697
class IntersectionAndGeneric

0 commit comments

Comments
 (0)