Skip to content

Commit 4abab4c

Browse files
committed
Updated Rector to commit 51261506c37859e99fde858677031dd0d72e7bfc
rectorphp/rector-src@5126150 [TypeDeclaration] Skip mixed in union on ClosureReturnTypeRector (#6228)
1 parent 267b6cc commit 4abab4c

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

src/Application/VersionResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '24fb5874905da56065ef38d9cfe9bff77cb04cac';
22+
public const PACKAGE_VERSION = '51261506c37859e99fde858677031dd0d72e7bfc';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-08-12 22:00:07';
27+
public const RELEASE_DATE = '2024-08-12 22:03:10';
2828
/**
2929
* @var int
3030
*/

src/PHPStanStaticTypeMapper/TypeMapper/MixedTypeMapper.php

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use PHPStan\Type\Type;
1111
use Rector\Php\PhpVersionProvider;
1212
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
13+
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
1314
use Rector\ValueObject\PhpVersionFeature;
1415
/**
1516
* @implements TypeMapperInterface<MixedType>
@@ -47,6 +48,9 @@ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node
4748
if (!$type->isExplicitMixed()) {
4849
return null;
4950
}
51+
if ($typeKind === TypeKind::UNION) {
52+
return null;
53+
}
5054
return new Identifier('mixed');
5155
}
5256
}

src/PHPStanStaticTypeMapper/TypeMapper/StrictMixedTypeMapper.php

+18
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,28 @@
88
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
99
use PHPStan\Type\StrictMixedType;
1010
use PHPStan\Type\Type;
11+
use Rector\Php\PhpVersionProvider;
1112
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
13+
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
14+
use Rector\ValueObject\PhpVersionFeature;
1215
/**
1316
* @implements TypeMapperInterface<StrictMixedType>
1417
*/
1518
final class StrictMixedTypeMapper implements TypeMapperInterface
1619
{
20+
/**
21+
* @readonly
22+
* @var \Rector\Php\PhpVersionProvider
23+
*/
24+
private $phpVersionProvider;
1725
/**
1826
* @var string
1927
*/
2028
private const MIXED = 'mixed';
29+
public function __construct(PhpVersionProvider $phpVersionProvider)
30+
{
31+
$this->phpVersionProvider = $phpVersionProvider;
32+
}
2133
public function getNodeClass() : string
2234
{
2335
return StrictMixedType::class;
@@ -34,6 +46,12 @@ public function mapToPHPStanPhpDocTypeNode(Type $type) : TypeNode
3446
*/
3547
public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node
3648
{
49+
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::MIXED_TYPE)) {
50+
return null;
51+
}
52+
if ($typeKind === TypeKind::UNION) {
53+
return null;
54+
}
3755
return new Identifier(self::MIXED);
3856
}
3957
}

src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
use PhpParser\Node\NullableType;
1313
use PhpParser\Node\UnionType as PhpParserUnionType;
1414
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
15-
use PHPStan\Type\MixedType;
1615
use PHPStan\Type\Type;
1716
use PHPStan\Type\UnionType;
18-
use PHPStan\Type\VoidType;
1917
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
2018
use Rector\Php\PhpVersionProvider;
2119
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
@@ -158,11 +156,8 @@ private function matchPhpParserUnionType(UnionType $unionType) : ?Node
158156
{
159157
$phpParserUnionedTypes = [];
160158
foreach ($unionType->getTypes() as $unionedType) {
161-
// void type and mixed type are not allowed in union
162-
if (\in_array(\get_class($unionedType), [MixedType::class, VoidType::class], \true)) {
163-
return null;
164-
}
165159
// NullType or ConstantBooleanType with false value inside UnionType is allowed
160+
// void type and mixed type are not allowed in union
166161
$phpParserNode = $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionedType, TypeKind::UNION);
167162
if ($phpParserNode === null) {
168163
return null;

src/PHPStanStaticTypeMapper/TypeMapper/VoidTypeMapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node
5050
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::VOID_TYPE)) {
5151
return null;
5252
}
53-
if (\in_array($typeKind, [TypeKind::PARAM, TypeKind::PROPERTY], \true)) {
53+
if (\in_array($typeKind, [TypeKind::PARAM, TypeKind::PROPERTY, TypeKind::UNION], \true)) {
5454
return null;
5555
}
5656
return new Identifier(self::VOID);

0 commit comments

Comments
 (0)