diff --git a/rules.neon b/rules.neon index df499a8..7ea85bb 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 67c3578..e380afe 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 de03671..5b0f437 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 4455c3f..7401e19 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 f7671d0..18f9052 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 2e78f58..73aef64 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 1480727..e141520 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 0000000..b5208ae --- /dev/null +++ b/src/Rules/Deprecations/DefaultDeprecationProvider.php @@ -0,0 +1,31 @@ +isDeprecated() + ? Deprecation::create()->withDescription($reflection->getDeprecatedDescription()) + : null; + } + + return $reflection->isDeprecated()->yes() + ? Deprecation::create()->withDescription($reflection->getDeprecatedDescription()) + : null; + } + +} diff --git a/src/Rules/Deprecations/DeprecatedClassHelper.php b/src/Rules/Deprecations/DeprecatedClassHelper.php index 82a9abc..a5028f7 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 0000000..7c48e17 --- /dev/null +++ b/src/Rules/Deprecations/Deprecation.php @@ -0,0 +1,34 @@ +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 0000000..4ad2db9 --- /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 0000000..77fa12e --- /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 0e5f9d6..58558fd 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 52d6f59..62b50a1 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 e16e836..1c6cf11 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 e723482..0cfb879 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 34effe1..96b207b 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 1dd34cc..3fd397e 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 27d0cb4..b94bd80 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/AccessDeprecatedPropertyRuleTest.php b/tests/Rules/Deprecations/AccessDeprecatedPropertyRuleTest.php index e20359e..16ed9b1 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 ef8c3de..7c57f9b 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 2297d6b..5b54356 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/CallToDeprecatedMethodRuleTest.php b/tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php index ebddb9a..3f79d0e 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, ); } diff --git a/tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php b/tests/Rules/Deprecations/CallToDeprecatedStaticMethodRuleTest.php index 37bbe17..017969e 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 66236ba..834850b 100644 --- a/tests/Rules/Deprecations/CallWithDeprecatedIniOptionRuleTest.php +++ b/tests/Rules/Deprecations/CallWithDeprecatedIniOptionRuleTest.php @@ -15,9 +15,10 @@ 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), ); } diff --git a/tests/Rules/Deprecations/CustomDeprecatedScopeResolverTest.php b/tests/Rules/Deprecations/CustomDeprecatedScopeResolverTest.php index 34bf486..485b8ac 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 29ccd5f..52355ef 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 1428ec2..1901daf 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 2483084..ca78ffc 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 a10c227..35c9226 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 0bf420e..811e0d4 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 22e1760..abe57b6 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 76c9153..3669070 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php @@ -13,9 +13,10 @@ 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)]), ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php index f23104b..c8b7c67 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClosureSignatureRuleTest.php @@ -13,9 +13,10 @@ 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)]), ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php index 9fbba8f..af70fe9 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInFunctionSignatureRuleTest.php @@ -13,9 +13,10 @@ 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)]), ); } diff --git a/tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php b/tests/Rules/Deprecations/UsageOfDeprecatedCastRuleTest.php index f2280a2..2f0349f 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 dfa528a..f5964ab 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, ); }