diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 258eea8553c..dd59c169008 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '24fb5874905da56065ef38d9cfe9bff77cb04cac'; + public const PACKAGE_VERSION = '51261506c37859e99fde858677031dd0d72e7bfc'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-08-12 22:00:07'; + public const RELEASE_DATE = '2024-08-12 22:03:10'; /** * @var int */ diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php index 2a7eac27fbb..e446ba533dc 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php @@ -10,6 +10,7 @@ use PHPStan\Type\Type; use Rector\Php\PhpVersionProvider; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; +use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\ValueObject\PhpVersionFeature; /** * @implements TypeMapperInterface @@ -47,6 +48,9 @@ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node if (!$type->isExplicitMixed()) { return null; } + if ($typeKind === TypeKind::UNION) { + return null; + } return new Identifier('mixed'); } } diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php index 961a63638a4..9539d083b82 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php @@ -8,16 +8,28 @@ use PHPStan\PhpDocParser\Ast\Type\TypeNode; use PHPStan\Type\StrictMixedType; use PHPStan\Type\Type; +use Rector\Php\PhpVersionProvider; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; +use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\ValueObject\PhpVersionFeature; /** * @implements TypeMapperInterface */ final class StrictMixedTypeMapper implements TypeMapperInterface { + /** + * @readonly + * @var \Rector\Php\PhpVersionProvider + */ + private $phpVersionProvider; /** * @var string */ private const MIXED = 'mixed'; + public function __construct(PhpVersionProvider $phpVersionProvider) + { + $this->phpVersionProvider = $phpVersionProvider; + } public function getNodeClass() : string { return StrictMixedType::class; @@ -34,6 +46,12 @@ public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode */ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node { + if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::MIXED_TYPE)) { + return null; + } + if ($typeKind === TypeKind::UNION) { + return null; + } return new Identifier(self::MIXED); } } diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php index c76c7ceca2c..142ccaaf654 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php @@ -12,10 +12,8 @@ use PhpParser\Node\NullableType; use PhpParser\Node\UnionType as PhpParserUnionType; use PHPStan\PhpDocParser\Ast\Type\TypeNode; -use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\UnionType; -use PHPStan\Type\VoidType; use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode; use Rector\Php\PhpVersionProvider; use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface; @@ -158,11 +156,8 @@ private function matchPhpParserUnionType(UnionType $unionType) : ?Node { $phpParserUnionedTypes = []; foreach ($unionType->getTypes() as $unionedType) { - // void type and mixed type are not allowed in union - if (\in_array(\get_class($unionedType), [MixedType::class, VoidType::class], \true)) { - return null; - } // NullType or ConstantBooleanType with false value inside UnionType is allowed + // void type and mixed type are not allowed in union $phpParserNode = $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionedType, TypeKind::UNION); if ($phpParserNode === null) { return null; diff --git a/src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php b/src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php index 91e8b8dcc1f..e640706d9f0 100644 --- a/src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php +++ b/src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php @@ -50,7 +50,7 @@ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::VOID_TYPE)) { return null; } - if (\in_array($typeKind, [TypeKind::PARAM, TypeKind::PROPERTY], \true)) { + if (\in_array($typeKind, [TypeKind::PARAM, TypeKind::PROPERTY, TypeKind::UNION], \true)) { return null; } return new Identifier(self::VOID);