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

Breadcrumb

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

function RequestStackGetMainRequestRule::processNode

File

vendor/mglaman/phpstan-drupal/src/Rules/Drupal/RequestStackGetMainRequestRule.php, line 27

Class

RequestStackGetMainRequestRule
@implements Rule<Node\Expr\MethodCall>

Namespace

mglaman\PHPStanDrupal\Rules\Drupal

Code

public function processNode(Node $node, Scope $scope) : array {
    if (DeprecatedScopeCheck::inDeprecatedScope($scope)) {
        return [];
    }
    [
        $major,
        $minor,
    ] = explode('.', Drupal::VERSION, 3);
    // Only valid for 9.3 -> 9.5. Deprecated in Drupal 10.
    if ($major !== '9' || (int) $minor < 3) {
        return [];
    }
    if (!$node->name instanceof Node\Identifier) {
        return [];
    }
    $method_name = $node->name
        ->toString();
    if ($method_name !== 'getMasterRequest') {
        return [];
    }
    $type = $scope->getType($node->var);
    $symfonyRequestStackType = new ObjectType(SymfonyRequestStack::class);
    if ($symfonyRequestStackType->isSuperTypeOf($type)
        ->yes()) {
        $message = sprintf('%s::getMasterRequest() is deprecated in drupal:9.3.0 and is removed from drupal:10.0.0 for Symfony 6 compatibility. Use the forward compatibility shim class %s and its getMainRequest() method instead.', SymfonyRequestStack::class, 'Drupal\\Core\\Http\\RequestStack');
        return [
            RuleErrorBuilder::message($message)->tip('Change record: https://www.drupal.org/node/3253744')
                ->build(),
        ];
    }
    return [];
}
RSS feed
Powered by Drupal