qossmic / deprecation-detector

MIT License
391 stars 40 forks source link

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

Open achasseux opened 6 years ago

achasseux commented 6 years ago

Exemple with symfony 3.4 :

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.