diff --git a/src/DependencyInjection/LazyContainerFactory.php b/src/DependencyInjection/LazyContainerFactory.php index 9ee6280ca2a..748f31e1f19 100644 --- a/src/DependencyInjection/LazyContainerFactory.php +++ b/src/DependencyInjection/LazyContainerFactory.php @@ -148,7 +148,6 @@ use Rector\PHPStanStaticTypeMapper\TypeMapper\ConditionalTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\ConstantArrayTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\FloatTypeMapper; -use Rector\PHPStanStaticTypeMapper\TypeMapper\GenericClassStringTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\HasMethodTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetValueTypeTypeMapper; @@ -165,11 +164,9 @@ use Rector\PHPStanStaticTypeMapper\TypeMapper\OversizedArrayTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\ParentStaticTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\ResourceTypeMapper; -use Rector\PHPStanStaticTypeMapper\TypeMapper\SelfObjectTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\StaticTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\StrictMixedTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\StringTypeMapper; -use Rector\PHPStanStaticTypeMapper\TypeMapper\ThisTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\TypeWithClassNameTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\UnionTypeMapper; use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper; @@ -303,7 +300,6 @@ final class LazyContainerFactory ConditionalTypeForParameterMapper::class, ConditionalTypeMapper::class, FloatTypeMapper::class, - GenericClassStringTypeMapper::class, HasMethodTypeMapper::class, HasOffsetTypeMapper::class, HasOffsetValueTypeTypeMapper::class, @@ -320,11 +316,9 @@ final class LazyContainerFactory OversizedArrayTypeMapper::class, ParentStaticTypeMapper::class, ResourceTypeMapper::class, - SelfObjectTypeMapper::class, StaticTypeMapper::class, StrictMixedTypeMapper::class, StringTypeMapper::class, - ThisTypeMapper::class, TypeWithClassNameTypeMapper::class, UnionTypeMapper::class, VoidTypeMapper::class, diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/GenericClassStringTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/GenericClassStringTypeMapper.php deleted file mode 100644 index b85df380011..00000000000 --- a/src/PHPStanStaticTypeMapper/TypeMapper/GenericClassStringTypeMapper.php +++ /dev/null @@ -1,50 +0,0 @@ - - */ -final readonly class GenericClassStringTypeMapper implements TypeMapperInterface -{ - public function __construct( - private PhpVersionProvider $phpVersionProvider - ) { - } - - public function getNodeClass(): string - { - return GenericClassStringType::class; - } - - /** - * @param GenericClassStringType $type - */ - public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode - { - return $type->toPhpDocNode(); - } - - /** - * @param GenericClassStringType $type - */ - public function mapToPhpParserNode(Type $type, string $typeKind): ?Node - { - if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) { - return null; - } - - return new Identifier('string'); - } -} diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php deleted file mode 100644 index 738cd579b59..00000000000 --- a/src/PHPStanStaticTypeMapper/TypeMapper/SelfObjectTypeMapper.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -final class SelfObjectTypeMapper implements TypeMapperInterface -{ - public function getNodeClass(): string - { - return SelfObjectType::class; - } - - /** - * @param SelfObjectType $type - */ - public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode - { - return $type->toPhpDocNode(); - } - - /** - * @param SelfObjectType $type - */ - public function mapToPhpParserNode(Type $type, string $typeKind): Name - { - return new Name('self'); - } -} diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php deleted file mode 100644 index fb2a26b3938..00000000000 --- a/src/PHPStanStaticTypeMapper/TypeMapper/ThisTypeMapper.php +++ /dev/null @@ -1,38 +0,0 @@ - - */ -final class ThisTypeMapper implements TypeMapperInterface -{ - public function getNodeClass(): string - { - return ThisType::class; - } - - /** - * @param ThisType $type - */ - public function mapToPHPStanPhpDocTypeNode(Type $type): TypeNode - { - return $type->toPhpDocNode(); - } - - /** - * @param ThisType $type - */ - public function mapToPhpParserNode(Type $type, string $typeKind): Name - { - return new Name('self'); - } -} diff --git a/tests/PHPStanStaticTypeMapper/TypeMapperOrderTest.php b/tests/PHPStanStaticTypeMapper/TypeMapperOrderTest.php new file mode 100644 index 00000000000..0b2b779aa0f --- /dev/null +++ b/tests/PHPStanStaticTypeMapper/TypeMapperOrderTest.php @@ -0,0 +1,49 @@ +resolveTypeMappers(); + + foreach ($typeMappers as $position => $typeMapper) { + $nodeClass = $typeMapper->getNodeClass(); + + for ($earlierPosition = 0; $earlierPosition < $position; ++$earlierPosition) { + $earlierNodeClass = $typeMappers[$earlierPosition]->getNodeClass(); + + $this->assertFalse(is_a($nodeClass, $earlierNodeClass, true), sprintf( + 'The "%s" is registered after "%s", but "%s" is a "%s". It can never be reached, register it earlier.', + $typeMapper::class, + $typeMappers[$earlierPosition]::class, + $nodeClass, + $earlierNodeClass + )); + } + } + } + + /** + * @return TypeMapperInterface[] + */ + private function resolveTypeMappers(): array + { + $typeMappers = iterator_to_array(self::getContainer()->tagged(TypeMapperInterface::class)); + + $this->assertNotEmpty($typeMappers); + + return array_values($typeMappers); + } +}