rector/packages/StaticTypeMapper/PhpDocParser/IntersectionTypeMapper.php
Tomas Votruba 7d0f151a40 Updated Rector to commit a2cd7283fbf2d6b2904016c51e3f4a545caa0256
a2cd7283fb Typo fix comment php 7.3 compat on rector workflow (#3432)
2023-03-01 13:00:30 +00:00

47 lines
1.4 KiB
PHP

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