From 34faa5131cd77de90f06f8b00e383f15bff75d1a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 19 Oct 2026 00:12:34 +0200 Subject: [PATCH] Deprecate DowngradeParameterTypeWideningRector Used for Symfony container internals, no longer needed nor safe as it depends on autoload order. Mark with DeprecatedInterface, drop from downgrade-php72 set, and remove now-orphaned analyzers and obsolete tests. --- config/set/downgrade-php72.php | 2 - ...wngradeParameterTypeWideningRectorTest.php | 28 --- .../Fixture/anonymous_class.php.inc | 55 ------ .../anonymous_class_alternative.php.inc | 65 ------- ...nonymous_return_abstract_interface.php.inc | 57 ------ .../Fixture/container_has_interface.php.inc | 50 ----- .../default_null_not_part_of_union.php.inc | 33 ---- .../Fixture/fixture.php.inc | 53 ------ .../Fixture/include_used_trait.php.inc | 40 ---- .../Fixture/interface_on_parent_class.php.inc | 48 ----- .../Fixture/nullable_callable_value.php.inc | 36 ---- .../Source/AnotherContainerInterface.php | 10 - .../Source/AnyService.php | 9 - .../Source/ParentNullableString.php | 12 -- .../Source/SomeExternalContainerInterface.php | 10 - .../Source/UniqueType.php | 8 - .../Source/vendor/NullableStringTrait.php | 12 -- .../config/configured_rule.php | 10 - .../NodeAnalyzer/BuiltInMethodAnalyzer.php | 40 ---- ...errideFromAnonymousClassMethodAnalyzer.php | 86 --------- .../NodeAnalyzer/SealedClassAnalyzer.php | 26 --- .../PhpDoc/NativeParamToPhpDocDecorator.php | 75 -------- .../DowngradeParameterTypeWideningRector.php | 171 +----------------- .../Fixture/fixture.php.inc | 42 ----- .../both_parent_child_typed.php.inc | 51 ------ ...ade_param_reflection_get_attribute.php.inc | 44 ----- .../FixtureDownToPhp71/fixture.php.inc | 42 ----- .../IssueDowngradeParamTypeTest.php | 28 --- .../IssueDowngradeParamTypeToPhp71Test.php | 28 --- .../config/configured_rule.php | 13 -- ...onfigured_rule_downgrade_down_to_php71.php | 11 -- 31 files changed, 8 insertions(+), 1187 deletions(-) delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/DowngradeParameterTypeWideningRectorTest.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class_alternative.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_return_abstract_interface.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/container_has_interface.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/default_null_not_part_of_union.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/fixture.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/include_used_trait.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/interface_on_parent_class.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/nullable_callable_value.php.inc delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/AnotherContainerInterface.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/AnyService.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/ParentNullableString.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/SomeExternalContainerInterface.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/UniqueType.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/vendor/NullableStringTrait.php delete mode 100644 rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/config/configured_rule.php delete mode 100644 rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php delete mode 100644 rules/DowngradePhp72/NodeAnalyzer/OverrideFromAnonymousClassMethodAnalyzer.php delete mode 100644 rules/DowngradePhp72/NodeAnalyzer/SealedClassAnalyzer.php delete mode 100644 rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php delete mode 100644 tests/Issues/IssueDowngradeParamType/Fixture/fixture.php.inc delete mode 100644 tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/both_parent_child_typed.php.inc delete mode 100644 tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/downgrade_param_reflection_get_attribute.php.inc delete mode 100644 tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/fixture.php.inc delete mode 100644 tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeTest.php delete mode 100644 tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeToPhp71Test.php delete mode 100644 tests/Issues/IssueDowngradeParamType/config/configured_rule.php delete mode 100644 tests/Issues/IssueDowngradeParamType/config/configured_rule_downgrade_down_to_php71.php diff --git a/config/set/downgrade-php72.php b/config/set/downgrade-php72.php index 8d14e435..a7083e12 100644 --- a/config/set/downgrade-php72.php +++ b/config/set/downgrade-php72.php @@ -4,7 +4,6 @@ use Rector\Config\RectorConfig; use Rector\ValueObject\PhpVersion; -use Rector\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector; use Rector\DowngradePhp72\Rector\ConstFetch\DowngradePhp72JsonConstRector; use Rector\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector; use Rector\DowngradePhp72\Rector\FuncCall\DowngradePregUnmatchedAsNullConstantRector; @@ -16,7 +15,6 @@ $rectorConfig->rules([ DowngradeObjectTypeDeclarationRector::class, - DowngradeParameterTypeWideningRector::class, DowngradePregUnmatchedAsNullConstantRector::class, DowngradeStreamIsattyRector::class, DowngradeJsonDecodeNullAssociativeArgRector::class, diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/DowngradeParameterTypeWideningRectorTest.php b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/DowngradeParameterTypeWideningRectorTest.php deleted file mode 100644 index 26843d3d..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/DowngradeParameterTypeWideningRectorTest.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/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class.php.inc deleted file mode 100644 index 550b87fd..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class.php.inc +++ /dev/null @@ -1,55 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class_alternative.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class_alternative.php.inc deleted file mode 100644 index 557fe49d..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_class_alternative.php.inc +++ /dev/null @@ -1,65 +0,0 @@ -doSomethingElse(); - }) implements SomeInterface { - public function hello(string $world = 'world') { - printf('Hi %s', $world); - } - }; - } - - public function doSomethingElse(): void - { - print('Hello again'); - } -} - -?> ------ -doSomethingElse(); - }) implements SomeInterface { - /** - * @param string $world - */ - public function hello($world = 'world') { - printf('Hi %s', $world); - } - }; - } - - public function doSomethingElse(): void - { - print('Hello again'); - } -} - -?> diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_return_abstract_interface.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_return_abstract_interface.php.inc deleted file mode 100644 index 5694ab81..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/anonymous_return_abstract_interface.php.inc +++ /dev/null @@ -1,57 +0,0 @@ -test2($file); - } -}; - -?> ------ -test2($file); - } -}; - -?> diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/container_has_interface.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/container_has_interface.php.inc deleted file mode 100644 index ec354053..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/container_has_interface.php.inc +++ /dev/null @@ -1,50 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/default_null_not_part_of_union.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/default_null_not_part_of_union.php.inc deleted file mode 100644 index 35ae95c4..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/default_null_not_part_of_union.php.inc +++ /dev/null @@ -1,33 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/fixture.php.inc deleted file mode 100644 index dda1af36..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/fixture.php.inc +++ /dev/null @@ -1,53 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/include_used_trait.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/include_used_trait.php.inc deleted file mode 100644 index a824feba..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/include_used_trait.php.inc +++ /dev/null @@ -1,40 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/interface_on_parent_class.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/interface_on_parent_class.php.inc deleted file mode 100644 index 033cd38b..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/interface_on_parent_class.php.inc +++ /dev/null @@ -1,48 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/nullable_callable_value.php.inc b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/nullable_callable_value.php.inc deleted file mode 100644 index 1c9b09bb..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Fixture/nullable_callable_value.php.inc +++ /dev/null @@ -1,36 +0,0 @@ - ------ - diff --git a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/AnotherContainerInterface.php b/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/AnotherContainerInterface.php deleted file mode 100644 index 95199fe7..00000000 --- a/rules-tests/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector/Source/AnotherContainerInterface.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(DowngradeParameterTypeWideningRector::class); -}; diff --git a/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php b/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php deleted file mode 100644 index b842670a..00000000 --- a/rules/DowngradePhp72/NodeAnalyzer/BuiltInMethodAnalyzer.php +++ /dev/null @@ -1,40 +0,0 @@ -isClass()) { - return false; - } - - $methodName = $this->nodeNameResolver->getName($classMethod); - - foreach ($classReflection->getInterfaces() as $interfaceReflection) { - if (! $interfaceReflection->isBuiltin()) { - continue; - } - - if (! $interfaceReflection->hasMethod($methodName)) { - continue; - } - - return true; - } - - return false; - } -} diff --git a/rules/DowngradePhp72/NodeAnalyzer/OverrideFromAnonymousClassMethodAnalyzer.php b/rules/DowngradePhp72/NodeAnalyzer/OverrideFromAnonymousClassMethodAnalyzer.php deleted file mode 100644 index bd69cfac..00000000 --- a/rules/DowngradePhp72/NodeAnalyzer/OverrideFromAnonymousClassMethodAnalyzer.php +++ /dev/null @@ -1,86 +0,0 @@ -classAnalyzer->isAnonymousClass($classLike)) { - return null; - } - - /** @var Class_ $classLike */ - $interfaces = $classLike->implements; - foreach ($interfaces as $interface) { - if (! $interface instanceof FullyQualified) { - continue; - } - - $resolve = $this->resolveClassReflectionWithNotPrivateMethod($interface, $classMethod); - if ($resolve instanceof ClassReflection) { - return $resolve; - } - } - - /** @var Class_ $classLike */ - if (! $classLike->extends instanceof FullyQualified) { - return null; - } - - return $this->resolveClassReflectionWithNotPrivateMethod($classLike->extends, $classMethod); - } - - private function resolveClassReflectionWithNotPrivateMethod( - FullyQualified $fullyQualified, - ClassMethod $classMethod - ): ?ClassReflection { - $ancestorClassLike = $fullyQualified->toString(); - if (! $this->reflectionProvider->hasClass($ancestorClassLike)) { - return null; - } - - $classReflection = $this->reflectionProvider->getClass($ancestorClassLike); - $methodName = $this->nodeNameResolver->getName($classMethod); - if (! $classReflection->hasMethod($methodName)) { - return null; - } - - /** @var ClassMemberAccessAnswerer $scope */ - $scope = $classMethod->getAttribute(AttributeKey::SCOPE); - - $extendedMethodReflection = $classReflection->getMethod($methodName, $scope); - if (! $extendedMethodReflection instanceof PhpMethodReflection) { - return null; - } - - if ($extendedMethodReflection->isPrivate()) { - return null; - } - - return $classReflection; - } -} diff --git a/rules/DowngradePhp72/NodeAnalyzer/SealedClassAnalyzer.php b/rules/DowngradePhp72/NodeAnalyzer/SealedClassAnalyzer.php deleted file mode 100644 index ea6cf4bc..00000000 --- a/rules/DowngradePhp72/NodeAnalyzer/SealedClassAnalyzer.php +++ /dev/null @@ -1,26 +0,0 @@ -isClass()) { - return false; - } - - if (! $classReflection->isFinal()) { - return false; - } - - return count($classReflection->getAncestors()) === 1; - } -} diff --git a/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php b/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php deleted file mode 100644 index a59ece69..00000000 --- a/rules/DowngradePhp72/PhpDoc/NativeParamToPhpDocDecorator.php +++ /dev/null @@ -1,75 +0,0 @@ -type instanceof Node) { - return; - } - - $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod); - - $paramName = $this->nodeNameResolver->getName($param); - - $mappedCurrentParamType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type); - $correctedNullableParamType = $this->correctNullableType($param, $mappedCurrentParamType); - - $this->phpDocTypeChanger->changeParamType( - $classMethod, - $phpDocInfo, - $correctedNullableParamType, - $param, - $paramName - ); - } - - private function isParamNullable(Param $param): bool - { - if (! $param->default instanceof Expr) { - return false; - } - - return $this->valueResolver->isNull($param->default); - } - - private function correctNullableType(Param $param, Type $paramType): UnionType|Type - { - if (! $this->isParamNullable($param)) { - return $paramType; - } - - if (TypeCombinator::containsNull($paramType)) { - return $paramType; - } - - // add default null type - return TypeCombinator::addNull($paramType); - } -} diff --git a/rules/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php b/rules/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php index ddf0aa3e..2c239984 100644 --- a/rules/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php +++ b/rules/DowngradePhp72/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php @@ -5,45 +5,19 @@ namespace Rector\DowngradePhp72\Rector\ClassMethod; use PhpParser\Node; -use PhpParser\Node\Param; use PhpParser\Node\Stmt\ClassLike; -use PhpParser\Node\Stmt\ClassMethod; -use PHPStan\Reflection\ClassReflection; +use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Rector\Contract\Rector\ConfigurableRectorInterface; -use Rector\DowngradePhp72\NodeAnalyzer\BuiltInMethodAnalyzer; -use Rector\DowngradePhp72\NodeAnalyzer\OverrideFromAnonymousClassMethodAnalyzer; -use Rector\DowngradePhp72\NodeAnalyzer\SealedClassAnalyzer; -use Rector\DowngradePhp72\PhpDoc\NativeParamToPhpDocDecorator; +use Rector\Exception\ShouldNotHappenException; use Rector\Rector\AbstractRector; -use Rector\Reflection\ReflectionResolver; use Rector\RuleDoc\CodeSample\ConfiguredCodeSample; use Rector\RuleDoc\RuleDefinition; -use Rector\TypeDeclaration\NodeAnalyzer\AutowiredClassMethodOrPropertyAnalyzer; -use Webmozart\Assert\Assert; /** - * @changelog https://www.php.net/manual/en/migration72.new-features.php#migration72.new-features.param-type-widening - * @changelog https://3v4l.org/fOgSE - * - * @see \Rector\Tests\DowngradePhp72\Rector\ClassMethod\DowngradeParameterTypeWideningRector\DowngradeParameterTypeWideningRectorTest + * @deprecated Used for Symfony container internals, no longer needed nor safe as it depends on autoload order. */ -final class DowngradeParameterTypeWideningRector extends AbstractRector implements ConfigurableRectorInterface +final class DowngradeParameterTypeWideningRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface { - /** - * @var array - */ - private array $unsafeTypesToMethods = []; - - public function __construct( - private readonly NativeParamToPhpDocDecorator $nativeParamToPhpDocDecorator, - private readonly ReflectionResolver $reflectionResolver, - private readonly AutowiredClassMethodOrPropertyAnalyzer $autowiredClassMethodOrPropertyAnalyzer, - private readonly BuiltInMethodAnalyzer $builtInMethodAnalyzer, - private readonly OverrideFromAnonymousClassMethodAnalyzer $overrideFromAnonymousClassMethodAnalyzer, - private readonly SealedClassAnalyzer $sealedClassAnalyzer - ) { - } - public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change param type to match the lowest type in whole family tree', [ @@ -79,7 +53,6 @@ public function test($input) , [ 'ContainerInterface' => ['set', 'get', 'has', 'initialized'], - 'SomeContainerInterface' => ['set', 'has'], ] ), ]); @@ -98,38 +71,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { - $hasChanged = false; - - foreach ($node->getMethods() as $method) { - $ancestorOverridableAnonymousClass = $this->overrideFromAnonymousClassMethodAnalyzer->matchAncestorClassReflectionOverridable( - $node, - $method - ); - - if ($ancestorOverridableAnonymousClass instanceof ClassReflection) { - $classMethod = $this->processRemoveParamTypeFromMethod($ancestorOverridableAnonymousClass, $method); - - if ($classMethod instanceof ClassMethod) { - $hasChanged = true; - continue; - } - - continue; - } - - $classReflection = $this->reflectionResolver->resolveClassAndAnonymousClass($node); - $classMethod = $this->processRemoveParamTypeFromMethod($classReflection, $method); - - if ($classMethod instanceof ClassMethod) { - $hasChanged = true; - } - } - - if ($hasChanged) { - return $node; - } - - return null; + throw new ShouldNotHappenException(sprintf( + '"%s" is deprecated, as used for Symfony container internals and no longer safe - it depends on autoload order', + self::class + )); } /** @@ -137,105 +82,5 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - $unsafeTypesToMethods = $configuration; - - foreach ($unsafeTypesToMethods as $key => $value) { - Assert::string($key); - Assert::isArray($value); - Assert::allString($value); - } - - $this->unsafeTypesToMethods = $unsafeTypesToMethods; - } - - private function shouldSkip(ClassReflection $classReflection, ClassMethod $classMethod): bool - { - if ($classMethod->params === []) { - return true; - } - - if ($classMethod->isPrivate()) { - return true; - } - - if ($classMethod->isMagic()) { - return true; - } - - if ($this->sealedClassAnalyzer->isSealedClass($classReflection)) { - return true; - } - - if ($this->autowiredClassMethodOrPropertyAnalyzer->detect($classMethod)) { - return true; - } - - if ($this->hasParamAlreadyNonTyped($classMethod)) { - return true; - } - - return $this->isSafeType($classReflection, $classMethod); - } - - private function processRemoveParamTypeFromMethod( - ClassReflection $classReflection, - ClassMethod $classMethod - ): ?ClassMethod { - if ($this->shouldSkip($classReflection, $classMethod)) { - return null; - } - - if ($this->builtInMethodAnalyzer->isImplementsBuiltInInterface($classReflection, $classMethod)) { - return null; - } - - // Downgrade every scalar parameter, just to be sure - foreach (array_keys($classMethod->params) as $paramPosition) { - $this->removeParamTypeFromMethod($classMethod, $paramPosition); - } - - return $classMethod; - } - - private function removeParamTypeFromMethod(ClassMethod $classMethod, int $paramPosition): void - { - $param = $classMethod->params[$paramPosition] ?? null; - if (! $param instanceof Param) { - return; - } - - // Add the current type in the PHPDoc - $this->nativeParamToPhpDocDecorator->decorate($classMethod, $param); - $param->type = null; - } - - private function hasParamAlreadyNonTyped(ClassMethod $classMethod): bool - { - return array_all($classMethod->params, static fn (Param $param): bool => ! $param->type instanceof Node); - } - - private function isSafeType(ClassReflection $classReflection, ClassMethod $classMethod): bool - { - if ($this->unsafeTypesToMethods === []) { - return false; - } - - $classReflectionName = $classReflection->getName(); - foreach ($this->unsafeTypesToMethods as $unsafeType => $unsafeMethods) { - if (! $this->isNames($classMethod, $unsafeMethods)) { - continue; - } - - if ($classReflection->is($unsafeType)) { - return false; - } - - // skip self too - if ($classReflectionName === $unsafeType) { - return false; - } - } - - return true; } } diff --git a/tests/Issues/IssueDowngradeParamType/Fixture/fixture.php.inc b/tests/Issues/IssueDowngradeParamType/Fixture/fixture.php.inc deleted file mode 100644 index c4af35c4..00000000 --- a/tests/Issues/IssueDowngradeParamType/Fixture/fixture.php.inc +++ /dev/null @@ -1,42 +0,0 @@ - ------ - diff --git a/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/both_parent_child_typed.php.inc b/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/both_parent_child_typed.php.inc deleted file mode 100644 index 98827eb5..00000000 --- a/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/both_parent_child_typed.php.inc +++ /dev/null @@ -1,51 +0,0 @@ - ------ - diff --git a/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/downgrade_param_reflection_get_attribute.php.inc b/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/downgrade_param_reflection_get_attribute.php.inc deleted file mode 100644 index 39f9de61..00000000 --- a/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/downgrade_param_reflection_get_attribute.php.inc +++ /dev/null @@ -1,44 +0,0 @@ -getFileName(); - - if ($reflectionClass->getAttributes()) { - return true; - } - return false; - } -} - -?> ------ -getFileName(); - - if (method_exists($reflectionClass, 'getAttributes') ? $reflectionClass->getAttributes() : []) { - return true; - } - return false; - } -} - -?> diff --git a/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/fixture.php.inc b/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/fixture.php.inc deleted file mode 100644 index c4af35c4..00000000 --- a/tests/Issues/IssueDowngradeParamType/FixtureDownToPhp71/fixture.php.inc +++ /dev/null @@ -1,42 +0,0 @@ - ------ - diff --git a/tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeTest.php b/tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeTest.php deleted file mode 100644 index 161d9933..00000000 --- a/tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeTest.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/tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeToPhp71Test.php b/tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeToPhp71Test.php deleted file mode 100644 index 2f1b80f3..00000000 --- a/tests/Issues/IssueDowngradeParamType/IssueDowngradeParamTypeToPhp71Test.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/FixtureDownToPhp71'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule_downgrade_down_to_php71.php'; - } -} diff --git a/tests/Issues/IssueDowngradeParamType/config/configured_rule.php b/tests/Issues/IssueDowngradeParamType/config/configured_rule.php deleted file mode 100644 index 79a2aa98..00000000 --- a/tests/Issues/IssueDowngradeParamType/config/configured_rule.php +++ /dev/null @@ -1,13 +0,0 @@ -importNames(); - $rectorConfig->rule(DowngradeTrailingCommasInParamUseRector::class); - $rectorConfig->rule(DowngradeParameterTypeWideningRector::class); -}; diff --git a/tests/Issues/IssueDowngradeParamType/config/configured_rule_downgrade_down_to_php71.php b/tests/Issues/IssueDowngradeParamType/config/configured_rule_downgrade_down_to_php71.php deleted file mode 100644 index 765ec71e..00000000 --- a/tests/Issues/IssueDowngradeParamType/config/configured_rule_downgrade_down_to_php71.php +++ /dev/null @@ -1,11 +0,0 @@ -importNames(); - $rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_71]); -};