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

Breadcrumb

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

function AccessDeprecatedPropertyRule::processNode

File

vendor/phpstan/phpstan-deprecation-rules/src/Rules/Deprecations/AccessDeprecatedPropertyRule.php, line 40

Class

AccessDeprecatedPropertyRule
@implements Rule<PropertyFetch>

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;
    $propertyAccessedOnType = $scope->getType($node->var);
    $referencedClasses = $propertyAccessedOnType->getObjectClassNames();
    foreach ($referencedClasses as $referencedClass) {
        try {
            $classReflection = $this->reflectionProvider
                ->getClass($referencedClass);
            $propertyReflection = $classReflection->getProperty($propertyName, $scope);
            if ($propertyReflection->isDeprecated()
                ->yes()) {
                $description = $propertyReflection->getDeprecatedDescription();
                if ($description === null) {
                    return [
                        RuleErrorBuilder::message(sprintf('Access to deprecated property $%s of %s %s.', $propertyName, strtolower($propertyReflection->getDeclaringClass()
                            ->getClassTypeDescription()), $propertyReflection->getDeclaringClass()
                            ->getName()))
                            ->identifier('property.deprecated')
                            ->build(),
                    ];
                }
                return [
                    RuleErrorBuilder::message(sprintf("Access to deprecated property \$%s of %s %s:\n%s", $propertyName, strtolower($propertyReflection->getDeclaringClass()
                        ->getClassTypeDescription()), $propertyReflection->getDeclaringClass()
                        ->getName(), $description))
                        ->identifier('property.deprecated')
                        ->build(),
                ];
            }
        } catch (ClassNotFoundException $e) {
            // Other rules will notify if the class is not found
        } catch (MissingPropertyFromReflectionException $e) {
            // Other rules will notify if the property is not found
        }
    }
    return [];
}

API Navigation

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