-
Notifications
You must be signed in to change notification settings - Fork 20
Closed
Description
Bug report
I am using phpstan
in combination with phpstan-deprecation-rules
and getting false-positives in my test classes since a deprecation annotation has been added to PHPUnit.
The code detecting deprecations in phpstan-deprecation-rules
looks good:
$classReflection = $this->reflectionProvider->getClass($referencedClass);
$methodReflection = $classReflection->getMethod($methodName, $scope);
if (!$methodReflection->isDeprecated()->yes()) {
continue;
}
But the $methodReflection
is pointing to the method defined in the (TestCase
) base class instead of the overwriting method in the ProphecyTrait
.
To reproduce this issue easily, I have created a minimal setup.
source file to check
<?php
declare(strict_types=1);
trait MyTrait
{
protected function prophesize(): void
{
echo 'Trait';
}
}
abstract class MyBaseClass
{
/** @deprecated Use MyTrait::prophesize() */
protected function prophesize(): void
{
echo 'Base';
}
}
final class MyClass extends MyBaseClass
{
use MyTrait;
public function callProphesize(): void
{
$this->prophesize(); // wrongly detected deprecation
}
}
phpstan.neon
parameters:
level: max
paths:
- src
includes:
- %rootDir%/../../phpstan/phpstan-deprecation-rules/rules.neon
Expected output
I am expectiong that the $methodReflection
variable is pointing to MyTrait::prophesize()
so that $methodReflection->isDeprecated()->yes()
returns false
and no deprecation is detected by phpstan-deprecation-rules
.
Did PHPStan help you today? Did it make you happy in any way?
phpstan
is a great tool that helps a lot in daily work.
Fabex, raf262, emyrtille, alecsmrekar, mstrelan and 7 more
Metadata
Metadata
Assignees
Labels
No labels