Skip to content

Detecting deprecated methods from an interface #48

Closed
@eiriksm

Description

@eiriksm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions