diff --git a/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php b/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php index e16e836..8506246 100644 --- a/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php +++ b/src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php @@ -55,6 +55,7 @@ public function processNode(Node $node, Scope $scope): array } $parentClassName = (string) $node->extends; + $line = $node->name !== null ? $node->name->getStartLine() : $node->getStartLine(); try { $parentClass = $this->reflectionProvider->getClass($parentClassName); @@ -66,27 +67,27 @@ public function processNode(Node $node, Scope $scope): array 'Class %s extends deprecated class %s.', $className, $parentClassName, - ))->identifier('class.extendsDeprecatedClass')->build(); + ))->identifier('class.extendsDeprecatedClass')->line($line)->build(); } else { $errors[] = RuleErrorBuilder::message(sprintf( "Class %s extends deprecated class %s:\n%s", $className, $parentClassName, $description, - ))->identifier('class.extendsDeprecatedClass')->build(); + ))->identifier('class.extendsDeprecatedClass')->line($line)->build(); } } else { if ($description === null) { $errors[] = RuleErrorBuilder::message(sprintf( 'Anonymous class extends deprecated class %s.', $parentClassName, - ))->identifier('class.extendsDeprecatedClass')->build(); + ))->identifier('class.extendsDeprecatedClass')->line($line)->build(); } else { $errors[] = RuleErrorBuilder::message(sprintf( "Anonymous class extends deprecated class %s:\n%s", $parentClassName, $description, - ))->identifier('class.extendsDeprecatedClass')->build(); + ))->identifier('class.extendsDeprecatedClass')->line($line)->build(); } } } diff --git a/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php b/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php index e723482..ed0683b 100644 --- a/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php +++ b/src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php @@ -45,6 +45,7 @@ public function processNode(Node $node, Scope $scope): array return []; } + $line = $node->name !== null ? $node->name->getStartLine() : $node->getStartLine(); $errors = []; foreach ($node->extends as $parentInterfaceName) { @@ -63,14 +64,14 @@ public function processNode(Node $node, Scope $scope): array 'Interface %s extends deprecated interface %s.', $interfaceName, $parentInterfaceName, - ))->identifier('interface.extendsDeprecatedInterface')->build(); + ))->identifier('interface.extendsDeprecatedInterface')->line($line)->build(); } else { $errors[] = RuleErrorBuilder::message(sprintf( "Interface %s extends deprecated interface %s:\n%s", $interfaceName, $parentInterfaceName, $description, - ))->identifier('interface.extendsDeprecatedInterface')->build(); + ))->identifier('interface.extendsDeprecatedInterface')->line($line)->build(); } } catch (ClassNotFoundException $e) { // Other rules will notify if the interface is not found diff --git a/src/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRule.php b/src/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRule.php index cb747aa..a872935 100644 --- a/src/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRule.php +++ b/src/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRule.php @@ -38,6 +38,7 @@ public function processNode(Node $node, Scope $scope): array } $method = $node->getMethodReflection(); + $line = $node->getOriginalNode()->name->getStartLine(); $errors = []; foreach ($method->getParameters() as $parameter) { @@ -51,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array strtolower($deprecatedClass->getClassTypeDescription()), $deprecatedClass->getName(), $this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass), - ))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build(); + ))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build(); } else { $errors[] = RuleErrorBuilder::message(sprintf( 'Parameter $%s of method %s::%s() has typehint with deprecated %s %s%s', @@ -61,7 +62,7 @@ public function processNode(Node $node, Scope $scope): array strtolower($deprecatedClass->getClassTypeDescription()), $deprecatedClass->getName(), $this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass), - ))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build(); + ))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build(); } } } @@ -75,7 +76,7 @@ public function processNode(Node $node, Scope $scope): array strtolower($deprecatedClass->getClassTypeDescription()), $deprecatedClass->getName(), $this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass), - ))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build(); + ))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build(); } else { $errors[] = RuleErrorBuilder::message(sprintf( 'Return type of method %s::%s() has typehint with deprecated %s %s%s', @@ -84,7 +85,7 @@ public function processNode(Node $node, Scope $scope): array strtolower($deprecatedClass->getClassTypeDescription()), $deprecatedClass->getName(), $this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass), - ))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build(); + ))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build(); } } diff --git a/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php b/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php index a10c227..332f87c 100644 --- a/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php +++ b/tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php @@ -33,6 +33,10 @@ public function testInheritanceOfDeprecatedClassInClasses(): void "Class InheritanceOfDeprecatedClass\Bar3 extends deprecated class InheritanceOfDeprecatedClass\DeprecatedWithDescription:\nInheritance is deprecated.", 15, ], + [ + "Class InheritanceOfDeprecatedClass\Bar4 extends deprecated class InheritanceOfDeprecatedClass\DeprecatedWithDescription:\nInheritance is deprecated.", + 21, + ], ], ); } diff --git a/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php b/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php index 0bf420e..35a65a8 100644 --- a/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php +++ b/tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php @@ -38,6 +38,10 @@ public function testInheritanceOfDeprecatedInterfaces(): void "Interface InheritanceOfDeprecatedInterface\Foo4 extends deprecated interface InheritanceOfDeprecatedInterface\DeprecatedWithDescription:\nImplement something else.", 20, ], + [ + 'Interface InheritanceOfDeprecatedInterface\Foo4 extends deprecated interface InheritanceOfDeprecatedInterface\DeprecatedFooable.', + 50, + ], ], ); } diff --git a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php index 76c9153..0233c65 100644 --- a/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php +++ b/tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php @@ -33,6 +33,7 @@ public function test(): void ['Parameter $property of method TypeHintDeprecatedInClassMethodSignature\FooImplNoOverride::oops() has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 50], ['Parameter $property of method __construct() in anonymous class has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 71], ['Return type of method getProperty() in anonymous class has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 76], + ['Return type of method methodWithAttribute() in anonymous class has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 82], ], ); } diff --git a/tests/Rules/Deprecations/data/inheritance-of-deprecated-class-in-classes.php b/tests/Rules/Deprecations/data/inheritance-of-deprecated-class-in-classes.php index 743889e..4c5ffe6 100644 --- a/tests/Rules/Deprecations/data/inheritance-of-deprecated-class-in-classes.php +++ b/tests/Rules/Deprecations/data/inheritance-of-deprecated-class-in-classes.php @@ -16,3 +16,9 @@ class Bar3 extends DeprecatedWithDescription { } + +#[SomeAttribute] +class Bar4 extends DeprecatedWithDescription +{ + +} diff --git a/tests/Rules/Deprecations/data/inheritance-of-deprecated-interface.php b/tests/Rules/Deprecations/data/inheritance-of-deprecated-interface.php index e05dedd..a6849a4 100644 --- a/tests/Rules/Deprecations/data/inheritance-of-deprecated-interface.php +++ b/tests/Rules/Deprecations/data/inheritance-of-deprecated-interface.php @@ -45,3 +45,9 @@ interface DeprecatedFoo3 extends Fooable, DeprecatedFooable, DeprecatedFooable2 { } + +#[SomeAttribute] +interface Foo4 extends Fooable, DeprecatedFooable +{ + +} diff --git a/tests/Rules/Deprecations/data/typehint-class-method-deprecated-class.php b/tests/Rules/Deprecations/data/typehint-class-method-deprecated-class.php index a983b50..9603b45 100644 --- a/tests/Rules/Deprecations/data/typehint-class-method-deprecated-class.php +++ b/tests/Rules/Deprecations/data/typehint-class-method-deprecated-class.php @@ -77,4 +77,11 @@ public function getProperty(): ?DeprecatedProperty { return $this->property; } + + #[SomeAttribute] + public function methodWithAttribute(): ?DeprecatedProperty + { + return $this->property; + } + };