From c3e31f067de83606b46188d26fcca61a3e89c3c8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 19 Jul 2022 22:22:36 +0200 Subject: [PATCH] move ReturnTypeFromStrictTypedCallRector to enterprise (#2685) --- config/set/type-declaration-strict.php | 2 - .../Fixture/also_static_call.php.inc | 43 ---- .../Fixture/arrow_function.php.inc | 39 --- ...inner_functionlike_only_has_return.php.inc | 65 ----- .../Fixture/external_caller.php.inc | 31 --- .../Fixture/external_static_caller.php.inc | 31 --- ...functionlike_and_parent_has_return.php.inc | 69 ----- .../Fixture/return_function.php.inc | 37 --- .../return_self_different_namespace.php.inc | 37 --- ..._self_different_namespace_nullable.php.inc | 37 --- .../Fixture/skip_arrow_function_void.php.inc | 13 - .../Fixture/skip_constructor_for_void.php.inc | 11 - .../skip_external_function_caller.php.inc | 13 - .../Fixture/skip_false_report_type.php.inc | 19 -- .../Fixture/skip_interface_for_void.php.inc | 8 - .../skip_once_type_and_once_not.php.inc | 29 --- .../Fixture/skip_possible_no_return.php.inc | 18 -- .../Fixture/skip_twice_different_type.php.inc | 25 -- .../Fixture/some_class.php.inc | 37 --- .../Fixture/twice_same_type.php.inc | 45 ---- .../Fixture/use_return_self.php.inc | 47 ---- .../Fixture/use_return_self_nullable.php.inc | 55 ---- .../mix_of_nullable_types.php.inc | 55 ---- .../FixturePhp80/mix_of_union_types.php.inc | 55 ---- .../FixturePhp80/twice_different_type.php.inc | 55 ---- .../Php80Test.php | 33 --- ...eturnTypeFromStrictTypedCallRectorTest.php | 33 --- .../Source/CallWithVoid.php | 12 - .../Source/ReturnSelfFromSource.php | 13 - .../Source/ReturnSelfFromSourceNullable.php | 17 -- .../Source/SomeExternalCaller.php | 13 - .../Source/SomeExternalStaticCaller.php | 13 - .../Source/external_bool_function.php | 10 - .../config/configured_rule.php | 13 - .../config/php80_rule.php | 13 - .../NodeAnalyzer/ReturnStrictTypeAnalyzer.php | 82 ------ .../NodeAnalyzer/TypeNodeUnwrapper.php | 58 ----- .../ReturnTypeFromStrictTypedCallRector.php | 241 ------------------ 38 files changed, 1427 deletions(-) delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/also_static_call.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/arrow_function.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/do_not_return_parent_inner_functionlike_only_has_return.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_caller.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_static_caller.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/inner_functionlike_and_parent_has_return.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_function.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace_nullable.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_arrow_function_void.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_constructor_for_void.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_external_function_caller.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_false_report_type.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_interface_for_void.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_once_type_and_once_not.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_possible_no_return.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_twice_different_type.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/some_class.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/twice_same_type.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self_nullable.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_nullable_types.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_union_types.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/twice_different_type.php.inc delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Php80Test.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/ReturnTypeFromStrictTypedCallRectorTest.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/CallWithVoid.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/ReturnSelfFromSource.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/ReturnSelfFromSourceNullable.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/SomeExternalCaller.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/SomeExternalStaticCaller.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/external_bool_function.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/config/configured_rule.php delete mode 100644 rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/config/php80_rule.php delete mode 100644 rules/TypeDeclaration/NodeAnalyzer/ReturnStrictTypeAnalyzer.php delete mode 100644 rules/TypeDeclaration/NodeAnalyzer/TypeNodeUnwrapper.php delete mode 100644 rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php diff --git a/config/set/type-declaration-strict.php b/config/set/type-declaration-strict.php index fecbc97c024..eafe2740f43 100644 --- a/config/set/type-declaration-strict.php +++ b/config/set/type-declaration-strict.php @@ -12,7 +12,6 @@ use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector; use Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector; use Rector\TypeDeclaration\Rector\Param\ParamTypeFromStrictTypedPropertyRector; @@ -26,7 +25,6 @@ ReturnTypeFromStrictTypedPropertyRector::class, TypedPropertyFromStrictConstructorRector::class, ParamTypeFromStrictTypedPropertyRector::class, - ReturnTypeFromStrictTypedCallRector::class, AddVoidReturnTypeWhereNoReturnRector::class, ReturnTypeFromReturnNewRector::class, TypedPropertyFromStrictGetterMethodReturnTypeRector::class, diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/also_static_call.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/also_static_call.php.inc deleted file mode 100644 index 5ff8be96128..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/also_static_call.php.inc +++ /dev/null @@ -1,43 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/arrow_function.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/arrow_function.php.inc deleted file mode 100644 index 81854934be5..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/arrow_function.php.inc +++ /dev/null @@ -1,39 +0,0 @@ - App::init(); - -}; - -?> ------ - App::init(); - -}; - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/do_not_return_parent_inner_functionlike_only_has_return.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/do_not_return_parent_inner_functionlike_only_has_return.php.inc deleted file mode 100644 index a72c711a46d..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/do_not_return_parent_inner_functionlike_only_has_return.php.inc +++ /dev/null @@ -1,65 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_caller.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_caller.php.inc deleted file mode 100644 index c05e087f119..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_caller.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -getName(); - } -} - -?> ------ -getName(); - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_static_caller.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_static_caller.php.inc deleted file mode 100644 index 048b17bc96f..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/external_static_caller.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/inner_functionlike_and_parent_has_return.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/inner_functionlike_and_parent_has_return.php.inc deleted file mode 100644 index 7da3705f502..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/inner_functionlike_and_parent_has_return.php.inc +++ /dev/null @@ -1,69 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_function.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_function.php.inc deleted file mode 100644 index 412200cd786..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_function.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace.php.inc deleted file mode 100644 index f802743332c..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace_nullable.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace_nullable.php.inc deleted file mode 100644 index dc6007bef05..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/return_self_different_namespace_nullable.php.inc +++ /dev/null @@ -1,37 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_arrow_function_void.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_arrow_function_void.php.inc deleted file mode 100644 index bfabd222ef9..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_arrow_function_void.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - $callWithVoid->nothing(); - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_constructor_for_void.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_constructor_for_void.php.inc deleted file mode 100644 index 12d599fccad..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_constructor_for_void.php.inc +++ /dev/null @@ -1,11 +0,0 @@ -fakedTypes(); - } - - /** - * @return bool - */ - private function fakedTypes() - { - return 100; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_interface_for_void.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_interface_for_void.php.inc deleted file mode 100644 index e4ca22abb53..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_interface_for_void.php.inc +++ /dev/null @@ -1,8 +0,0 @@ -getNumber(); - } - - return $this->getRandom(); - } - - private function getNumber(): int - { - return 100; - } - - private function getRandom() - { - if (mt_rand(0, 1)) { - return true; - } - - return '...'; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_possible_no_return.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_possible_no_return.php.inc deleted file mode 100644 index d36ac3ef565..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_possible_no_return.php.inc +++ /dev/null @@ -1,18 +0,0 @@ -getNumber(); - } - } - - private function getNumber(): int - { - return 100; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_twice_different_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_twice_different_type.php.inc deleted file mode 100644 index f7300f84b26..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/skip_twice_different_type.php.inc +++ /dev/null @@ -1,25 +0,0 @@ -getNumber(); - } - - return $this->getString(); - } - - private function getNumber(): int - { - return 100; - } - - private function getString(): string - { - return 'hey'; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/some_class.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/some_class.php.inc deleted file mode 100644 index f2406fce96d..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,37 +0,0 @@ -getNumber(); - } - - private function getNumber(): int - { - return 1000; - } -} - -?> ------ -getNumber(); - } - - private function getNumber(): int - { - return 1000; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/twice_same_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/twice_same_type.php.inc deleted file mode 100644 index 5c96d7fd2ed..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/twice_same_type.php.inc +++ /dev/null @@ -1,45 +0,0 @@ -getNumber(100); - } - - return $this->getNumber(10); - } - - private function getNumber(int $value): int - { - return $value; - } -} - -?> ------ -getNumber(100); - } - - return $this->getNumber(10); - } - - private function getNumber(int $value): int - { - return $value; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self.php.inc deleted file mode 100644 index 500558b57b7..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self.php.inc +++ /dev/null @@ -1,47 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self_nullable.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self_nullable.php.inc deleted file mode 100644 index 1b80abc79ac..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Fixture/use_return_self_nullable.php.inc +++ /dev/null @@ -1,55 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_nullable_types.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_nullable_types.php.inc deleted file mode 100644 index a5d43dd4578..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_nullable_types.php.inc +++ /dev/null @@ -1,55 +0,0 @@ -getFirstMix(); - } - - return $this->getSecondMixed(); - } - - private function getFirstMix(): ?int - { - return 100; - } - - private function getSecondMixed(): ?string - { - return 'hey'; - } -} - -?> ------ -getFirstMix(); - } - - return $this->getSecondMixed(); - } - - private function getFirstMix(): ?int - { - return 100; - } - - private function getSecondMixed(): ?string - { - return 'hey'; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_union_types.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_union_types.php.inc deleted file mode 100644 index a4d75be1fdf..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/mix_of_union_types.php.inc +++ /dev/null @@ -1,55 +0,0 @@ -getFirstMix(); - } - - return $this->getSecondMixed(); - } - - private function getFirstMix(): int|string - { - return 100; - } - - private function getSecondMixed(): string|bool - { - return 'hey'; - } -} - -?> ------ -getFirstMix(); - } - - return $this->getSecondMixed(); - } - - private function getFirstMix(): int|string - { - return 100; - } - - private function getSecondMixed(): string|bool - { - return 'hey'; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/twice_different_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/twice_different_type.php.inc deleted file mode 100644 index 48c45e13a97..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/FixturePhp80/twice_different_type.php.inc +++ /dev/null @@ -1,55 +0,0 @@ -getNumber(); - } - - return $this->getString(); - } - - private function getNumber(): int - { - return 100; - } - - private function getString(): string - { - return 'hey'; - } -} - -?> ------ -getNumber(); - } - - return $this->getString(); - } - - private function getNumber(): int - { - return 100; - } - - private function getString(): string - { - return 'hey'; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Php80Test.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Php80Test.php deleted file mode 100644 index 772694be2ab..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Php80Test.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/php80_rule.php'; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/ReturnTypeFromStrictTypedCallRectorTest.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/ReturnTypeFromStrictTypedCallRectorTest.php deleted file mode 100644 index 7cdacfa3537..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/ReturnTypeFromStrictTypedCallRectorTest.php +++ /dev/null @@ -1,33 +0,0 @@ -doTestFileInfo($fileInfo); - } - - /** - * @return Iterator - */ - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/CallWithVoid.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/CallWithVoid.php deleted file mode 100644 index a0c3793e0ff..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/Source/CallWithVoid.php +++ /dev/null @@ -1,12 +0,0 @@ -rule(ReturnTypeFromStrictTypedCallRector::class); - - $rectorConfig->phpVersion(PhpVersionFeature::UNION_TYPES - 1); -}; diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/config/php80_rule.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/config/php80_rule.php deleted file mode 100644 index 13cec2bea25..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector/config/php80_rule.php +++ /dev/null @@ -1,13 +0,0 @@ -rule(ReturnTypeFromStrictTypedCallRector::class); - - $rectorConfig->phpVersion(PhpVersion::PHP_80); -}; diff --git a/rules/TypeDeclaration/NodeAnalyzer/ReturnStrictTypeAnalyzer.php b/rules/TypeDeclaration/NodeAnalyzer/ReturnStrictTypeAnalyzer.php deleted file mode 100644 index 142dc05a3bb..00000000000 --- a/rules/TypeDeclaration/NodeAnalyzer/ReturnStrictTypeAnalyzer.php +++ /dev/null @@ -1,82 +0,0 @@ - - */ - public function collectStrictReturnTypes(array $returns): array - { - $returnedStrictTypeNodes = []; - - foreach ($returns as $return) { - if ($return->expr === null) { - return []; - } - - $returnedExpr = $return->expr; - - if ($returnedExpr instanceof MethodCall || $returnedExpr instanceof StaticCall || $returnedExpr instanceof FuncCall) { - $returnNode = $this->resolveMethodCallReturnNode($returnedExpr); - } else { - return []; - } - - if (! $returnNode instanceof Node) { - return []; - } - - $returnedStrictTypeNodes[] = $returnNode; - } - - return $this->typeNodeUnwrapper->uniquateNodes($returnedStrictTypeNodes); - } - - private function resolveMethodCallReturnNode(MethodCall | StaticCall | FuncCall $call): ?Node - { - $methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($call); - if ($methodReflection === null) { - return null; - } - - $parametersAcceptor = $methodReflection->getVariants()[0]; - if ($parametersAcceptor instanceof FunctionVariantWithPhpDocs) { - // native return type is needed, as docblock can be false - $returnType = $parametersAcceptor->getNativeReturnType(); - } else { - $returnType = $parametersAcceptor->getReturnType(); - } - - if ($returnType instanceof MixedType) { - return null; - } - - return $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($returnType, TypeKind::RETURN); - } -} diff --git a/rules/TypeDeclaration/NodeAnalyzer/TypeNodeUnwrapper.php b/rules/TypeDeclaration/NodeAnalyzer/TypeNodeUnwrapper.php deleted file mode 100644 index 2427e36d814..00000000000 --- a/rules/TypeDeclaration/NodeAnalyzer/TypeNodeUnwrapper.php +++ /dev/null @@ -1,58 +0,0 @@ - $typeNodes - * @return array - */ - public function unwrapNullableUnionTypes(array $typeNodes): array - { - $unwrappedTypeNodes = []; - - foreach ($typeNodes as $typeNode) { - if ($typeNode instanceof UnionType) { - $unwrappedTypeNodes = array_merge($unwrappedTypeNodes, $typeNode->types); - } elseif ($typeNode instanceof NullableType) { - $unwrappedTypeNodes[] = $typeNode->type; - $unwrappedTypeNodes[] = new Identifier('null'); - } else { - $unwrappedTypeNodes[] = $typeNode; - } - } - - return $this->uniquateNodes($unwrappedTypeNodes); - } - - /** - * @param Node[] $nodes - * @return Node[] - */ - public function uniquateNodes(array $nodes): array - { - $uniqueNodes = []; - foreach ($nodes as $node) { - $uniqueHash = $this->nodeComparator->printWithoutComments($node); - $uniqueNodes[$uniqueHash] = $node; - } - - // reset keys from 0, for further compatibility - return array_values($uniqueNodes); - } -} diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php deleted file mode 100644 index 7e2608d093c..00000000000 --- a/rules/TypeDeclaration/Rector/ClassMethod/ReturnTypeFromStrictTypedCallRector.php +++ /dev/null @@ -1,241 +0,0 @@ -getNumber(); - } - - private function getNumber(): int - { - return 1000; - } -} -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -final class SomeClass -{ - public function getData(): int - { - return $this->getNumber(); - } - - private function getNumber(): int - { - return 1000; - } -} -CODE_SAMPLE - ), - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class]; - } - - /** - * @param ClassMethod|Function_|Closure|ArrowFunction $node - */ - public function refactor(Node $node): ?Node - { - if ($this->isSkipped($node)) { - return null; - } - - if ($node instanceof ArrowFunction) { - return $this->processArrowFunction($node); - } - - /** @var Return_[] $returns */ - $returns = $this->betterNodeFinder->find((array) $node->stmts, function (Node $subNode) use ($node): bool { - $currentFunctionLike = $this->betterNodeFinder->findParentType($subNode, FunctionLike::class); - - if ($currentFunctionLike === $node) { - return $subNode instanceof Return_; - } - - $currentReturn = $this->betterNodeFinder->findParentType($subNode, Return_::class); - if (! $currentReturn instanceof Return_) { - return false; - } - - $currentFunctionLike = $this->betterNodeFinder->findParentType($currentReturn, FunctionLike::class); - if ($currentFunctionLike !== $node) { - return false; - } - - return $subNode instanceof Return_; - }); - - $returnedStrictTypes = $this->returnStrictTypeAnalyzer->collectStrictReturnTypes($returns); - if ($returnedStrictTypes === []) { - return null; - } - - if (count($returnedStrictTypes) === 1) { - return $this->refactorSingleReturnType($returns[0], $returnedStrictTypes[0], $node); - } - - if ($this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::UNION_TYPES)) { - /** @var PhpParserUnionType[] $returnedStrictTypes */ - $unwrappedTypes = $this->typeNodeUnwrapper->unwrapNullableUnionTypes($returnedStrictTypes); - $node->returnType = new PhpParserUnionType($unwrappedTypes); - - return $node; - } - - return null; - } - - private function processArrowFunction(ArrowFunction $arrowFunction): ?ArrowFunction - { - $resolvedType = $this->nodeTypeResolver->getType($arrowFunction->expr); - - // void type is not accepted for arrow functions - https://www.php.net/manual/en/functions.arrow.php#125673 - if ($resolvedType instanceof VoidType) { - return null; - } - - $returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($resolvedType, TypeKind::RETURN); - - if (! $returnType instanceof Node) { - return null; - } - - $arrowFunction->returnType = $returnType; - return $arrowFunction; - } - - private function isUnionPossibleReturnsVoid(ClassMethod | Function_ | Closure $node): bool - { - $inferReturnType = $this->returnTypeInferer->inferFunctionLike($node); - if ($inferReturnType instanceof UnionType) { - foreach ($inferReturnType->getTypes() as $type) { - if ($type instanceof VoidType) { - return true; - } - } - } - - return false; - } - - private function processSingleUnionType( - ClassMethod | Function_ | Closure $node, - UnionType $unionType, - NullableType $nullableType - ): Closure | ClassMethod | Function_ { - $types = $unionType->getTypes(); - $returnType = $types[0] instanceof ObjectType && $types[1] instanceof NullType - ? new NullableType(new FullyQualified($types[0]->getClassName())) - : $nullableType; - - $node->returnType = $returnType; - return $node; - } - - private function isSkipped(ClassMethod | Function_ | Closure | ArrowFunction $node): bool - { - if (! $this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::SCALAR_TYPES)) { - return true; - } - - if ($node instanceof ArrowFunction) { - return $node->returnType !== null; - } - - if ($node->returnType !== null) { - return true; - } - - if (! $node instanceof ClassMethod) { - return $this->isUnionPossibleReturnsVoid($node); - } - - if (! $node->isMagic()) { - return $this->isUnionPossibleReturnsVoid($node); - } - - return true; - } - - private function refactorSingleReturnType( - Return_ $return, - Identifier|Name|NullableType $returnedStrictTypeNode, - ClassMethod | Function_ | Closure $functionLike - ): Closure | ClassMethod | Function_ { - $resolvedType = $this->nodeTypeResolver->getType($return); - - if ($resolvedType instanceof UnionType) { - if (! $returnedStrictTypeNode instanceof NullableType) { - return $functionLike; - } - - return $this->processSingleUnionType($functionLike, $resolvedType, $returnedStrictTypeNode); - } - - /** @var Name $returnType */ - $returnType = $resolvedType instanceof ObjectType - ? new FullyQualified($resolvedType->getClassName()) - : $returnedStrictTypeNode; - - $functionLike->returnType = $returnType; - - return $functionLike; - } -}