Skip to content

Commit 4e75297

Browse files
committed
Do not report at attribute line
1 parent adf5e23 commit 4e75297

9 files changed

+41
-10
lines changed

src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function processNode(Node $node, Scope $scope): array
5555
}
5656

5757
$parentClassName = (string) $node->extends;
58+
$line = $node->name !== null ? $node->name->getStartLine() : $node->getStartLine();
5859

5960
try {
6061
$parentClass = $this->reflectionProvider->getClass($parentClassName);
@@ -66,27 +67,27 @@ public function processNode(Node $node, Scope $scope): array
6667
'Class %s extends deprecated class %s.',
6768
$className,
6869
$parentClassName,
69-
))->identifier('class.extendsDeprecatedClass')->build();
70+
))->identifier('class.extendsDeprecatedClass')->line($line)->build();
7071
} else {
7172
$errors[] = RuleErrorBuilder::message(sprintf(
7273
"Class %s extends deprecated class %s:\n%s",
7374
$className,
7475
$parentClassName,
7576
$description,
76-
))->identifier('class.extendsDeprecatedClass')->build();
77+
))->identifier('class.extendsDeprecatedClass')->line($line)->build();
7778
}
7879
} else {
7980
if ($description === null) {
8081
$errors[] = RuleErrorBuilder::message(sprintf(
8182
'Anonymous class extends deprecated class %s.',
8283
$parentClassName,
83-
))->identifier('class.extendsDeprecatedClass')->build();
84+
))->identifier('class.extendsDeprecatedClass')->line($line)->build();
8485
} else {
8586
$errors[] = RuleErrorBuilder::message(sprintf(
8687
"Anonymous class extends deprecated class %s:\n%s",
8788
$parentClassName,
8889
$description,
89-
))->identifier('class.extendsDeprecatedClass')->build();
90+
))->identifier('class.extendsDeprecatedClass')->line($line)->build();
9091
}
9192
}
9293
}

src/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function processNode(Node $node, Scope $scope): array
4545
return [];
4646
}
4747

48+
$line = $node->name !== null ? $node->name->getStartLine() : $node->getStartLine();
4849
$errors = [];
4950

5051
foreach ($node->extends as $parentInterfaceName) {
@@ -63,14 +64,14 @@ public function processNode(Node $node, Scope $scope): array
6364
'Interface %s extends deprecated interface %s.',
6465
$interfaceName,
6566
$parentInterfaceName,
66-
))->identifier('interface.extendsDeprecatedInterface')->build();
67+
))->identifier('interface.extendsDeprecatedInterface')->line($line)->build();
6768
} else {
6869
$errors[] = RuleErrorBuilder::message(sprintf(
6970
"Interface %s extends deprecated interface %s:\n%s",
7071
$interfaceName,
7172
$parentInterfaceName,
7273
$description,
73-
))->identifier('interface.extendsDeprecatedInterface')->build();
74+
))->identifier('interface.extendsDeprecatedInterface')->line($line)->build();
7475
}
7576
} catch (ClassNotFoundException $e) {
7677
// Other rules will notify if the interface is not found

src/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRule.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function processNode(Node $node, Scope $scope): array
3838
}
3939

4040
$method = $node->getMethodReflection();
41+
$line = $node->getOriginalNode()->name->getStartLine();
4142

4243
$errors = [];
4344
foreach ($method->getParameters() as $parameter) {
@@ -51,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
5152
strtolower($deprecatedClass->getClassTypeDescription()),
5253
$deprecatedClass->getName(),
5354
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass),
54-
))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build();
55+
))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build();
5556
} else {
5657
$errors[] = RuleErrorBuilder::message(sprintf(
5758
'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
6162
strtolower($deprecatedClass->getClassTypeDescription()),
6263
$deprecatedClass->getName(),
6364
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass),
64-
))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build();
65+
))->identifier(sprintf('parameter.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build();
6566
}
6667
}
6768
}
@@ -75,7 +76,7 @@ public function processNode(Node $node, Scope $scope): array
7576
strtolower($deprecatedClass->getClassTypeDescription()),
7677
$deprecatedClass->getName(),
7778
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass),
78-
))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build();
79+
))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build();
7980
} else {
8081
$errors[] = RuleErrorBuilder::message(sprintf(
8182
'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
8485
strtolower($deprecatedClass->getClassTypeDescription()),
8586
$deprecatedClass->getName(),
8687
$this->deprecatedClassHelper->getClassDeprecationDescription($deprecatedClass),
87-
))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->build();
88+
))->identifier(sprintf('return.deprecated%s', $deprecatedClass->getClassTypeDescription()))->line($line)->build();
8889
}
8990
}
9091

tests/Rules/Deprecations/InheritanceOfDeprecatedClassRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ public function testInheritanceOfDeprecatedClassInClasses(): void
3333
"Class InheritanceOfDeprecatedClass\Bar3 extends deprecated class InheritanceOfDeprecatedClass\DeprecatedWithDescription:\nInheritance is deprecated.",
3434
15,
3535
],
36+
[
37+
"Class InheritanceOfDeprecatedClass\Bar4 extends deprecated class InheritanceOfDeprecatedClass\DeprecatedWithDescription:\nInheritance is deprecated.",
38+
21,
39+
],
3640
],
3741
);
3842
}

tests/Rules/Deprecations/InheritanceOfDeprecatedInterfaceRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ public function testInheritanceOfDeprecatedInterfaces(): void
3838
"Interface InheritanceOfDeprecatedInterface\Foo4 extends deprecated interface InheritanceOfDeprecatedInterface\DeprecatedWithDescription:\nImplement something else.",
3939
20,
4040
],
41+
[
42+
'Interface InheritanceOfDeprecatedInterface\Foo4 extends deprecated interface InheritanceOfDeprecatedInterface\DeprecatedFooable.',
43+
50,
44+
],
4145
],
4246
);
4347
}

tests/Rules/Deprecations/TypeHintDeprecatedInClassMethodSignatureRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function test(): void
3333
['Parameter $property of method TypeHintDeprecatedInClassMethodSignature\FooImplNoOverride::oops() has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 50],
3434
['Parameter $property of method __construct() in anonymous class has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 71],
3535
['Return type of method getProperty() in anonymous class has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 76],
36+
['Return type of method methodWithAttribute() in anonymous class has typehint with deprecated class TypeHintDeprecatedInClassMethodSignature\DeprecatedProperty.', 82],
3637
],
3738
);
3839
}

tests/Rules/Deprecations/data/inheritance-of-deprecated-class-in-classes.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ class Bar3 extends DeprecatedWithDescription
1616
{
1717

1818
}
19+
20+
#[SomeAttribute]
21+
class Bar4 extends DeprecatedWithDescription
22+
{
23+
24+
}

tests/Rules/Deprecations/data/inheritance-of-deprecated-interface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ interface DeprecatedFoo3 extends Fooable, DeprecatedFooable, DeprecatedFooable2
4545
{
4646

4747
}
48+
49+
#[SomeAttribute]
50+
interface Foo4 extends Fooable, DeprecatedFooable
51+
{
52+
53+
}

tests/Rules/Deprecations/data/typehint-class-method-deprecated-class.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@ public function getProperty(): ?DeprecatedProperty
7777
{
7878
return $this->property;
7979
}
80+
81+
#[SomeAttribute]
82+
public function methodWithAttribute(): ?DeprecatedProperty
83+
{
84+
return $this->property;
85+
}
86+
8087
};

0 commit comments

Comments
 (0)