rector/packages/StaticTypeMapper/PhpDocParser/IntersectionTypeMapper.php

47 lines
1.6 KiB
PHP
Raw Normal View History

<?php
declare (strict_types=1);
2022-06-06 16:43:29 +00:00
namespace RectorPrefix20220606\Rector\StaticTypeMapper\PhpDocParser;
2022-06-06 16:43:29 +00:00
use RectorPrefix20220606\PhpParser\Node;
use RectorPrefix20220606\PHPStan\Analyser\NameScope;
use RectorPrefix20220606\PHPStan\PhpDocParser\Ast\Type\IntersectionTypeNode;
use RectorPrefix20220606\PHPStan\PhpDocParser\Ast\Type\TypeNode;
use RectorPrefix20220606\PHPStan\Type\IntersectionType;
use RectorPrefix20220606\PHPStan\Type\Type;
use RectorPrefix20220606\Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
use RectorPrefix20220606\Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
use RectorPrefix20220606\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements PhpDocTypeMapperInterface<IntersectionTypeNode>
*/
2022-06-06 16:43:29 +00:00
final class IntersectionTypeMapper implements PhpDocTypeMapperInterface
{
/**
* @var \Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper
*/
private $phpDocTypeMapper;
public function getNodeType() : string
{
2022-06-06 16:43:29 +00:00
return IntersectionTypeNode::class;
}
/**
* @required
*/
2022-06-06 16:43:29 +00:00
public function autowire(PhpDocTypeMapper $phpDocTypeMapper) : void
{
$this->phpDocTypeMapper = $phpDocTypeMapper;
}
/**
* @param IntersectionTypeNode $typeNode
*/
2022-06-06 16:43:29 +00:00
public function mapToPHPStanType(TypeNode $typeNode, Node $node, NameScope $nameScope) : Type
{
$intersectionedTypes = [];
foreach ($typeNode->types as $intersectionedTypeNode) {
$intersectionedTypes[] = $this->phpDocTypeMapper->mapToPHPStanType($intersectionedTypeNode, $node, $nameScope);
}
2022-06-06 16:43:29 +00:00
return new IntersectionType($intersectionedTypes);
}
}