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

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

Open
achasseux opened this issue Dec 4, 2017 · 0 comments

Comments

@achasseux
Copy link

achasseux commented Dec 4, 2017

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.

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

No branches or pull requests

1 participant