*/ final class ConditionalTypeMapper implements TypeMapperInterface { /** * @var \Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper */ private $phpStanStaticTypeMapper; public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper) : void { $this->phpStanStaticTypeMapper = $phpStanStaticTypeMapper; } public function getNodeClass() : string { return ConditionalType::class; } /** * @param ConditionalType $type */ public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode { $type = TypeTraverser::map($type, static function (Type $type, callable $traverse) : Type { if ($type instanceof ObjectType && !$type->getClassReflection() instanceof ClassReflection) { $newClassName = (string) Strings::after($type->getClassName(), '\\', -1); return $traverse(new ObjectType($newClassName)); } return $traverse($type); }); return $type->toPhpDocNode(); } /** * @param ConditionalType $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); } }