diff --git a/composer.json b/composer.json index 82e305f82e8..3eaca32401e 100644 --- a/composer.json +++ b/composer.json @@ -93,7 +93,6 @@ ], "files": [ "tests/debug_functions.php", - "rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Source/FunctionTyped.php", "rules-tests/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector/Source/functions.php", "rules-tests/Php70/Rector/ClassMethod/Php4ConstructorRector/Source/ParentClass.php" ] diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/ArrayParamTypeByMethodCallTypeRectorTest.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/ArrayParamTypeByMethodCallTypeRectorTest.php deleted file mode 100644 index 8f89e0ac2f4..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/ArrayParamTypeByMethodCallTypeRectorTest.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/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/nullable_array.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/nullable_array.php.inc deleted file mode 100644 index 261e93af598..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/nullable_array.php.inc +++ /dev/null @@ -1,35 +0,0 @@ -use($value); - } - - private function use(?array $value): void - { - } -} - -?> ------ -use($value); - } - - private function use(?array $value): void - { - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_object_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_object_type.php.inc deleted file mode 100644 index a3eb601adfe..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_object_type.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -use($value); - } - - private function use(stdClass $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_scalar_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_scalar_type.php.inc deleted file mode 100644 index 19485ec7dd3..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_scalar_type.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -use($value); - } - - private function use(string $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_trait.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_trait.php.inc deleted file mode 100644 index 6c66c3b3c95..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/skip_trait.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -use($value); - } - - private function use(array $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/throw_without_new.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/throw_without_new.php.inc deleted file mode 100644 index 20ef3d2ef81..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/Fixture/throw_without_new.php.inc +++ /dev/null @@ -1,39 +0,0 @@ -execute($value); - } - - throw $t; - } -} - -?> ------ -execute($value); - } - - throw $t; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/config/configured_rule.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/config/configured_rule.php deleted file mode 100644 index 1379d4ac73a..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -withRules([ArrayParamTypeByMethodCallTypeRector::class]) - ->withPhpVersion(PhpVersion::PHP_80); diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/nullable_object_param.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/nullable_object_param.php.inc deleted file mode 100644 index b2abe73decf..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/nullable_object_param.php.inc +++ /dev/null @@ -1,39 +0,0 @@ -use($value); - } - - private function use(?stdClass $value): void - { - } -} - -?> ------ -use($value); - } - - private function use(?stdClass $value): void - { - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/object_param.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/object_param.php.inc deleted file mode 100644 index a00bd794e63..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/object_param.php.inc +++ /dev/null @@ -1,39 +0,0 @@ -use($value); - } - - private function use(stdClass $value): void - { - } -} - -?> ------ -use($value); - } - - private function use(stdClass $value): void - { - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/skip_array_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/skip_array_type.php.inc deleted file mode 100644 index 350a13c74e1..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/skip_array_type.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -use($value); - } - - private function use(array $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/skip_scalar_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/skip_scalar_type.php.inc deleted file mode 100644 index 1466d52b589..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/Fixture/skip_scalar_type.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -use($value); - } - - private function use(string $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/ObjectParamTypeByMethodCallTypeRectorTest.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/ObjectParamTypeByMethodCallTypeRectorTest.php deleted file mode 100644 index d08883ac632..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/ObjectParamTypeByMethodCallTypeRectorTest.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/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/config/configured_rule.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/config/configured_rule.php deleted file mode 100644 index 8d4a9eae7c7..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector/config/configured_rule.php +++ /dev/null @@ -1,11 +0,0 @@ -withRules([ObjectParamTypeByMethodCallTypeRector::class]) - ->withPhpVersion(PhpVersion::PHP_80); diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_conditional.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_conditional.php.inc deleted file mode 100644 index 4d41cc623fb..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_conditional.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -processArray($value); - } - } - - private function processArray(array $value) - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_conditional_with_latest_method_call.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_conditional_with_latest_method_call.php.inc deleted file mode 100644 index 8df6630ecbf..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_conditional_with_latest_method_call.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -removeQuotesFromArray($value); - } - - if (! is_string($value)) { - return $value; - } - - $matches = Strings::match($value, 'some_'); - if ($matches === null) { - return $value; - } - - return $matches['content']; - } - - private function removeQuotesFromArray(array $value) - { - return $value; - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_default_numeric_string_param_int.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_default_numeric_string_param_int.php.inc deleted file mode 100644 index 90a7788763a..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_default_numeric_string_param_int.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -execute($value); - } - - private function execute(int $value) - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_in_form_builder_callback.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_in_form_builder_callback.php.inc deleted file mode 100644 index fbc4f87df2c..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_in_form_builder_callback.php.inc +++ /dev/null @@ -1,37 +0,0 @@ -add('someType', DocumentType::class, [ - 'class' => SomeType::class, - 'required' => false, - 'label' => 'Some Type', - 'attr' => [ - 'data-help' => 'some data help', - ], - 'constraints' => [ - new Assert\Callback(function ($someType, ExecutionContextInterface $context): void { - if ($someType === null) { - return; - } - - $this->use($someType); - - // some logic here - }) - ] - ]); - } - - private function use(SomeType $someType): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_in_form_builder_callback_instanceof.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_in_form_builder_callback_instanceof.php.inc deleted file mode 100644 index bc88fc7b309..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_in_form_builder_callback_instanceof.php.inc +++ /dev/null @@ -1,37 +0,0 @@ -add('someType', DocumentType::class, [ - 'class' => SomeType::class, - 'required' => false, - 'label' => 'Some Type', - 'attr' => [ - 'data-help' => 'some data help', - ], - 'constraints' => [ - new Assert\Callback(function ($someType, ExecutionContextInterface $context): void { - if (! $someType instanceof SomeType) { - return; - } - - $this->use($someType); - - // some logic here - }) - ] - ]); - } - - private function use(SomeType $someType): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_mixed_as_not_precise.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_mixed_as_not_precise.php.inc deleted file mode 100644 index 3d37ca9ba5d..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_mixed_as_not_precise.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -processArray($value); - } - - private function processArray(mixed $value) - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_on_right_and.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_on_right_and.php.inc deleted file mode 100644 index be51bf25425..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_on_right_and.php.inc +++ /dev/null @@ -1,28 +0,0 @@ -code = $code; - } - - public static function tryFromUntrusted($code): ?self - { - $ok = \is_string($code) && self::isCodeOk($code); - if (! $ok) { - return null; - } - - return new self($code); - } - - private static function isCodeOk(string $code): bool - { - return true; - } -} \ No newline at end of file diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_param_reassign.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_param_reassign.php.inc deleted file mode 100644 index 007e4f30173..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_param_reassign.php.inc +++ /dev/null @@ -1,27 +0,0 @@ -resolve($item); - $this->send($item); - } - - /** @param int|stdClass $item */ - private function resolve($item): stdClass { - if ($item instanceof stdClass) { - return $item; - } - return new stdClass(); - } - - private function send(stdClass $item): void { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_parent_guarded_method.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_parent_guarded_method.php.inc deleted file mode 100644 index 3814bd67e5b..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_parent_guarded_method.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -someTypedService->run($value); - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_pure_array.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_pure_array.php.inc deleted file mode 100644 index 5aa27108910..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_pure_array.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -use($value); - } - - private function use(array $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_ternary.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_ternary.php.inc deleted file mode 100644 index c496207c29d..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_ternary.php.inc +++ /dev/null @@ -1,23 +0,0 @@ -processArray($value) : $this->processMixed($value); - } - - private function processArray(array $value) - { - - } - - private function processMixed($value) - { - - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_unknown_parent.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_unknown_parent.php.inc deleted file mode 100644 index 41285f968dc..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_unknown_parent.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -someTypedService->run($value); - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_variadic_array.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_variadic_array.php.inc deleted file mode 100644 index 00bc0d597cf..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_variadic_array.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -processVariadic($items); - } - - private function processVariadic(array $value) - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_with_possible_docblock.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_with_possible_docblock.php.inc deleted file mode 100644 index ac3905f02e5..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/skip_with_possible_docblock.php.inc +++ /dev/null @@ -1,26 +0,0 @@ -hashSet($key, $value); - case 'value': - return $this->valueSet($key, $value); - default: - throw new \Exception('ohno'); - } - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/union_on_multiple_calls.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/union_on_multiple_calls.php.inc deleted file mode 100644 index 5a4f07281b8..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/union_on_multiple_calls.php.inc +++ /dev/null @@ -1,61 +0,0 @@ -hashSet($key, $value); - case 'value': - return $this->valueSet($key, $value); - case 'hash2': - return $this->hashSet2($key, $value); - default: - throw new \Exception('ohno'); - } - } -} - -?> ------ -hashSet($key, $value); - case 'value': - return $this->valueSet($key, $value); - case 'hash2': - return $this->hashSet2($key, $value); - default: - throw new \Exception('ohno'); - } - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/union_on_multiple_calls_nullable.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/union_on_multiple_calls_nullable.php.inc deleted file mode 100644 index 942a40f2842..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Fixture/union_on_multiple_calls_nullable.php.inc +++ /dev/null @@ -1,61 +0,0 @@ -hashSet($key, $value); - case 'value': - return $this->valueSet($key, $value); - case 'hash2': - return $this->hashSet2($key, $value); - default: - throw new \Exception('ohno'); - } - } -} - -?> ------ -hashSet($key, $value); - case 'value': - return $this->valueSet($key, $value); - case 'hash2': - return $this->hashSet2($key, $value); - default: - throw new \Exception('ohno'); - } - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/ParamTypeByMethodCallTypeRectorTest.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/ParamTypeByMethodCallTypeRectorTest.php deleted file mode 100644 index eb854040241..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/ParamTypeByMethodCallTypeRectorTest.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/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Source/GoOneWayInterface.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Source/GoOneWayInterface.php deleted file mode 100644 index 209e9332e2b..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector/Source/GoOneWayInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -withRules([ParamTypeByMethodCallTypeRector::class]) - ->withPhpVersion(PhpVersion::PHP_80); diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/also_arrow_function.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/also_arrow_function.php.inc deleted file mode 100644 index efa49be2038..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/also_arrow_function.php.inc +++ /dev/null @@ -1,41 +0,0 @@ - $this->someTypedService->runInt($value); - } -} - -?> ------ - $this->someTypedService->runInt($value); - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/also_closure.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/also_closure.php.inc deleted file mode 100644 index a643bf40d48..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/also_closure.php.inc +++ /dev/null @@ -1,45 +0,0 @@ -someTypedService->runInt($value); - }; - } -} - -?> ------ -someTypedService->runInt($value); - }; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/default_null_union.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/default_null_union.php.inc deleted file mode 100644 index 989b7889262..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/default_null_union.php.inc +++ /dev/null @@ -1,41 +0,0 @@ -someTypedService->withDefaultNullUnion($value); - } -} - -?> ------ -someTypedService->withDefaultNullUnion($value); - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/func_call_elsewhere.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/func_call_elsewhere.php.inc deleted file mode 100644 index 190354e4ae7..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/func_call_elsewhere.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_array_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_array_type.php.inc deleted file mode 100644 index 158858feb41..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_array_type.php.inc +++ /dev/null @@ -1,15 +0,0 @@ -use($value); - } - - private function use(array $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_object_type.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_object_type.php.inc deleted file mode 100644 index da28901380e..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_object_type.php.inc +++ /dev/null @@ -1,17 +0,0 @@ -use($value); - } - - private function use(stdClass $value): void - { - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_string_caller_param.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_string_caller_param.php.inc deleted file mode 100644 index 9ade3c92293..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/skip_string_caller_param.php.inc +++ /dev/null @@ -1,19 +0,0 @@ -someTypedService->run($value); - } -} diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/some_class.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/some_class.php.inc deleted file mode 100644 index a9d4d3603d7..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,41 +0,0 @@ -someTypedService->runInt($value); - } -} - -?> ------ -someTypedService->runInt($value); - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/static_call_elsewhere.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/static_call_elsewhere.php.inc deleted file mode 100644 index 0ea6134d7a0..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/static_call_elsewhere.php.inc +++ /dev/null @@ -1,31 +0,0 @@ - ------ - diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/with_default_constant_integer_type_param_int.php.inc b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/with_default_constant_integer_type_param_int.php.inc deleted file mode 100644 index f0585ec3e13..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Fixture/with_default_constant_integer_type_param_int.php.inc +++ /dev/null @@ -1,35 +0,0 @@ -execute($value); - } - - private function execute(int $value) - { - } -} - -?> ------ -execute($value); - } - - private function execute(int $value) - { - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/ScalarParamTypeByMethodCallTypeRectorTest.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/ScalarParamTypeByMethodCallTypeRectorTest.php deleted file mode 100644 index 4f4aa56f1de..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/ScalarParamTypeByMethodCallTypeRectorTest.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/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Source/FunctionTyped.php b/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Source/FunctionTyped.php deleted file mode 100644 index 2bfd1e39cdc..00000000000 --- a/rules-tests/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector/Source/FunctionTyped.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([ScalarParamTypeByMethodCallTypeRector::class]) - ->withPhpVersion(PhpVersion::PHP_80); diff --git a/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php b/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php index ac507454878..6494e91dea2 100644 --- a/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php +++ b/rules/TypeDeclaration/NodeAnalyzer/CallerParamMatcher.php @@ -4,87 +4,24 @@ namespace Rector\TypeDeclaration\NodeAnalyzer; -use PhpParser\Node; use PhpParser\Node\Arg; -use PhpParser\Node\ComplexType; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Identifier; -use PhpParser\Node\IntersectionType; -use PhpParser\Node\Name; -use PhpParser\Node\NullableType; use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\Node\UnionType; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; -use PHPStan\Type\MixedType; use Rector\NodeNameResolver\NodeNameResolver; -use Rector\NodeTypeResolver\TypeComparator\TypeComparator; use Rector\PhpParser\AstResolver; -use Rector\StaticTypeMapper\StaticTypeMapper; final readonly class CallerParamMatcher { public function __construct( private NodeNameResolver $nodeNameResolver, - private AstResolver $astResolver, - private StaticTypeMapper $staticTypeMapper, - private TypeComparator $typeComparator + private AstResolver $astResolver ) { } - public function matchCallParamType( - Param $param, - Param $callParam - ): null|Identifier|Name|NullableType|UnionType|ComplexType { - if (! $callParam->type instanceof Node) { - return null; - } - - if (! $param->default instanceof Expr && ! $callParam->default instanceof Expr) { - // skip as mixed is not helpful and possibly requires more precise change elsewhere - if ($this->isCallParamMixed($callParam->type)) { - return null; - } - - return $callParam->type; - } - - $default = $param->default ?? $callParam->default; - if (! $default instanceof Expr) { - return null; - } - - $callParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($callParam->type); - $defaultType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($default); - - if ($this->typeComparator->areTypesEqual($callParamType, $defaultType)) { - return $callParam->type; - } - - if ($this->typeComparator->isSubtype($defaultType, $callParamType)) { - return $callParam->type; - } - - if (! $defaultType->isNull()->yes()) { - return null; - } - - if ($callParam->type instanceof Name || $callParam->type instanceof Identifier) { - return new NullableType($callParam->type); - } - - if ($callParam->type instanceof IntersectionType || $callParam->type instanceof UnionType) { - return new UnionType([...$callParam->type->types, new Identifier('null')]); - } - - return null; - } - public function matchParentParam(StaticCall $parentStaticCall, Param $param, Scope $scope): ?Param { $methodName = $this->nodeNameResolver->getName($parentStaticCall->name); @@ -101,22 +38,7 @@ public function matchParentParam(StaticCall $parentStaticCall, Param $param, Sco return $this->resolveParentMethodParam($scope, $methodName, $parentStaticCallArgPosition); } - public function matchCallParam(StaticCall|MethodCall|FuncCall $call, Param $param): ?Param - { - $callArgPosition = $this->matchCallArgPosition($call, $param); - if ($callArgPosition === null) { - return null; - } - - $classMethodOrFunction = $this->astResolver->resolveClassMethodOrFunctionFromCall($call); - if ($classMethodOrFunction === null) { - return null; - } - - return $classMethodOrFunction->params[$callArgPosition] ?? null; - } - - private function matchCallArgPosition(StaticCall|MethodCall|FuncCall $call, Param $param): int|null + private function matchCallArgPosition(StaticCall $call, Param $param): int|null { $paramName = $this->nodeNameResolver->getName($param); @@ -161,10 +83,4 @@ private function resolveParentMethodParam(Scope $scope, string $methodName, int return null; } - - private function isCallParamMixed(Node $node): bool - { - $callParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($node); - return $callParamType instanceof MixedType; - } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/AbstractParamTypeByMethodCallTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/AbstractParamTypeByMethodCallTypeRector.php index ac46f5b8946..5cb376aacb2 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/AbstractParamTypeByMethodCallTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/AbstractParamTypeByMethodCallTypeRector.php @@ -7,42 +7,13 @@ use PhpParser\Node; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; -use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Expr\MethodCall; -use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; -use PHPStan\Analyser\Scope; -use PHPStan\Type\Type; -use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\NodeTypeResolver\PHPStan\Type\TypeFactory; -use Rector\PhpParser\Node\BetterNodeFinder; -use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; -use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper; -use Rector\StaticTypeMapper\StaticTypeMapper; -use Rector\TypeDeclaration\Guard\ParamTypeAddGuard; -use Rector\TypeDeclaration\NodeAnalyzer\CallerParamMatcher; -use Rector\VendorLocker\ParentClassMethodTypeOverrideGuard; -/** - * Shared engine for adding a param type based on the type of the caller argument. - * Concrete rules narrow the change to a single type group via isMatchingParamType(). - */ abstract class AbstractParamTypeByMethodCallTypeRector extends AbstractRector { - public function __construct( - private readonly CallerParamMatcher $callerParamMatcher, - private readonly ParentClassMethodTypeOverrideGuard $parentClassMethodTypeOverrideGuard, - private readonly ParamTypeAddGuard $paramTypeAddGuard, - private readonly BetterNodeFinder $betterNodeFinder, - private readonly PhpParserNodeMapper $phpParserNodeMapper, - private readonly StaticTypeMapper $staticTypeMapper, - private readonly TypeFactory $typeFactory - ) { - } - /** * @return array> */ @@ -56,158 +27,9 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - if ($node->params === []) { - return null; - } - - // has params with at least one missing type - if (! $this->hasAtLeastOneParamWithoutType($node)) { - return null; - } - - if ($node instanceof ClassMethod && $this->shouldSkipClassMethod($node)) { - return null; - } - - /** @var array $callers */ - $callers = $this->betterNodeFinder->findInstancesOfScoped( - [$node], - [StaticCall::class, MethodCall::class, FuncCall::class] - ); - - // keep only callers with args - $callersWithArgs = array_filter( - $callers, - fn (StaticCall|MethodCall|FuncCall $caller): bool => $caller->args !== [] - ); - - if ($callersWithArgs === []) { - return null; - } - - $hasChanged = $this->refactorFunctionLike($node, $callersWithArgs); - if ($hasChanged) { - return $node; - } - - return null; - } - - /** - * Decide whether the inferred param type belongs to this rule's type group. - */ - abstract protected function isMatchingParamType(Type $type): bool; - - private function shouldSkipClassMethod(ClassMethod $classMethod): bool - { - // trait method can be used in a class that requires a contract type, adding a param type would break it - $scope = $classMethod->getAttribute(AttributeKey::SCOPE); - if ($scope instanceof Scope && $scope->isInTrait()) { - return true; - } - - // user-guarded class: adding a param type here would break its child classes - if ($this->parentClassMethodTypeOverrideGuard->isTypeGuardedClass($classMethod)) { - return true; - } - - $isMissingParameterTypes = false; - foreach ($classMethod->params as $param) { - if ($param->type instanceof Node) { - continue; - } - - if ($param->variadic) { - continue; - } - - $isMissingParameterTypes = true; - } - - if ($isMissingParameterTypes === false) { - return true; - } - - return $this->parentClassMethodTypeOverrideGuard->hasParentClassMethod($classMethod); - } - - private function shouldSkipParam( - Param $param, - ClassMethod|Function_|Closure|ArrowFunction $functionLike - ): bool { - // already has type, skip - if ($param->type instanceof Node) { - return true; - } - - if ($param->variadic) { - return true; - } - - return ! $this->paramTypeAddGuard->isLegal($param, $functionLike); - } - - /** - * @param array $callers - */ - private function refactorFunctionLike( - ClassMethod|Closure|Function_|ArrowFunction $functionLike, - array $callers - ): bool { - $hasChanged = false; - - foreach ($functionLike->params as $param) { - if ($this->shouldSkipParam($param, $functionLike)) { - continue; - } - - $paramTypes = []; - foreach ($callers as $caller) { - $matchCallParam = $this->callerParamMatcher->matchCallParam($caller, $param); - - // nothing to do with param, continue - if (! $matchCallParam instanceof Param) { - continue; - } - - $paramType = $this->callerParamMatcher->matchCallParamType($param, $matchCallParam); - if (! $paramType instanceof Node) { - $paramTypes = []; - break; - } - - if ($caller->getAttribute(AttributeKey::IS_RIGHT_AND)) { - $paramTypes = []; - break; - } - - $paramTypes[] = $this->phpParserNodeMapper->mapToPHPStanType($paramType); - } - - if ($paramTypes === []) { - continue; - } - - $type = $this->typeFactory->createMixedPassedOrUnionType($paramTypes); - - // only handle the type group owned by this rule - if (! $this->isMatchingParamType($type)) { - continue; - } - - $paramNodeType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::PARAM); - - if ($paramNodeType instanceof Node) { - $param->type = $paramNodeType; - $hasChanged = true; - } - } - - return $hasChanged; - } - - private function hasAtLeastOneParamWithoutType(ClassMethod|Function_|Closure|ArrowFunction $functionLike): bool - { - return array_any($functionLike->params, fn (Param $param): bool => ! $param->type instanceof Node); + throw new ShouldNotHappenException(sprintf( + '"%s" rule is deprecated, as it fills invalid types and can cause type errors on controllers and other input calls; use static analysis to verify types instead', + static::class + )); } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector.php index c590f2af621..256dbe76497 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ArrayParamTypeByMethodCallTypeRector.php @@ -4,17 +4,14 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; -use PHPStan\Type\Type; -use PHPStan\Type\TypeCombinator; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * Handles the array param type group, including nullable arrays. - * - * @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector\ArrayParamTypeByMethodCallTypeRectorTest + * @deprecated This rule is deprecated, as it fills invalid types and can cause type errors on controllers and other input calls. Inferring param types from a single caller is unreliable and needs human verification, so this better suits static analysis. */ -final class ArrayParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector +final class ArrayParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -66,10 +63,4 @@ public function go(array $value) ), ]); } - - protected function isMatchingParamType(Type $type): bool - { - return TypeCombinator::removeNull($type)->isArray() - ->yes(); - } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector.php index 3f5ff4227dd..f4033ec3d4d 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ObjectParamTypeByMethodCallTypeRector.php @@ -4,17 +4,14 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; -use PHPStan\Type\Type; -use PHPStan\Type\TypeCombinator; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * Handles the object param type group. - * - * @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector\ObjectParamTypeByMethodCallTypeRectorTest + * @deprecated This rule is deprecated, as it fills invalid types and can cause type errors on controllers and other input calls. Inferring param types from a single caller is unreliable and needs human verification, so this better suits static analysis. */ -final class ObjectParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector +final class ObjectParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -66,10 +63,4 @@ public function go(SomeObject $value) ), ]); } - - protected function isMatchingParamType(Type $type): bool - { - return TypeCombinator::removeNull($type)->isObject() - ->yes(); - } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php index 092d2fa3f97..5539463c727 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByMethodCallTypeRector.php @@ -4,21 +4,14 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; -use PHPStan\Type\Type; -use PHPStan\Type\TypeCombinator; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * Handles the remaining compound param type group: everything that is neither a pure object, - * a pure scalar, nor a pure array (e.g. cross-group unions like array|string, iterable, callable). - * - * @see \Rector\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector for object types - * @see \Rector\TypeDeclaration\Rector\ClassMethod\ScalarParamTypeByMethodCallTypeRector for scalar types - * @see \Rector\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector for array types - * @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector\ParamTypeByMethodCallTypeRectorTest + * @deprecated This rule is deprecated, as it fills invalid types and can cause type errors on controllers and other input calls. Inferring param types from a single caller is unreliable and needs human verification, so this better suits static analysis. */ -final class ParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector +final class ParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -70,17 +63,4 @@ public function go(iterable $value) ), ]); } - - protected function isMatchingParamType(Type $type): bool - { - $bareType = TypeCombinator::removeNull($type); - - // remaining compound types: not a pure object, scalar, nor array (iterable, callable, cross-group unions) - return ! $bareType->isObject() - ->yes() - && ! $bareType->isScalar() - ->yes() - && ! $bareType->isArray() - ->yes(); - } } diff --git a/rules/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector.php b/rules/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector.php index 30832bec1d9..1cf126d77cc 100644 --- a/rules/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector.php +++ b/rules/TypeDeclaration/Rector/ClassMethod/ScalarParamTypeByMethodCallTypeRector.php @@ -4,17 +4,14 @@ namespace Rector\TypeDeclaration\Rector\ClassMethod; -use PHPStan\Type\Type; -use PHPStan\Type\TypeCombinator; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** - * Handles the scalar (string/int/float/bool) param type group. - * - * @see \Rector\Tests\TypeDeclaration\Rector\ClassMethod\ScalarParamTypeByMethodCallTypeRector\ScalarParamTypeByMethodCallTypeRectorTest + * @deprecated This rule is deprecated, as it fills invalid types and can cause type errors on controllers and other input calls. Inferring param types from a single caller is unreliable and needs human verification, so this better suits static analysis. */ -final class ScalarParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector +final class ScalarParamTypeByMethodCallTypeRector extends AbstractParamTypeByMethodCallTypeRector implements DeprecatedInterface { public function getRuleDefinition(): RuleDefinition { @@ -66,17 +63,4 @@ public function go(int $value) ), ]); } - - protected function isMatchingParamType(Type $type): bool - { - $type = TypeCombinator::removeNull($type); - if (! $type->isScalar()->yes()) { - return false; - } - - // a string param accepts int/float/bool via scalar coercion, so a caller - // may pass another scalar - inferring string from it would be unsafe - return ! $type->isString() - ->yes(); - } } diff --git a/src/Config/Level/TypeDeclarationLevel.php b/src/Config/Level/TypeDeclarationLevel.php index 97f02a56430..ba3780a6150 100644 --- a/src/Config/Level/TypeDeclarationLevel.php +++ b/src/Config/Level/TypeDeclarationLevel.php @@ -29,7 +29,6 @@ use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector; use Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeFromTryCatchTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromBooleanConstAndStrictReturnsRector; use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromBooleanConstReturnsRector; use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromBooleanStrictReturnsRector; @@ -37,8 +36,6 @@ use Rector\TypeDeclaration\Rector\ClassMethod\NarrowObjectReturnTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictReturnsRector; use Rector\TypeDeclaration\Rector\ClassMethod\NumericReturnTypeFromStrictScalarReturnsRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ObjectParamTypeByMethodCallTypeRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; @@ -57,7 +54,6 @@ use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedPropertyRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromSymfonySerializerRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector; -use Rector\TypeDeclaration\Rector\ClassMethod\ScalarParamTypeByMethodCallTypeRector; use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector; use Rector\TypeDeclaration\Rector\ClassMethod\StringReturnTypeFromStrictScalarReturnsRector; use Rector\TypeDeclaration\Rector\ClassMethod\StringReturnTypeFromStrictStringReturnsRector; @@ -168,10 +164,6 @@ final class TypeDeclarationLevel AddParamTypeFromPropertyTypeRector::class, MergeDateTimePropertyTypeDeclarationRector::class, PropertyTypeFromStrictSetterGetterRector::class, - ParamTypeByMethodCallTypeRector::class, - ObjectParamTypeByMethodCallTypeRector::class, - ScalarParamTypeByMethodCallTypeRector::class, - ArrayParamTypeByMethodCallTypeRector::class, TypedPropertyFromContainerGetSetUpRector::class, TypedPropertyFromGetRepositorySetUpRector::class, TypedPropertyFromAssignsRector::class, diff --git a/src/PhpParser/AstResolver.php b/src/PhpParser/AstResolver.php index 58e1d84510c..3d4f8810a1b 100644 --- a/src/PhpParser/AstResolver.php +++ b/src/PhpParser/AstResolver.php @@ -5,27 +5,21 @@ namespace Rector\PhpParser; use PhpParser\Node; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\NullsafeMethodCall; use PhpParser\Node\Expr\StaticCall; -use PhpParser\Node\Name; use PhpParser\Node\Param; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Enum_; -use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Interface_; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Trait_; use PHPStan\Reflection\ClassReflection; -use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\MethodReflection; -use PHPStan\Reflection\Php\PhpFunctionReflection; use PHPStan\Reflection\Php\PhpPropertyReflection; use PHPStan\Reflection\ReflectionProvider; use Rector\NodeNameResolver\NodeNameResolver; @@ -111,42 +105,6 @@ function (Node $node) use ($classLikeName, $methodName, &$classMethod): bool { return $classMethod; } - public function resolveClassMethodOrFunctionFromCall( - FuncCall|StaticCall|MethodCall|New_|NullsafeMethodCall $call - ): ClassMethod|Function_|null { - if ($call instanceof FuncCall) { - return $this->resolveFunctionFromFuncCall($call); - } - - return $this->resolveClassMethodFromCall($call); - } - - public function resolveFunctionFromFunctionReflection(FunctionReflection $functionReflection): ?Function_ - { - if (! $functionReflection instanceof PhpFunctionReflection) { - return null; - } - - $fileName = $functionReflection->getFileName(); - $nodes = $this->parseFileNameToDecoratedNodes($fileName); - - $functionName = $functionReflection->getName(); - - /** @var Function_|null $functionNode */ - $functionNode = $this->betterNodeFinder->findFirst( - $nodes, - function (Node $node) use ($functionName): bool { - if (! $node instanceof Function_) { - return false; - } - - return $this->nodeNameResolver->isName($node, $functionName); - } - ); - - return $functionNode; - } - /** * @param class-string $className */ @@ -404,19 +362,4 @@ function (Node $node) use ($desiredClassName, $desiredPropertyName, &$paramNode) return $paramNode; } - - private function resolveFunctionFromFuncCall(FuncCall $funcCall): ?Function_ - { - if ($funcCall->name instanceof Expr) { - return null; - } - - $functionName = new Name((string) $this->nodeNameResolver->getName($funcCall)); - if (! $this->reflectionProvider->hasFunction($functionName, null)) { - return null; - } - - $functionReflection = $this->reflectionProvider->getFunction($functionName, null); - return $this->resolveFunctionFromFunctionReflection($functionReflection); - } }