Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.
This repository was archived by the owner on May 6, 2025. It is now read-only.

Method of subclass is not detected when parent class contains a deprecated method #138

@achasseux

Description

@achasseux

Exemple with symfony 3.4 :

  • AppKernel is a subclass of Symfony\Component\HttpKernel\Kernel with a deprecated loadClassCache() method since symfony 3.3, but AppKernel is not detected
  • web/app_dev.php calls the deprecated method for AppKernel
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();

When you run
./vendor/bin/deprecation-detector check web/ vendor/
No violation detected.

I have noticed an issue in your RuleSet into "hasMethod()" or "getMethod()" methods :

    public function hasMethod($method, $class)
    {
        return isset($this->methodDeprecations[$class][$method]);
    }

If $class is a subclass of the deprecated class, the method is not detected.

The next method could detect this type of deprecated method :

    public function getMethod($method, $class)
    {
        foreach ($this->methodDeprecations as $className => $methodDeprecation) {
            if (isset($methodDeprecation[$method]) && ($class === $className || is_subclass_of($class, $className))) {
                return $methodDeprecation[$method];
            }
        }

        return;
    }

The is_subclass_of() function could not work if the autoloads of the project are not included.
For example, the vendor/autoload.php of my symfony project file has to be loaded in order to call the is_subclass_of() function.

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