function ConditionManagerCreateInstanceContextConfigurationRule::processNode
File
-
vendor/
mglaman/ phpstan-drupal/ src/ Rules/ Deprecations/ ConditionManagerCreateInstanceContextConfigurationRule.php, line 25
Class
- ConditionManagerCreateInstanceContextConfigurationRule
- @implements Rule<Node\Expr\MethodCall>
Namespace
mglaman\PHPStanDrupal\Rules\DeprecationsCode
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 [];
}