Skip to content

Commit

Permalink
ParameterTypeHintSniff, PropertyTypeHintSniff, ReturnTypeHintSniff: F…
Browse files Browse the repository at this point in the history
…ixed false positives
  • Loading branch information
kukulich committed Feb 3, 2020
1 parent 7812bac commit 49e6021
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
22 changes: 10 additions & 12 deletions SlevomatCodingStandard/Helpers/AnnotationTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,24 +554,22 @@ public static function getTraversableTypeHintFromType(
array $traversableTypeHints
): ?string
{
$typeHint = null;

foreach ($typeNode->types as $type) {
if (
!$type instanceof GenericTypeNode
&& !$type instanceof ThisTypeNode
&& !$type instanceof IdentifierTypeNode
$type instanceof GenericTypeNode
|| $type instanceof ThisTypeNode
|| $type instanceof IdentifierTypeNode
) {
continue;
$typeHint = self::getTypeHintFromOneType($type);
break;
}

$typeHint = self::getTypeHintFromOneType($type);
if (!TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $pointer, $typeHint), $traversableTypeHints)) {
continue;
}

return $typeHint;
}

return null;
return $typeHint !== null && TypeHintHelper::isTraversableType(TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $pointer, $typeHint), $traversableTypeHints)
? $typeHint
: null;
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Sniffs/TypeHints/data/parameterTypeHintNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,11 @@ public function anotherDifferentTypes($a)
{
}

/**
* @param Whatever|mixed[]|array $a
*/
public function yetAnotherDifferentTypes($a)
{
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ class Whatever
*/
public $anotherDifferentTypes;

/**
* @var Whatever|mixed[]|array
*/
public $yetAnotherDifferentTypes;

}
7 changes: 7 additions & 0 deletions tests/Sniffs/TypeHints/data/returnTypeHintNoErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,11 @@ public function anotherDifferentTypes()
{
}

/**
* @return Whatever|mixed[]|array
*/
public function yetAnotherDifferentTypes()
{
}

}

0 comments on commit 49e6021

Please sign in to comment.