Skip to content

Commit

Permalink
use phpstan TypeCombinator
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Sep 1, 2024
1 parent 2b66191 commit 39ce2c7
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@

namespace Rector\PHPStanStaticTypeMapper\TypeAnalyzer;

use PHPStan\Type\NullType;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\UnionType;

final class UnionTypeAnalyzer
{
public function isNullable(UnionType $unionType, bool $checkTwoTypes = false): bool
public function isNullable(UnionType $unionType): bool
{
$types = $unionType->getTypes();

if ($checkTwoTypes && count($types) > 2) {
return false;
}

foreach ($types as $type) {
if ($type instanceof NullType) {
return true;
}
}

return false;
return TypeCombinator::containsNull($unionType);
}
}

0 comments on commit 39ce2c7

Please sign in to comment.