diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 9d8c06e93d4..15e77d6f634 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 355 Rules Overview +# 354 Rules Overview
@@ -40,7 +40,7 @@ - [Php80](#php80) (16) -- [Php81](#php81) (10) +- [Php81](#php81) (9) - [Php82](#php82) (4) @@ -5070,27 +5070,6 @@ Upgrade array callable to first class callable
-### IntersectionTypesRector - -Change docs to intersection types, where possible (properties are covered by TypedPropertyRector (@todo)) - -- class: [`Rector\Php81\Rector\FunctionLike\IntersectionTypesRector`](../rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php) - -```diff - final class SomeClass - { -- /** -- * @param Foo&Bar $types -- */ -- public function process($types) -+ public function process(Foo&Bar $types) - { - } - } -``` - -
- ### MyCLabsClassToEnumRector Refactor MyCLabs enum class to native Enum diff --git a/config/set/php81.php b/config/set/php81.php index 62a8bba4c7b..91d7916d1bd 100644 --- a/config/set/php81.php +++ b/config/set/php81.php @@ -9,7 +9,6 @@ use Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector; use Rector\Php81\Rector\ClassMethod\NewInInitializerRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; -use Rector\Php81\Rector\FunctionLike\IntersectionTypesRector; use Rector\Php81\Rector\MethodCall\MyCLabsMethodCallToEnumConstRector; use Rector\Php81\Rector\MethodCall\SpatieEnumMethodCallToEnumConstRector; use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; @@ -25,7 +24,6 @@ SpatieEnumClassToEnumRector::class, SpatieEnumMethodCallToEnumConstRector::class, NewInInitializerRector::class, - IntersectionTypesRector::class, NullToStrictStringFuncCallArgRector::class, FirstClassCallableRector::class, ]); diff --git a/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/Fixture/skip_scalar_types.php.inc b/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/Fixture/skip_scalar_types.php.inc deleted file mode 100644 index 0f82e7f6f15..00000000000 --- a/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/Fixture/skip_scalar_types.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ - diff --git a/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/IntersectionTypesRectorTest.php b/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/IntersectionTypesRectorTest.php deleted file mode 100644 index a3ac3df2cbf..00000000000 --- a/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/IntersectionTypesRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/Source/FirstObjectToIntersect.php b/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/Source/FirstObjectToIntersect.php deleted file mode 100644 index 13cf2f19d68..00000000000 --- a/rules-tests/Php81/Rector/FunctionLike/IntersectionTypesRector/Source/FirstObjectToIntersect.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(IntersectionTypesRector::class); -}; diff --git a/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php b/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php deleted file mode 100644 index 3bc76a8b298..00000000000 --- a/rules/Php81/Rector/FunctionLike/IntersectionTypesRector.php +++ /dev/null @@ -1,147 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [ArrowFunction::class, Closure::class, ClassMethod::class, Function_::class]; - } - - /** - * @param ArrowFunction|Closure|ClassMethod|Function_ $node - */ - public function refactor(Node $node): ?Node - { - $this->hasChanged = false; - - $phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); - if (! $phpDocInfo instanceof PhpDocInfo) { - return null; - } - - $this->refactorParamTypes($node, $phpDocInfo); - // $this->refactorReturnType($node, $phpDocInfo); - - if ($this->hasChanged) { - return $node; - } - - return null; - } - - public function provideMinPhpVersion(): int - { - return PhpVersionFeature::INTERSECTION_TYPES; - } - - private function refactorParamTypes( - ArrowFunction|Closure|ClassMethod|Function_ $functionLike, - PhpDocInfo $phpDocInfo - ): void { - foreach ($functionLike->params as $param) { - if ($param->type !== null) { - continue; - } - - /** @var string $paramName */ - $paramName = $this->getName($param->var); - $paramType = $phpDocInfo->getParamType($paramName); - - if (! $paramType instanceof IntersectionType) { - continue; - } - - if (! $this->isIntersectionableType($paramType)) { - continue; - } - - $phpParserIntersectionType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode( - $paramType, - TypeKind::PARAM - ); - - if (! $phpParserIntersectionType instanceof Node\IntersectionType) { - continue; - } - - $param->type = $phpParserIntersectionType; - $this->hasChanged = true; - } - } - - /** - * Only class-type are supported https://wiki.php.net/rfc/pure-intersection-types#supported_types - */ - private function isIntersectionableType(IntersectionType $intersectionType): bool - { - foreach ($intersectionType->getTypes() as $intersectionedType) { - if ($intersectionedType instanceof TypeWithClassName) { - continue; - } - - return false; - } - - return true; - } -}