Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. DeprecatedAnnotationsRuleBase.php

class DeprecatedAnnotationsRuleBase

@implements Rule<Node\Stmt\Class_>

Hierarchy

  • class \mglaman\PHPStanDrupal\Rules\Deprecations\DeprecatedAnnotationsRuleBase implements \PHPStan\Rules\Rule

Expanded class hierarchy of DeprecatedAnnotationsRuleBase

File

vendor/mglaman/phpstan-drupal/src/Rules/Deprecations/DeprecatedAnnotationsRuleBase.php, line 14

Namespace

mglaman\PHPStanDrupal\Rules\Deprecations
View source
abstract class DeprecatedAnnotationsRuleBase implements Rule {
    
    /**
     * @var \PHPStan\Reflection\ReflectionProvider
     */
    protected $reflectionProvider;
    public function __construct(ReflectionProvider $reflectionProvider) {
        $this->reflectionProvider = $reflectionProvider;
    }
    public function getNodeType() : string {
        return Node\Stmt\Class_::class;
    }
    protected abstract function getExpectedInterface() : string;
    protected abstract function doProcessNode(ClassReflection $reflection, Node\Stmt\Class_ $node, Scope $scope) : array;
    public function processNode(Node $node, Scope $scope) : array {
        if ($node->extends === null) {
            return [];
        }
        if ($node->name === null) {
            return [];
        }
        if ($node->isAbstract()) {
            return [];
        }
        // PHPStan gives anonymous classes a name, so we cannot determine if
        // a class is truly anonymous using the normal methods from php-parser.
        // @see \PHPStan\Reflection\BetterReflection\BetterReflectionProvider::getAnonymousClassReflection
        if ($node->hasAttribute('anonymousClass') && $node->getAttribute('anonymousClass') === true) {
            return [];
        }
        $className = $node->name->name;
        $namespace = $scope->getNamespace();
        $reflection = $this->reflectionProvider
            ->getClass($namespace . '\\' . $className);
        $implementsExpectedInterface = $reflection->implementsInterface($this->getExpectedInterface());
        if (!$implementsExpectedInterface) {
            return [];
        }
        return $this->doProcessNode($reflection, $node, $scope);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overrides
DeprecatedAnnotationsRuleBase::$reflectionProvider protected property
DeprecatedAnnotationsRuleBase::doProcessNode abstract protected function 2
DeprecatedAnnotationsRuleBase::getExpectedInterface abstract protected function 2
DeprecatedAnnotationsRuleBase::getNodeType public function
DeprecatedAnnotationsRuleBase::processNode public function
DeprecatedAnnotationsRuleBase::__construct public function
RSS feed
Powered by Drupal