phpstan/phpstan-deprecation-rules

Detecting deprecated methods from an interface

eiriksm opened this issue · 2 comments

Hi there. First of all. Thanks so much for this, it has been so helpful in our projects.

I encountered an issue today that surprised me. If you are calling a class method that is deprecated on the interface level, phpstan does not complain. It surprised me only because my IDE shows me this, and I never thought about checking if this was detected in phpstan as well.

Here is a minimal example:

<?php

class Foo implements FooInterface
{
    /**
     * {@inheritdoc}
     */
    public function createBar() {}
}

interface FooInterface
{
    /**
     * @deprecated Don't use this plz.
     */
    public function createBar();
}


$var = new Foo();
$var->createBar(); // I expect this to be an error, but it's not.

/** @var \FooInterface $var */
$var = $var;
$var->createBar(); // I also expect this to be an error, and it is.

Attached also a picture of my IDE where this is clearly identified. Not that I am saying phpstan and Phpstorm should obviously have the same feature set, just for completion on this issue report :)

Screenshot from 2021-11-19 11-31-39

Here is also the phpstan.neon file:

parameters:
    level: 1
includes:
    - vendor/phpstan/phpstan-deprecation-rules/rules.neon

Using phpstan/phpstan 1.2.0 and phpstan/phpstan-deprecation-rules 1.0.0

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.