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

Breadcrumb

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

function SymfonyCmfRouteObjectInterfaceConstantsRule::processNode

File

vendor/mglaman/phpstan-drupal/src/Rules/Deprecations/SymfonyCmfRouteObjectInterfaceConstantsRule.php, line 27

Class

SymfonyCmfRouteObjectInterfaceConstantsRule
@implements Rule<Node\Expr\ClassConstFetch>

Namespace

mglaman\PHPStanDrupal\Rules\Deprecations

Code

public function processNode(Node $node, Scope $scope) : array {
    if (!$node->name instanceof Node\Identifier) {
        return [];
    }
    if (!$node->class instanceof Node\Name) {
        return [];
    }
    $constantName = $node->name->name;
    $className = $node->class;
    $classType = $scope->resolveTypeByName($className);
    if (!$classType->hasConstant($constantName)
        ->yes()) {
        return [];
    }
    if (DeprecatedScopeCheck::inDeprecatedScope($scope)) {
        return [];
    }
    [
        $major,
        $minor,
    ] = explode('.', Drupal::VERSION, 3);
    if ($major !== '9') {
        return [];
    }
    if ((int) $minor < 1) {
        return [];
    }
    // @phpstan-ignore-next-line
    $cmfRouteObjectInterfaceType = new ObjectType(SymfonyRouteObjectInterface::class);
    if (!$classType->isSuperTypeOf($cmfRouteObjectInterfaceType)
        ->yes()) {
        return [];
    }
    $coreRouteObjectInterfaceType = new ObjectType(RouteObjectInterface::class);
    if (!$coreRouteObjectInterfaceType->hasConstant($constantName)
        ->yes()) {
        return [
            RuleErrorBuilder::message(sprintf('The core dependency symfony-cmf/routing is deprecated and %s::%s is not supported.', $className, $constantName))->tip('Change record: https://www.drupal.org/node/3151009')
                ->build(),
        ];
    }
    return [
        RuleErrorBuilder::message(sprintf('%s::%s is deprecated and removed in Drupal 10. Use \\Drupal\\Core\\Routing\\RouteObjectInterface::%2$s instead.', $className, $constantName))->tip('Change record: https://www.drupal.org/node/3151009')
            ->build(),
    ];
}
RSS feed
Powered by Drupal