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

Breadcrumb

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

function AccessDeprecatedStaticPropertyRule::processNode

File

vendor/phpstan/phpstan-deprecation-rules/src/Rules/Deprecations/AccessDeprecatedStaticPropertyRule.php, line 48

Class

AccessDeprecatedStaticPropertyRule
@implements Rule<StaticPropertyFetch>

Namespace

PHPStan\Rules\Deprecations

Code

public function processNode(Node $node, Scope $scope) : array {
    if ($this->deprecatedScopeHelper
        ->isScopeDeprecated($scope)) {
        return [];
    }
    if (!$node->name instanceof Identifier) {
        return [];
    }
    $propertyName = $node->name->name;
    $referencedClasses = [];
    if ($node->class instanceof Name) {
        $referencedClasses[] = $scope->resolveName($node->class);
    }
    else {
        $classTypeResult = $this->ruleLevelHelper
            ->findTypeToCheck($scope, $node->class, '', static function (Type $type) use ($propertyName) : bool {
            return $type->canAccessProperties()
                ->yes() && $type->hasProperty($propertyName)
                ->yes();
        });
        if ($classTypeResult->getType() instanceof ErrorType) {
            return [];
        }
        $referencedClasses = $classTypeResult->getReferencedClasses();
    }
    foreach ($referencedClasses as $referencedClass) {
        try {
            $class = $this->reflectionProvider
                ->getClass($referencedClass);
            $property = $class->getProperty($propertyName, $scope);
        } catch (ClassNotFoundException $e) {
            continue;
        } catch (MissingPropertyFromReflectionException $e) {
            continue;
        }
        if ($property->isDeprecated()
            ->yes()) {
            $description = $property->getDeprecatedDescription();
            if ($description === null) {
                return [
                    RuleErrorBuilder::message(sprintf('Access to deprecated static property $%s of %s %s.', $propertyName, strtolower($property->getDeclaringClass()
                        ->getClassTypeDescription()), $property->getDeclaringClass()
                        ->getName()))
                        ->identifier('staticProperty.deprecated')
                        ->build(),
                ];
            }
            return [
                RuleErrorBuilder::message(sprintf("Access to deprecated static property \$%s of %s %s:\n%s", $propertyName, strtolower($property->getDeclaringClass()
                    ->getClassTypeDescription()), $property->getDeclaringClass()
                    ->getName(), $description))
                    ->identifier('staticProperty.deprecated')
                    ->build(),
            ];
        }
    }
    return [];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal