From dbc2a05680f9c51a1eaef978fe6ef030a34f80ef Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 10 Apr 2025 13:10:35 +0200 Subject: [PATCH 1/3] DeprecationHelper: phase 1 --- rules.neon | 10 +++++ .../AccessDeprecatedPropertyRule.php | 11 +++-- .../AccessDeprecatedStaticPropertyRule.php | 10 +++-- .../CallToDeprecatedFunctionRule.php | 10 +++-- .../CallToDeprecatedMethodRule.php | 10 +++-- .../CallToDeprecatedStaticMethodRule.php | 15 ++++--- .../DefaultDeprecatedScopeResolver.php | 13 ++++-- .../DefaultDeprecationProvider.php | 40 ++++++++++++++++++ .../Deprecations/DeprecatedClassHelper.php | 14 +++++-- src/Rules/Deprecations/Deprecation.php | 38 +++++++++++++++++ src/Rules/Deprecations/DeprecationHelper.php | 41 +++++++++++++++++++ .../Deprecations/DeprecationProvider.php | 19 +++++++++ ...etchingClassConstOfDeprecatedClassRule.php | 15 ++++--- .../FetchingDeprecatedConstRule.php | 10 +++-- ...mplementationOfDeprecatedInterfaceRule.php | 13 ++++-- .../InheritanceOfDeprecatedClassRule.php | 10 +++-- .../InheritanceOfDeprecatedInterfaceRule.php | 13 ++++-- .../InstantiationOfDeprecatedClassRule.php | 10 +++-- .../UsageOfDeprecatedCastRule.php | 11 +++-- .../UsageOfDeprecatedTraitRule.php | 10 +++-- .../CallToDeprecatedMethodRuleTest.php | 4 +- 21 files changed, 275 insertions(+), 52 deletions(-) create mode 100644 src/Rules/Deprecations/DefaultDeprecationProvider.php create mode 100644 src/Rules/Deprecations/Deprecation.php create mode 100644 src/Rules/Deprecations/DeprecationHelper.php create mode 100644 src/Rules/Deprecations/DeprecationProvider.php diff --git a/rules.neon b/rules.neon index df499a84..7ea85bb3 100644 --- a/rules.neon +++ b/rules.neon @@ -19,6 +19,16 @@ services: - class: PHPStan\Rules\Deprecations\CallWithDeprecatedIniOptionRule + - + class: PHPStan\Rules\Deprecations\DeprecationHelper + arguments: + providers: tagged(phpstan.deprecationProvider) + + - + class: PHPStan\Rules\Deprecations\DefaultDeprecationProvider + tags: + - phpstan.deprecationProvider + rules: - PHPStan\Rules\Deprecations\AccessDeprecatedPropertyRule - PHPStan\Rules\Deprecations\AccessDeprecatedStaticPropertyRule diff --git a/src/Rules/Deprecations/AccessDeprecatedPropertyRule.php b/src/Rules/Deprecations/AccessDeprecatedPropertyRule.php index 67c35789..e380afe8 100644 --- a/src/Rules/Deprecations/AccessDeprecatedPropertyRule.php +++ b/src/Rules/Deprecations/AccessDeprecatedPropertyRule.php @@ -24,10 +24,13 @@ class AccessDeprecatedPropertyRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -54,8 +57,10 @@ public function processNode(Node $node, Scope $scope): array $classReflection = $this->reflectionProvider->getClass($referencedClass); $propertyReflection = $classReflection->getProperty($propertyName, $scope); - if ($propertyReflection->isDeprecated()->yes()) { - $description = $propertyReflection->getDeprecatedDescription(); + $deprecation = $this->deprecationHelper->getDeprecation($propertyReflection); + + if ($deprecation !== null) { + $description = $deprecation->getDescription(); if ($description === null) { return [ RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php b/src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php index de036716..5b0f4372 100644 --- a/src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php +++ b/src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php @@ -30,11 +30,14 @@ class AccessDeprecatedStaticPropertyRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->ruleLevelHelper = $ruleLevelHelper; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -82,8 +85,9 @@ public function processNode(Node $node, Scope $scope): array continue; } - if ($property->isDeprecated()->yes()) { - $description = $property->getDeprecatedDescription(); + $deprecation = $this->deprecationHelper->getDeprecation($property); + if ($deprecation !== null) { + $description = $deprecation->getDescription(); if ($description === null) { return [ RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/CallToDeprecatedFunctionRule.php b/src/Rules/Deprecations/CallToDeprecatedFunctionRule.php index 4455c3f9..7401e194 100644 --- a/src/Rules/Deprecations/CallToDeprecatedFunctionRule.php +++ b/src/Rules/Deprecations/CallToDeprecatedFunctionRule.php @@ -22,10 +22,13 @@ class CallToDeprecatedFunctionRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -50,8 +53,9 @@ public function processNode(Node $node, Scope $scope): array return []; } - if ($function->isDeprecated()->yes()) { - $description = $function->getDeprecatedDescription(); + $deprecation = $this->deprecationHelper->getDeprecation($function); + if ($deprecation !== null) { + $description = $deprecation->getDescription(); if ($description === null) { return [ RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/CallToDeprecatedMethodRule.php b/src/Rules/Deprecations/CallToDeprecatedMethodRule.php index f7671d06..18f90521 100644 --- a/src/Rules/Deprecations/CallToDeprecatedMethodRule.php +++ b/src/Rules/Deprecations/CallToDeprecatedMethodRule.php @@ -24,10 +24,13 @@ class CallToDeprecatedMethodRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -54,11 +57,12 @@ public function processNode(Node $node, Scope $scope): array $classReflection = $this->reflectionProvider->getClass($referencedClass); $methodReflection = $classReflection->getMethod($methodName, $scope); - if (!$methodReflection->isDeprecated()->yes()) { + $deprecation = $this->deprecationHelper->getDeprecation($methodReflection); + if ($deprecation === null) { continue; } - $description = $methodReflection->getDeprecatedDescription(); + $description = $deprecation->getDescription(); if ($description === null) { return [ RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php b/src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php index 2e78f583..73aef647 100644 --- a/src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php +++ b/src/Rules/Deprecations/CallToDeprecatedStaticMethodRule.php @@ -30,11 +30,14 @@ class CallToDeprecatedStaticMethodRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->ruleLevelHelper = $ruleLevelHelper; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -84,8 +87,9 @@ public function processNode(Node $node, Scope $scope): array continue; } - if ($class->isDeprecated()) { - $classDescription = $class->getDeprecatedDescription(); + $classDeprecation = $this->deprecationHelper->getDeprecation($class); + if ($classDeprecation !== null) { + $classDescription = $classDeprecation->getDescription(); if ($classDescription === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Call to method %s() of deprecated %s %s.', @@ -104,11 +108,12 @@ public function processNode(Node $node, Scope $scope): array } } - if (!$methodReflection->isDeprecated()->yes()) { + $methodDeprecation = $this->deprecationHelper->getDeprecation($methodReflection); + if ($methodDeprecation === null) { continue; } - $description = $methodReflection->getDeprecatedDescription(); + $description = $methodDeprecation->getDescription(); if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Call to deprecated method %s() of %s %s.', diff --git a/src/Rules/Deprecations/DefaultDeprecatedScopeResolver.php b/src/Rules/Deprecations/DefaultDeprecatedScopeResolver.php index 14807272..e1415205 100644 --- a/src/Rules/Deprecations/DefaultDeprecatedScopeResolver.php +++ b/src/Rules/Deprecations/DefaultDeprecatedScopeResolver.php @@ -7,20 +7,27 @@ final class DefaultDeprecatedScopeResolver implements DeprecatedScopeResolver { + private DeprecationHelper $deprecationHelper; + + public function __construct(DeprecationHelper $deprecationHelper) + { + $this->deprecationHelper = $deprecationHelper; + } + public function isScopeDeprecated(Scope $scope): bool { $class = $scope->getClassReflection(); - if ($class !== null && $class->isDeprecated()) { + if ($class !== null && $this->deprecationHelper->getDeprecation($class) !== null) { return true; } $trait = $scope->getTraitReflection(); - if ($trait !== null && $trait->isDeprecated()) { + if ($trait !== null && $this->deprecationHelper->getDeprecation($trait) !== null) { return true; } $function = $scope->getFunction(); - if ($function !== null && $function->isDeprecated()->yes()) { + if ($function !== null && $this->deprecationHelper->getDeprecation($function) !== null) { return true; } diff --git a/src/Rules/Deprecations/DefaultDeprecationProvider.php b/src/Rules/Deprecations/DefaultDeprecationProvider.php new file mode 100644 index 00000000..b896806e --- /dev/null +++ b/src/Rules/Deprecations/DefaultDeprecationProvider.php @@ -0,0 +1,40 @@ +isDeprecated() + ? Deprecation::create()->withDescription($reflection->getDeprecatedDescription()) + : null; + } + + if ( + $reflection instanceof ConstantReflection + || $reflection instanceof EnumCaseReflection + || $reflection instanceof ExtendedPropertyReflection + || $reflection instanceof ExtendedMethodReflection + || $reflection instanceof FunctionReflection + ) { + return $reflection->isDeprecated()->yes() + ? Deprecation::create()->withDescription($reflection->getDeprecatedDescription()) + : null; + } + + return null; + } +} diff --git a/src/Rules/Deprecations/DeprecatedClassHelper.php b/src/Rules/Deprecations/DeprecatedClassHelper.php index 82a9abc3..a5028f7e 100644 --- a/src/Rules/Deprecations/DeprecatedClassHelper.php +++ b/src/Rules/Deprecations/DeprecatedClassHelper.php @@ -12,14 +12,22 @@ class DeprecatedClassHelper private ReflectionProvider $reflectionProvider; - public function __construct(ReflectionProvider $reflectionProvider) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; + $this->deprecationHelper = $deprecationHelper; } public function getClassDeprecationDescription(ClassReflection $class): string { - $description = $class->getDeprecatedDescription(); + $deprecation = $this->deprecationHelper->getDeprecation($class); + if ($deprecation === null) { + return '.'; + } + + $description = $deprecation->getDescription(); if ($description === null) { return '.'; } @@ -41,7 +49,7 @@ public function filterDeprecatedClasses(array $referencedClasses): array continue; } - if (!$class->isDeprecated()) { + if ($this->deprecationHelper->getDeprecation($class) === null) { continue; } diff --git a/src/Rules/Deprecations/Deprecation.php b/src/Rules/Deprecations/Deprecation.php new file mode 100644 index 00000000..b5a1198d --- /dev/null +++ b/src/Rules/Deprecations/Deprecation.php @@ -0,0 +1,38 @@ +description = $description; + return $clone; + } + + public function getDescription(): ?string + { + return $this->description; + } + +} diff --git a/src/Rules/Deprecations/DeprecationHelper.php b/src/Rules/Deprecations/DeprecationHelper.php new file mode 100644 index 00000000..4ad2db9d --- /dev/null +++ b/src/Rules/Deprecations/DeprecationHelper.php @@ -0,0 +1,41 @@ + */ + private array $providers; + + /** + * @param list $providers + */ + public function __construct(array $providers) + { + $this->providers = $providers; + } + + /** + * @param ExtendedPropertyReflection|ExtendedMethodReflection|FunctionReflection|ClassReflection|ConstantReflection|ClassConstantReflection $reflection + */ + public function getDeprecation($reflection): ?Deprecation + { + foreach ($this->providers as $provider) { + $deprecation = $provider->getDeprecation($reflection); + if ($deprecation !== null) { + return $deprecation; + } + } + + return null; + } + +} diff --git a/src/Rules/Deprecations/DeprecationProvider.php b/src/Rules/Deprecations/DeprecationProvider.php new file mode 100644 index 00000000..b7bb9a7f --- /dev/null +++ b/src/Rules/Deprecations/DeprecationProvider.php @@ -0,0 +1,19 @@ +reflectionProvider = $reflectionProvider; $this->ruleLevelHelper = $ruleLevelHelper; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -80,8 +83,9 @@ public function processNode(Node $node, Scope $scope): array continue; } - if ($class->isDeprecated()) { - $classDescription = $class->getDeprecatedDescription(); + $classDeprecation = $this->deprecationHelper->getDeprecation($class); + if ($classDeprecation !== null) { + $classDescription = $classDeprecation->getDescription(); if ($classDescription === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Fetching class constant %s of deprecated %s %s.', @@ -110,11 +114,12 @@ public function processNode(Node $node, Scope $scope): array $constantReflection = $class->getConstant($constantName); - if (!$constantReflection->isDeprecated()->yes()) { + $constantDeprecation = $this->deprecationHelper->getDeprecation($constantReflection); + if ($constantDeprecation === null) { continue; } - $description = $constantReflection->getDeprecatedDescription(); + $description = $constantDeprecation->getDescription(); if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Fetching deprecated class constant %s of %s %s.', diff --git a/src/Rules/Deprecations/FetchingDeprecatedConstRule.php b/src/Rules/Deprecations/FetchingDeprecatedConstRule.php index 0e5f9d67..58558fd6 100644 --- a/src/Rules/Deprecations/FetchingDeprecatedConstRule.php +++ b/src/Rules/Deprecations/FetchingDeprecatedConstRule.php @@ -20,10 +20,13 @@ class FetchingDeprecatedConstRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -43,10 +46,11 @@ public function processNode(Node $node, Scope $scope): array $constantReflection = $this->reflectionProvider->getConstant($node->name, $scope); - if ($constantReflection->isDeprecated()->yes()) { + $deprecation = $this->deprecationHelper->getDeprecation($constantReflection); + if ($deprecation !== null) { return [ RuleErrorBuilder::message(sprintf( - $constantReflection->getDeprecatedDescription() ?? 'Use of constant %s is deprecated.', + $deprecation->getDescription() ?? 'Use of constant %s is deprecated.', $constantReflection->getName(), ))->identifier('constant.deprecated')->build(), ]; diff --git a/src/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRule.php b/src/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRule.php index 52d6f59e..62b50a14 100644 --- a/src/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRule.php +++ b/src/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRule.php @@ -21,10 +21,13 @@ class ImplementationOfDeprecatedInterfaceRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -50,7 +53,8 @@ public function processNode(Node $node, Scope $scope): array return []; } - if ($class->isDeprecated()) { + $classDeprecation = $this->deprecationHelper->getDeprecation($class); + if ($classDeprecation !== null) { return []; } @@ -60,8 +64,9 @@ public function processNode(Node $node, Scope $scope): array try { $interface = $this->reflectionProvider->getClass($interfaceName); - if ($interface->isDeprecated()) { - $description = $interface->getDeprecatedDescription(); + $interfaceDeprecation = $this->deprecationHelper->getDeprecation($interface); + if ($interfaceDeprecation !== null) { + $description = $interfaceDeprecation->getDescription(); if (!$class->isAnonymous()) { if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php b/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php index e16e836a..1c6cf116 100644 --- a/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php +++ b/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php @@ -21,10 +21,13 @@ class InheritanceOfDeprecatedClassRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -58,8 +61,9 @@ public function processNode(Node $node, Scope $scope): array try { $parentClass = $this->reflectionProvider->getClass($parentClassName); - $description = $parentClass->getDeprecatedDescription(); - if ($parentClass->isDeprecated()) { + $parentDeprecation = $this->deprecationHelper->getDeprecation($parentClass); + if ($parentDeprecation !== null) { + $description = $parentDeprecation->getDescription(); if (!$class->isAnonymous()) { if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php b/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php index e723482f..0cfb8791 100644 --- a/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php +++ b/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php @@ -19,9 +19,12 @@ class InheritanceOfDeprecatedInterfaceRule implements Rule private ReflectionProvider $reflectionProvider; - public function __construct(ReflectionProvider $reflectionProvider) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -41,7 +44,8 @@ public function processNode(Node $node, Scope $scope): array return []; } - if ($interface->isDeprecated()) { + $interfaceDeprecation = $this->deprecationHelper->getDeprecation($interface); + if ($interfaceDeprecation !== null) { return []; } @@ -53,11 +57,12 @@ public function processNode(Node $node, Scope $scope): array try { $parentInterface = $this->reflectionProvider->getClass($parentInterfaceName); - if (!$parentInterface->isDeprecated()) { + $parentDeprecation = $this->deprecationHelper->getDeprecation($parentInterface); + if ($parentDeprecation === null) { continue; } - $description = $parentInterface->getDeprecatedDescription(); + $description = $parentDeprecation->getDescription(); if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Interface %s extends deprecated interface %s.', diff --git a/src/Rules/Deprecations/InstantiationOfDeprecatedClassRule.php b/src/Rules/Deprecations/InstantiationOfDeprecatedClassRule.php index 34effe15..96b207bc 100644 --- a/src/Rules/Deprecations/InstantiationOfDeprecatedClassRule.php +++ b/src/Rules/Deprecations/InstantiationOfDeprecatedClassRule.php @@ -27,11 +27,14 @@ class InstantiationOfDeprecatedClassRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, RuleLevelHelper $ruleLevelHelper, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->ruleLevelHelper = $ruleLevelHelper; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -79,11 +82,12 @@ public function processNode(Node $node, Scope $scope): array continue; } - if (!$class->isDeprecated()) { + $deprecation = $this->deprecationHelper->getDeprecation($class); + if ($deprecation === null) { continue; } - $description = $class->getDeprecatedDescription(); + $description = $deprecation->getDescription(); if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Instantiation of deprecated class %s.', diff --git a/src/Rules/Deprecations/UsageOfDeprecatedCastRule.php b/src/Rules/Deprecations/UsageOfDeprecatedCastRule.php index 1dd34cc1..3fd397ec 100644 --- a/src/Rules/Deprecations/UsageOfDeprecatedCastRule.php +++ b/src/Rules/Deprecations/UsageOfDeprecatedCastRule.php @@ -17,9 +17,12 @@ class UsageOfDeprecatedCastRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -39,10 +42,12 @@ public function processNode(Node $node, Scope $scope): array } $method = $castedType->getMethod('__toString', $scope); - if (! $method->isDeprecated()->yes()) { + $deprecation = $this->deprecationHelper->getDeprecation($method); + if ($deprecation === null) { return []; } - $description = $method->getDeprecatedDescription(); + + $description = $deprecation->getDescription(); if ($description === null) { return [ RuleErrorBuilder::message(sprintf( diff --git a/src/Rules/Deprecations/UsageOfDeprecatedTraitRule.php b/src/Rules/Deprecations/UsageOfDeprecatedTraitRule.php index 27d0cb42..b94bd803 100644 --- a/src/Rules/Deprecations/UsageOfDeprecatedTraitRule.php +++ b/src/Rules/Deprecations/UsageOfDeprecatedTraitRule.php @@ -22,10 +22,13 @@ class UsageOfDeprecatedTraitRule implements Rule private DeprecatedScopeHelper $deprecatedScopeHelper; - public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) + private DeprecationHelper $deprecationHelper; + + public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper, DeprecationHelper $deprecationHelper) { $this->reflectionProvider = $reflectionProvider; $this->deprecatedScopeHelper = $deprecatedScopeHelper; + $this->deprecationHelper = $deprecationHelper; } public function getNodeType(): string @@ -52,11 +55,12 @@ public function processNode(Node $node, Scope $scope): array try { $trait = $this->reflectionProvider->getClass($traitName); - if (!$trait->isDeprecated()) { + $deprecation = $this->deprecationHelper->getDeprecation($trait); + if ($deprecation === null) { continue; } - $description = $trait->getDeprecatedDescription(); + $description = $deprecation->getDescription(); if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Usage of deprecated trait %s in class %s.', diff --git a/tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php b/tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php index ebddb9a8..3f79d0e5 100644 --- a/tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php +++ b/tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php @@ -13,9 +13,11 @@ class CallToDeprecatedMethodRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new CallToDeprecatedMethodRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } From e71954a536c8f7d2b40683badbd16fc3a89e3aa1 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 10 Apr 2025 13:26:55 +0200 Subject: [PATCH 2/3] Adjust tests --- .../Rules/Deprecations/AccessDeprecatedPropertyRuleTest.php | 4 +++- .../Deprecations/AccessDeprecatedStaticPropertyRuleTest.php | 4 +++- .../Rules/Deprecations/CallToDeprecatedFunctionRuleTest.php | 4 +++- .../Deprecations/CallToDeprecatedStaticMethodRuleTest.php | 4 +++- .../Deprecations/CallWithDeprecatedIniOptionRuleTest.php | 4 +++- .../Deprecations/CustomDeprecatedScopeResolverTest.php | 4 +++- .../FetchingClassConstOfDeprecatedClassRuleTest.php | 4 +++- .../Rules/Deprecations/FetchingDeprecatedConstRuleTest.php | 4 +++- .../ImplementationOfDeprecatedInterfaceRuleTest.php | 4 +++- .../Deprecations/InheritanceOfDeprecatedClassRuleTest.php | 4 +++- .../InheritanceOfDeprecatedInterfaceRuleTest.php | 6 +++++- .../Deprecations/InstantiationOfDeprecatedClassRuleTest.php | 4 +++- .../TypeHintDeprecatedInClassMethodSignatureRuleTest.php | 6 ++++-- .../TypeHintDeprecatedInClosureSignatureRuleTest.php | 6 ++++-- .../TypeHintDeprecatedInFunctionSignatureRuleTest.php | 6 ++++-- tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php | 4 +++- tests/Rules/Deprecations/UsageOfDeprecatedTraitRuleTest.php | 4 +++- 17 files changed, 56 insertions(+), 20 deletions(-) diff --git a/tests/Rules/Deprecations/AccessDeprecatedPropertyRuleTest.php b/tests/Rules/Deprecations/AccessDeprecatedPropertyRuleTest.php index e20359e9..16ed9b15 100644 --- a/tests/Rules/Deprecations/AccessDeprecatedPropertyRuleTest.php +++ b/tests/Rules/Deprecations/AccessDeprecatedPropertyRuleTest.php @@ -13,9 +13,11 @@ class AccessDeprecatedPropertyRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new AccessDeprecatedPropertyRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/AccessDeprecatedStaticPropertyRuleTest.php b/tests/Rules/Deprecations/AccessDeprecatedStaticPropertyRuleTest.php index ef8c3dea..7c57f9b8 100644 --- a/tests/Rules/Deprecations/AccessDeprecatedStaticPropertyRuleTest.php +++ b/tests/Rules/Deprecations/AccessDeprecatedStaticPropertyRuleTest.php @@ -14,10 +14,12 @@ class AccessDeprecatedStaticPropertyRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new AccessDeprecatedStaticPropertyRule( $this->createReflectionProvider(), self::getContainer()->getByType(RuleLevelHelper::class), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/CallToDeprecatedFunctionRuleTest.php b/tests/Rules/Deprecations/CallToDeprecatedFunctionRuleTest.php index 2297d6b3..5b54356a 100644 --- a/tests/Rules/Deprecations/CallToDeprecatedFunctionRuleTest.php +++ b/tests/Rules/Deprecations/CallToDeprecatedFunctionRuleTest.php @@ -13,9 +13,11 @@ class CallToDeprecatedFunctionRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new CallToDeprecatedFunctionRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php b/tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php index 37bbe171..017969e3 100644 --- a/tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php +++ b/tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php @@ -14,10 +14,12 @@ class CallToDeprecatedStaticMethodRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new CallToDeprecatedStaticMethodRule( $this->createReflectionProvider(), self::getContainer()->getByType(RuleLevelHelper::class), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/CallWithDeprecatedIniOptionRuleTest.php b/tests/Rules/Deprecations/CallWithDeprecatedIniOptionRuleTest.php index 66236baa..874af0c0 100644 --- a/tests/Rules/Deprecations/CallWithDeprecatedIniOptionRuleTest.php +++ b/tests/Rules/Deprecations/CallWithDeprecatedIniOptionRuleTest.php @@ -15,10 +15,12 @@ class CallWithDeprecatedIniOptionRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new CallWithDeprecatedIniOptionRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), self::getContainer()->getByType(PhpVersion::class), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/CustomDeprecatedScopeResolverTest.php b/tests/Rules/Deprecations/CustomDeprecatedScopeResolverTest.php index 34bf486c..485b8ac4 100644 --- a/tests/Rules/Deprecations/CustomDeprecatedScopeResolverTest.php +++ b/tests/Rules/Deprecations/CustomDeprecatedScopeResolverTest.php @@ -15,6 +15,7 @@ final class CustomDeprecatedScopeResolverTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); $customScopeResolver = new class implements DeprecatedScopeResolver { @@ -30,9 +31,10 @@ public function isScopeDeprecated(Scope $scope): bool return new CallToDeprecatedMethodRule( $this->createReflectionProvider(), new DeprecatedScopeHelper([ - new DefaultDeprecatedScopeResolver(), + new DefaultDeprecatedScopeResolver($deprecationHelper), $customScopeResolver, ]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRuleTest.php b/tests/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRuleTest.php index 29ccd5fe..52355ef6 100644 --- a/tests/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRuleTest.php +++ b/tests/Rules/Deprecations/FetchingClassConstOfDeprecatedClassRuleTest.php @@ -14,10 +14,12 @@ class FetchingClassConstOfDeprecatedClassRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new FetchingClassConstOfDeprecatedClassRule( $this->createReflectionProvider(), self::getContainer()->getByType(RuleLevelHelper::class), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php index 1428ec26..1901daf9 100644 --- a/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php +++ b/tests/Rules/Deprecations/FetchingDeprecatedConstRuleTest.php @@ -14,9 +14,11 @@ class FetchingDeprecatedConstRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new FetchingDeprecatedConstRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRuleTest.php b/tests/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRuleTest.php index 24830841..ca78ffce 100644 --- a/tests/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRuleTest.php +++ b/tests/Rules/Deprecations/ImplementationOfDeprecatedInterfaceRuleTest.php @@ -13,9 +13,11 @@ class ImplementationOfDeprecatedInterfaceRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new ImplementationOfDeprecatedInterfaceRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php b/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php index a10c227d..35c92265 100644 --- a/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php +++ b/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php @@ -13,9 +13,11 @@ class InheritanceOfDeprecatedClassRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new InheritanceOfDeprecatedClassRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php b/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php index 0bf420ed..811e0d46 100644 --- a/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php +++ b/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php @@ -13,7 +13,11 @@ class InheritanceOfDeprecatedInterfaceRuleTest extends RuleTestCase protected function getRule(): Rule { - return new InheritanceOfDeprecatedInterfaceRule($this->createReflectionProvider()); + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); + return new InheritanceOfDeprecatedInterfaceRule( + $this->createReflectionProvider(), + $deprecationHelper, + ); } public function testInheritanceOfDeprecatedInterfaces(): void diff --git a/tests/Rules/Deprecations/InstantiationOfDeprecatedClassRuleTest.php b/tests/Rules/Deprecations/InstantiationOfDeprecatedClassRuleTest.php index 22e1760c..abe57b67 100644 --- a/tests/Rules/Deprecations/InstantiationOfDeprecatedClassRuleTest.php +++ b/tests/Rules/Deprecations/InstantiationOfDeprecatedClassRuleTest.php @@ -14,10 +14,12 @@ class InstantiationOfDeprecatedClassRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new InstantiationOfDeprecatedClassRule( $this->createReflectionProvider(), self::getContainer()->getByType(RuleLevelHelper::class), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php index 76c9153a..47647f2e 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php @@ -13,9 +13,11 @@ class TypeHintDeprecatedInClassMethodSignatureRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new TypeHintDeprecatedInClassMethodSignatureRule( - new DeprecatedClassHelper($this->createReflectionProvider()), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedClassHelper($this->createReflectionProvider(), $deprecationHelper), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php index f23104b7..04545225 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php @@ -13,9 +13,11 @@ class TypeHintDeprecatedInClosureSignatureRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new TypeHintDeprecatedInClosureSignatureRule( - new DeprecatedClassHelper($this->createReflectionProvider()), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedClassHelper($this->createReflectionProvider(), $deprecationHelper), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php index 9fbba8fb..e676f652 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php @@ -13,9 +13,11 @@ class TypeHintDeprecatedInFunctionSignatureRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new TypeHintDeprecatedInFunctionSignatureRule( - new DeprecatedClassHelper($this->createReflectionProvider()), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedClassHelper($this->createReflectionProvider(), $deprecationHelper), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php b/tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php index f2280a2e..2f0349fe 100644 --- a/tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php +++ b/tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php @@ -13,8 +13,10 @@ class UsageOfDeprecatedCastRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new UsageOfDeprecatedCastRule( - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/UsageOfDeprecatedTraitRuleTest.php b/tests/Rules/Deprecations/UsageOfDeprecatedTraitRuleTest.php index dfa528ad..f5964abf 100644 --- a/tests/Rules/Deprecations/UsageOfDeprecatedTraitRuleTest.php +++ b/tests/Rules/Deprecations/UsageOfDeprecatedTraitRuleTest.php @@ -13,9 +13,11 @@ class UsageOfDeprecatedTraitRuleTest extends RuleTestCase protected function getRule(): Rule { + $deprecationHelper = new DeprecationHelper([new DefaultDeprecationProvider()]); return new UsageOfDeprecatedTraitRule( $this->createReflectionProvider(), - new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver()]), + new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), + $deprecationHelper, ); } From a0961f73e2eb9ae1549ced745b67b4c915632d8e Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 10 Apr 2025 15:32:35 +0200 Subject: [PATCH 3/3] Fixes --- .../Deprecations/DefaultDeprecationProvider.php | 17 ++++------------- src/Rules/Deprecations/Deprecation.php | 12 ++++-------- src/Rules/Deprecations/DeprecationProvider.php | 2 +- .../CallWithDeprecatedIniOptionRuleTest.php | 1 - ...DeprecatedInClassMethodSignatureRuleTest.php | 1 - ...HintDeprecatedInClosureSignatureRuleTest.php | 1 - ...intDeprecatedInFunctionSignatureRuleTest.php | 1 - 7 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/Rules/Deprecations/DefaultDeprecationProvider.php b/src/Rules/Deprecations/DefaultDeprecationProvider.php index b896806e..b5208aec 100644 --- a/src/Rules/Deprecations/DefaultDeprecationProvider.php +++ b/src/Rules/Deprecations/DefaultDeprecationProvider.php @@ -23,18 +23,9 @@ public function getDeprecation($reflection): ?Deprecation : null; } - if ( - $reflection instanceof ConstantReflection - || $reflection instanceof EnumCaseReflection - || $reflection instanceof ExtendedPropertyReflection - || $reflection instanceof ExtendedMethodReflection - || $reflection instanceof FunctionReflection - ) { - return $reflection->isDeprecated()->yes() - ? Deprecation::create()->withDescription($reflection->getDeprecatedDescription()) - : null; - } - - return null; + return $reflection->isDeprecated()->yes() + ? Deprecation::create()->withDescription($reflection->getDeprecatedDescription()) + : null; } + } diff --git a/src/Rules/Deprecations/Deprecation.php b/src/Rules/Deprecations/Deprecation.php index b5a1198d..7c48e170 100644 --- a/src/Rules/Deprecations/Deprecation.php +++ b/src/Rules/Deprecations/Deprecation.php @@ -2,12 +2,6 @@ namespace PHPStan\Rules\Deprecations; -use PHPStan\BetterReflection\Reflection\ReflectionClass; -use PHPStan\BetterReflection\Reflection\ReflectionFunction; -use PHPStan\BetterReflection\Reflection\ReflectionMethod; -use PHPStan\BetterReflection\Reflection\ReflectionProperty; -use PHPStan\Reflection\PropertyReflection; - /** * @api */ @@ -20,11 +14,13 @@ private function __construct() { } - public static function create(): self { + public static function create(): self + { return new self(); } - public function withDescription(?string $description): self { + public function withDescription(?string $description): self + { $clone = clone $this; $clone->description = $description; return $clone; diff --git a/src/Rules/Deprecations/DeprecationProvider.php b/src/Rules/Deprecations/DeprecationProvider.php index b7bb9a7f..77fa12eb 100644 --- a/src/Rules/Deprecations/DeprecationProvider.php +++ b/src/Rules/Deprecations/DeprecationProvider.php @@ -1,4 +1,4 @@ -createReflectionProvider(), new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), self::getContainer()->getByType(PhpVersion::class), - $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php index 47647f2e..36690700 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php @@ -17,7 +17,6 @@ protected function getRule(): Rule return new TypeHintDeprecatedInClassMethodSignatureRule( new DeprecatedClassHelper($this->createReflectionProvider(), $deprecationHelper), new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), - $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php index 04545225..c8b7c67e 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php @@ -17,7 +17,6 @@ protected function getRule(): Rule return new TypeHintDeprecatedInClosureSignatureRule( new DeprecatedClassHelper($this->createReflectionProvider(), $deprecationHelper), new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), - $deprecationHelper, ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php index e676f652..af70fe97 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php @@ -17,7 +17,6 @@ protected function getRule(): Rule return new TypeHintDeprecatedInFunctionSignatureRule( new DeprecatedClassHelper($this->createReflectionProvider(), $deprecationHelper), new DeprecatedScopeHelper([new DefaultDeprecatedScopeResolver($deprecationHelper)]), - $deprecationHelper, ); }