2021-11-06 12:10:48 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace Rector\Php74\TypeAnalyzer;
|
|
|
|
|
2021-11-14 12:07:09 +00:00
|
|
|
use PhpParser\Node\ComplexType;
|
2021-11-06 12:10:48 +00:00
|
|
|
use PhpParser\Node\Name;
|
|
|
|
use PhpParser\Node\NullableType;
|
|
|
|
use PHPStan\Type\NullType;
|
|
|
|
use PHPStan\Type\Type;
|
|
|
|
use PHPStan\Type\UnionType;
|
|
|
|
final class PropertyUnionTypeResolver
|
|
|
|
{
|
|
|
|
/**
|
2021-11-14 12:07:09 +00:00
|
|
|
* @param \PhpParser\Node\ComplexType|\PhpParser\Node\Name $phpUnionType
|
2021-11-06 12:10:48 +00:00
|
|
|
*/
|
|
|
|
public function resolve($phpUnionType, \PHPStan\Type\Type $possibleUnionType) : \PHPStan\Type\Type
|
|
|
|
{
|
|
|
|
if (!$phpUnionType instanceof \PhpParser\Node\NullableType) {
|
|
|
|
return $possibleUnionType;
|
|
|
|
}
|
|
|
|
if (!$possibleUnionType instanceof \PHPStan\Type\UnionType) {
|
|
|
|
return $possibleUnionType;
|
|
|
|
}
|
|
|
|
$types = $possibleUnionType->getTypes();
|
|
|
|
foreach ($types as $type) {
|
|
|
|
if (!$type instanceof \PHPStan\Type\NullType) {
|
|
|
|
return $type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $possibleUnionType;
|
|
|
|
}
|
|
|
|
}
|