Skip to content
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

Detect deprecated methods from the interface as well. #792

Merged
merged 1 commit into from
Nov 21, 2021

Conversation

eiriksm
Copy link
Contributor

@eiriksm eiriksm commented Nov 20, 2021

Based on feedback from phpstan/phpstan-deprecation-rules#49

Initial bug report on that repo: phpstan/phpstan-deprecation-rules#48


$class = $reflectionProvider->getClass(\DeprecatedAnnotations\DeprecatedBar::class);
$scope = $this->createMock(Scope::class);
$this->assertTrue($class->getMethod('superDeprecated', $scope)->isDeprecated()->yes());
Copy link
Member

Choose a reason for hiding this comment

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

I don't like mocking, you can call getNativeMethod instead

@@ -131,4 +131,15 @@ public function testNonDeprecatedNativeFunctions(): void
$this->assertFalse($reflectionProvider->getFunction(new Name('function_exists'), null)->isDeprecated()->yes());
}

public function testDeprecatedMethodsFromInterface(): void
{
require_once __DIR__ . '/data/annotations-deprecated.php';
Copy link
Member

Choose a reason for hiding this comment

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

The require doesn't need to be there. You just need to make sure to run composer dump locally before running tests.

@ondrejmirtes
Copy link
Member

Can you please rebase and force push so that the history is linear with no merge commits? Thank you.

@eiriksm eiriksm force-pushed the fix/deprecated-from-interface branch from 34a1f5c to a8322b2 Compare November 21, 2021 04:31
@eiriksm
Copy link
Contributor Author

eiriksm commented Nov 21, 2021

Of course, no problem. Thanks for your time Ondrej, and thanks again for the family of phpstan libraries!

@ondrejmirtes ondrejmirtes merged commit 19d5638 into phpstan:master Nov 21, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@ossinkine
Copy link
Contributor

@ondrejmirtes @eiriksm Actually this is wrong behavour and conflicts with phpstan/phpstan#3378. The assumption that if a method in a parent class is deprecated, then a method in a child class should also be deprecated is not correct.

I have an example. Doctrine\ORM\Event\LifecycleEventArgs extends Doctrine\Persistence\Event\LifecycleEventArgs. Parent class has deprecated getEntity method and child class contain it but in child class it is not deprecated and should not be so.

So I suggest to revert this changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants