Skip to content

Commit

Permalink
TypeHintDeclarationSniff: Fixed false positive
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Feb 3, 2019
1 parent ecb6084 commit fdab228
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ private function checkParametersTypeHints(File $phpcsFile, int $functionPointer)

$possibleParameterTypeHint = $this->getTraversableTypeHintFromType($parameterTypeNode);
$nullableParameterTypeHint = false;

if (!$this->isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleParameterTypeHint))) {
continue;
}
}
}

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

$possibleReturnTypeHint = $this->getTraversableTypeHintFromType($returnTypeNode);
$nullableReturnTypeHint = false;

if (!$this->isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $functionPointer, $possibleReturnTypeHint))) {
return;
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Sniffs/TypeHints/data/typeHintDeclarationNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,21 @@ public function hasGenericReturnAnnotation(): \Traversable
{
}

/**
* @param mixed[]|string $parameter
*/
public function parameterArrayOrString($parameter): void
{
}

/**
* @return mixed[]|string
*/
public function returnsArrayOrString()
{
return [];
}

}

class IntersectionAndGeneric
Expand Down

0 comments on commit fdab228

Please sign in to comment.