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

Breadcrumb

  1. Drupal Core 11.1.x

FetchingDeprecatedConstRule.php

Namespace

PHPStan\Rules\Deprecations

File

vendor/phpstan/phpstan-deprecation-rules/src/Rules/Deprecations/FetchingDeprecatedConstRule.php

View source
<?php

declare (strict_types=1);
namespace PHPStan\Rules\Deprecations;

use PhpParser\Node;
use PhpParser\Node\Expr\ConstFetch;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use function sprintf;

/**
 * @implements Rule<ConstFetch>
 */
class FetchingDeprecatedConstRule implements Rule {
    
    /** @var ReflectionProvider */
    private $reflectionProvider;
    
    /** @var DeprecatedScopeHelper */
    private $deprecatedScopeHelper;
    public function __construct(ReflectionProvider $reflectionProvider, DeprecatedScopeHelper $deprecatedScopeHelper) {
        $this->reflectionProvider = $reflectionProvider;
        $this->deprecatedScopeHelper = $deprecatedScopeHelper;
    }
    public function getNodeType() : string {
        return ConstFetch::class;
    }
    public function processNode(Node $node, Scope $scope) : array {
        if ($this->deprecatedScopeHelper
            ->isScopeDeprecated($scope)) {
            return [];
        }
        if (!$this->reflectionProvider
            ->hasConstant($node->name, $scope)) {
            return [];
        }
        $constantReflection = $this->reflectionProvider
            ->getConstant($node->name, $scope);
        if ($constantReflection->isDeprecated()
            ->yes()) {
            return [
                RuleErrorBuilder::message(sprintf($constantReflection->getDeprecatedDescription() ?? 'Use of constant %s is deprecated.', $constantReflection->getName()))
                    ->identifier('constant.deprecated')
                    ->build(),
            ];
        }
        return [];
    }

}

Classes

Title Deprecated Summary
FetchingDeprecatedConstRule @implements Rule<ConstFetch>

API Navigation

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