rector/packages/PHPStanStaticTypeMapper/TypeMapper/ConditionalTypeForParameterMapper.php
Tomas Votruba aae549741f Updated Rector to commit 0cb3fd0feb464b4568e07607a05c794637aa2862
0cb3fd0feb [Php73] Handle crash Type Error on JsonThrowOnErrorRector (#4626)
2023-08-01 10:55:14 +00:00

55 lines
1.6 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\PHPStanStaticTypeMapper\TypeMapper;
use PhpParser\Node;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\ConditionalTypeForParameter;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use RectorPrefix202308\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements TypeMapperInterface<ConditionalTypeForParameter>
*/
final class ConditionalTypeForParameterMapper implements TypeMapperInterface
{
/**
* @var \Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper
*/
private $phpStanStaticTypeMapper;
/**
* @required
*/
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper) : void
{
$this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper;
}
/**
* @return class-string<Type>
*/
public function getNodeClass() : string
{
return ConditionalTypeForParameter::class;
}
/**
* @param ConditionalTypeForParameter $type
*/
public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode
{
return $type->toPhpDocNode();
}
/**
* @param ConditionalTypeForParameter $type
* @param TypeKind::* $typeKind
*/
public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node
{
$type = TypeCombinator::union($type->getIf(), $type->getElse());
return $this->phpStanStaticTypeMapper->mapToPhpParserNode($type, $typeKind);
}
}