Skip to content

Commit

Permalink
Updated Rector to commit 51261506c37859e99fde858677031dd0d72e7bfc
Browse files Browse the repository at this point in the history
rectorphp/rector-src@5126150 [TypeDeclaration] Skip mixed in union on ClosureReturnTypeRector (#6228)
  • Loading branch information
TomasVotruba committed Aug 12, 2024
1 parent 267b6cc commit 4abab4c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions src/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<MixedType>
Expand Down Expand Up @@ -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');
}
}
18 changes: 18 additions & 0 deletions src/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<StrictMixedType>
*/
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;
Expand All @@ -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);
}
}
7 changes: 1 addition & 6 deletions src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4abab4c

Please sign in to comment.