rector/packages/StaticTypeMapper/PhpParser/IntersectionTypeNodeMapper.php
Tomas Votruba 6981c70c9a Updated Rector to commit 9ed8c21b127cdd45a28307d5fc41668f867f4ef4
9ed8c21b12 [DeadCode] Remove findFirstPrevious() usage on UselessIfCondBeforeForeachDetector (#4388)
2023-07-01 09:41:56 +00:00

44 lines
1.2 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\StaticTypeMapper\PhpParser;
use PhpParser\Node;
use PHPStan\Type\IntersectionType;
use PHPStan\Type\Type;
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
use RectorPrefix202307\Symfony\Contracts\Service\Attribute\Required;
/**
* @implements PhpParserNodeMapperInterface<Node\IntersectionType>
*/
final class IntersectionTypeNodeMapper implements PhpParserNodeMapperInterface
{
/**
* @var \Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper
*/
private $phpParserNodeMapper;
/**
* @required
*/
public function autowire(PhpParserNodeMapper $phpParserNodeMapper) : void
{
$this->phpParserNodeMapper = $phpParserNodeMapper;
}
public function getNodeType() : string
{
return Node\IntersectionType::class;
}
/**
* @param Node\IntersectionType $node
*/
public function mapToPHPStan(Node $node) : Type
{
$types = [];
foreach ($node->types as $intersectionedType) {
$types[] = $this->phpParserNodeMapper->mapToPHPStanType($intersectionedType);
}
return new IntersectionType($types);
}
}