Skip to content

Commit e3da0f3

Browse files
committed
Updated Rector to commit a4c489ee0914233600f93379edee4932ce2d4ee4
rectorphp/rector-src@a4c489e [TypeDeclaration] Allow union with closure type on property on TypedPropertyFromAssignsRector (#6717)
1 parent 9ae9296 commit e3da0f3

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
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 = '7f910682cd51567d6ae5606a2edcd756f4cc79b0';
22+
public const PACKAGE_VERSION = 'a4c489ee0914233600f93379edee4932ce2d4ee4';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-02-03 21:35:57';
27+
public const RELEASE_DATE = '2025-02-05 11:37:04';
2828
/**
2929
* @var int
3030
*/

src/NodeAnalyzer/PropertyAnalyzer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function hasForbiddenType(Property $property) : bool
3939
}
4040
return \false;
4141
}
42-
private function isForbiddenType(Type $type) : bool
42+
public function isForbiddenType(Type $type) : bool
4343
{
4444
if ($type instanceof NonExistingObjectType) {
4545
return \true;

src/PHPStanStaticTypeMapper/TypeMapper/ClosureTypeMapper.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ public function mapToPhpParserNode(Type $type, string $typeKind) : ?Node
6565
if ($typeKind === TypeKind::PROPERTY && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::TYPED_PROPERTIES)) {
6666
return new FullyQualified('Closure');
6767
}
68-
if ($typeKind !== TypeKind::RETURN) {
69-
return null;
70-
}
7168
// ref https://3v4l.org/nUreN#v7.0.0
72-
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ANONYMOUS_FUNCTION_RETURN_TYPE)) {
73-
return null;
69+
if ($typeKind === TypeKind::RETURN && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::ANONYMOUS_FUNCTION_RETURN_TYPE)) {
70+
return new FullyQualified('Closure');
71+
}
72+
// ref https://3v4l.org/ruh5g#v8.0.0
73+
if ($typeKind === TypeKind::UNION && $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
74+
return new FullyQualified('Closure');
7475
}
75-
return new FullyQualified('Closure');
76+
return null;
7677
}
7778
}

src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPStan\Type\Type;
1616
use PHPStan\Type\UnionType;
1717
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
18+
use Rector\NodeAnalyzer\PropertyAnalyzer;
1819
use Rector\Php\PhpVersionProvider;
1920
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
2021
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
@@ -31,10 +32,15 @@ final class UnionTypeMapper implements TypeMapperInterface
3132
* @readonly
3233
*/
3334
private PhpVersionProvider $phpVersionProvider;
35+
/**
36+
* @readonly
37+
*/
38+
private PropertyAnalyzer $propertyAnalyzer;
3439
private PHPStanStaticTypeMapper $phpStanStaticTypeMapper;
35-
public function __construct(PhpVersionProvider $phpVersionProvider)
40+
public function __construct(PhpVersionProvider $phpVersionProvider, PropertyAnalyzer $propertyAnalyzer)
3641
{
3742
$this->phpVersionProvider = $phpVersionProvider;
43+
$this->propertyAnalyzer = $propertyAnalyzer;
3844
}
3945
public function autowire(PHPStanStaticTypeMapper $phpStanStaticTypeMapper) : void
4046
{
@@ -159,7 +165,7 @@ private function matchPhpParserUnionType(UnionType $unionType, string $typeKind)
159165
return null;
160166
}
161167
// special callable type only not allowed on property
162-
if ($typeKind === TypeKind::PROPERTY && $unionedType->isCallable()->yes()) {
168+
if ($typeKind === TypeKind::PROPERTY && $this->propertyAnalyzer->isForbiddenType($unionedType)) {
163169
return null;
164170
}
165171
$phpParserUnionedTypes[] = $phpParserNode;

0 commit comments

Comments
 (0)