Skip to content

Commit

Permalink
Updated Rector to commit 554cad981917c1d402601c9fb158e3be9a66eeb1
Browse files Browse the repository at this point in the history
rectorphp/rector-src@554cad9 Avoid pre-mature abstract of union type (#6090)
  • Loading branch information
TomasVotruba committed Jun 30, 2024
1 parent 2f18f17 commit e6124b8
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 92 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 = '33655134e27ea56c99a01e159425d1f358c0b4a0';
public const PACKAGE_VERSION = '554cad981917c1d402601c9fb158e3be9a66eeb1';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-06-30 20:01:23';
public const RELEASE_DATE = '2024-06-30 23:09:24';
/**
* @var int
*/
Expand Down
15 changes: 0 additions & 15 deletions src/PHPStanStaticTypeMapper/TypeAnalyzer/UnionTypeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use PHPStan\Type\IterableType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis;
use Traversable;
Expand All @@ -34,20 +33,6 @@ public function analyseForArrayAndIterable(UnionType $unionType) : ?UnionTypeAna
}
return new UnionTypeAnalysis($hasIterable, $hasArray);
}
/**
* @return TypeWithClassName[]
*/
public function matchExclusiveTypesWithClassNames(UnionType $unionType) : array
{
$typesWithClassNames = [];
foreach ($unionType->getTypes() as $unionedType) {
if (!$unionedType instanceof TypeWithClassName) {
return [];
}
$typesWithClassNames[] = $unionedType;
}
return $typesWithClassNames;
}
public function isNullable(UnionType $unionType, bool $checkTwoTypes = \false) : bool
{
$types = $unionType->getTypes();
Expand Down
68 changes: 0 additions & 68 deletions src/PHPStanStaticTypeMapper/TypeMapper/UnionTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,12 @@
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\NullableType;
use PhpParser\Node\UnionType as PhpParserUnionType;
use PhpParser\NodeAbstract;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\IterableType;
use PHPStan\Type\MixedType;
use PHPStan\Type\NullType;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use PHPStan\Type\VoidType;
use Rector\BetterPhpDocParser\ValueObject\Type\BracketsAwareUnionTypeNode;
Expand All @@ -30,7 +27,6 @@
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeAnalyzer\UnionTypeAnalyzer;
use Rector\PHPStanStaticTypeMapper\ValueObject\UnionTypeAnalysis;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use RectorPrefix202406\Webmozart\Assert\Assert;
use RectorPrefix202406\Webmozart\Assert\InvalidArgumentException;
Expand Down Expand Up @@ -229,11 +225,6 @@ private function hasObjectAndStaticType(PhpParserUnionType $phpParserUnionType)
*/
private function matchTypeForUnionedTypes(UnionType $unionType, string $typeKind) : ?Node
{
// use first unioned type in case of unioned object types
$compatibleObjectTypeNode = $this->processResolveCompatibleObjectCandidates($unionType);
if ($compatibleObjectTypeNode instanceof NullableType || $compatibleObjectTypeNode instanceof FullyQualified) {
return $compatibleObjectTypeNode;
}
$phpParserUnionType = $this->matchPhpParserUnionType($unionType, $typeKind);
if ($phpParserUnionType instanceof NullableType) {
return $phpParserUnionType;
Expand All @@ -243,21 +234,6 @@ private function matchTypeForUnionedTypes(UnionType $unionType, string $typeKind
}
return $phpParserUnionType;
}
private function processResolveCompatibleObjectCandidates(UnionType $unionType) : ?Node
{
// the type should be compatible with all other types, e.g. A extends B, B
$compatibleObjectType = $this->resolveCompatibleObjectCandidate($unionType);
if ($compatibleObjectType instanceof UnionType) {
$type = $this->matchTypeForNullableUnionType($compatibleObjectType);
if ($type instanceof ObjectType) {
return $this->resolveNullableType(new NullableType(new FullyQualified($type->getClassName())));
}
}
if (!$compatibleObjectType instanceof ObjectType) {
return null;
}
return new FullyQualified($compatibleObjectType->getClassName());
}
/**
* @param TypeKind::* $typeKind
* @return Name|FullyQualified|ComplexType|Identifier|null
Expand Down Expand Up @@ -304,50 +280,6 @@ private function resolveAllowedStandaloneTypeInUnionType(Type $unionedType, stri
}
return $this->phpStanStaticTypeMapper->mapToPhpParserNode($unionedType, $typeKind);
}
/**
* @return \PHPStan\Type\UnionType|\PHPStan\Type\TypeWithClassName|null
*/
private function resolveCompatibleObjectCandidate(UnionType $unionType)
{
$typesWithClassNames = $this->unionTypeAnalyzer->matchExclusiveTypesWithClassNames($unionType);
if ($typesWithClassNames === []) {
return null;
}
$sharedTypeWithClassName = $this->matchTwoObjectTypes($typesWithClassNames);
if ($sharedTypeWithClassName instanceof TypeWithClassName) {
return $this->correctObjectType($sharedTypeWithClassName);
}
return null;
}
/**
* @param TypeWithClassName[] $typesWithClassNames
*/
private function matchTwoObjectTypes(array $typesWithClassNames) : ?TypeWithClassName
{
foreach ($typesWithClassNames as $typeWithClassName) {
foreach ($typesWithClassNames as $nestedTypeWithClassName) {
if (!$this->areTypeWithClassNamesRelated($typeWithClassName, $nestedTypeWithClassName)) {
continue 2;
}
}
return $typeWithClassName;
}
return null;
}
private function areTypeWithClassNamesRelated(TypeWithClassName $firstType, TypeWithClassName $secondType) : bool
{
return $firstType->accepts($secondType, \false)->yes();
}
private function correctObjectType(TypeWithClassName $typeWithClassName) : TypeWithClassName
{
if ($typeWithClassName->getClassName() === NodeAbstract::class) {
return new ObjectType('PhpParser\\Node');
}
if ($typeWithClassName->getClassName() === AbstractRector::class) {
return new ObjectType('Rector\\Contract\\Rector\\RectorInterface');
}
return $typeWithClassName;
}
private function resolveUnionTypeNode(PhpParserUnionType $phpParserUnionType) : ?PhpParserUnionType
{
if (!$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) {
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1867,12 +1867,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "d8a2c6297ff1563542e33ddba23a5e870576af71"
"reference": "b785e83846b0baeb9c59170de1a9584898854055"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/d8a2c6297ff1563542e33ddba23a5e870576af71",
"reference": "d8a2c6297ff1563542e33ddba23a5e870576af71",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/b785e83846b0baeb9c59170de1a9584898854055",
"reference": "b785e83846b0baeb9c59170de1a9584898854055",
"shasum": ""
},
"require": {
Expand Down Expand Up @@ -1901,7 +1901,7 @@
"tomasvotruba\/class-leak": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2024-06-26T14:22:03+00:00",
"time": "2024-06-30T21:02:53+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 8c5d6ee'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main c053b97'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 2245183'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main d8a2c62'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main 8c5d6ee'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main c053b97'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 2245183'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main b785e83'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class StringExtensionToConfigBuilderRector extends AbstractRector
/**
* @var array<string, string>
*/
private const EXTENSION_KEY_TO_CLASS_MAP = ['security' => 'Symfony\\Config\\SecurityConfig', 'framework' => 'Symfony\\Config\\FrameworkConfig', 'monolog' => 'Symfony\\Config\\MonologConfig', 'twig' => 'Symfony\\Config\\TwigConfig', 'doctrine' => 'Symfony\\Config\\DoctrineConfig', 'doctrine_migrations' => 'Symfony\\Config\\DoctrineMigrationsConfig', 'sentry' => 'Symfony\\Config\\SentryConfig'];
private const EXTENSION_KEY_TO_CLASS_MAP = ['security' => 'Symfony\\Config\\SecurityConfig', 'framework' => 'Symfony\\Config\\FrameworkConfig', 'monolog' => 'Symfony\\Config\\MonologConfig', 'twig' => 'Symfony\\Config\\TwigConfig', 'doctrine' => 'Symfony\\Config\\DoctrineConfig', 'doctrine_migrations' => 'Symfony\\Config\\DoctrineMigrationsConfig', 'sentry' => 'Symfony\\Config\\SentryConfig', 'web_profiler' => 'Symfony\\Config\\WebProfilerConfig'];
public function __construct(SymfonyPhpClosureDetector $symfonyPhpClosureDetector, SymfonyClosureExtensionMatcher $symfonyClosureExtensionMatcher, PropertyNaming $propertyNaming, ValueResolver $valueResolver, NestedConfigCallsFactory $nestedConfigCallsFactory, SecurityAccessDecisionManagerConfigArrayHandler $securityAccessDecisionManagerConfigArrayHandler, SymfonyClosureFactory $symfonyClosureFactory)
{
$this->symfonyPhpClosureDetector = $symfonyPhpClosureDetector;
Expand Down

0 comments on commit e6124b8

Please sign in to comment.