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

Breadcrumb

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

class ConditionManagerCreateInstanceContextConfigurationRule

@implements Rule<Node\Expr\MethodCall>

Hierarchy

  • class \mglaman\PHPStanDrupal\Rules\Deprecations\ConditionManagerCreateInstanceContextConfigurationRule implements \PHPStan\Rules\Rule

Expanded class hierarchy of ConditionManagerCreateInstanceContextConfigurationRule

File

vendor/mglaman/phpstan-drupal/src/Rules/Deprecations/ConditionManagerCreateInstanceContextConfigurationRule.php, line 18

Namespace

mglaman\PHPStanDrupal\Rules\Deprecations
View source
final class ConditionManagerCreateInstanceContextConfigurationRule implements Rule {
    public function getNodeType() : string {
        return Node\Expr\MethodCall::class;
    }
    public function processNode(Node $node, Scope $scope) : array {
        if (!$node->name instanceof Node\Identifier) {
            return [];
        }
        if ($node->name
            ->toString() !== 'createInstance') {
            return [];
        }
        $args = $node->getArgs();
        if (count($args) !== 2) {
            return [];
        }
        $conditionManagerType = new ObjectType(ConditionManager::class);
        $type = $scope->getType($node->var);
        if (!$conditionManagerType->isSuperTypeOf($type)
            ->yes()) {
            return [];
        }
        $configuration = $args[1];
        $configurationType = $scope->getType($configuration->value);
        // Must be an array, return [] and allow parameter inspection rule to report error.
        if (!$configurationType instanceof ConstantArrayType) {
            return [];
        }
        foreach ($configurationType->getKeyTypes() as $keyType) {
            if ($keyType instanceof ConstantStringType && $keyType->getValue() === 'context') {
                return [
                    RuleErrorBuilder::message('Passing context values to plugins via configuration is deprecated in drupal:9.1.0 and will be removed before drupal:10.0.0. Instead, call ::setContextValue() on the plugin itself. See https://www.drupal.org/node/3120980')->line($node->getStartLine())
                        ->build(),
                ];
            }
        }
        return [];
    }

}

Members

Title Sort descending Modifiers Object type Summary
ConditionManagerCreateInstanceContextConfigurationRule::getNodeType public function
ConditionManagerCreateInstanceContextConfigurationRule::processNode public function

API Navigation

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