Skip to content

Do not report at attribute line #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Rules/Deprecations/InheritanceOfDeprecatedClassRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, this should report at the parameter line, but that would be much bigger BC.

} else {
$errors[] = RuleErrorBuilder::message(sprintf(
'Parameter $%s of method %s::%s() has typehint with deprecated %s %s%s',
Expand All @@ -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();
}
}
}
Expand All @@ -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',
Expand All @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ class Bar3 extends DeprecatedWithDescription
{

}

#[SomeAttribute]
class Bar4 extends DeprecatedWithDescription
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ interface DeprecatedFoo3 extends Fooable, DeprecatedFooable, DeprecatedFooable2
{

}

#[SomeAttribute]
interface Foo4 extends Fooable, DeprecatedFooable
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@ public function getProperty(): ?DeprecatedProperty
{
return $this->property;
}

#[SomeAttribute]
public function methodWithAttribute(): ?DeprecatedProperty
{
return $this->property;
}

};