function PluginManagerInspectionRule::processNode
File
-
vendor/
mglaman/ phpstan-drupal/ src/ Rules/ Classes/ PluginManagerInspectionRule.php, line 29
Class
- PluginManagerInspectionRule
- @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Class_>
Namespace
mglaman\PHPStanDrupal\Rules\ClassesCode
public function processNode(Node $node, Scope $scope) : array {
if ($node->namespacedName === null) {
// anonymous class
return [];
}
if ($node->extends === null) {
return [];
}
$className = (string) $node->namespacedName;
$pluginManagerType = new ObjectType($className);
$pluginManagerInterfaceType = new ObjectType('\\Drupal\\Component\\Plugin\\PluginManagerInterface');
if (!$pluginManagerInterfaceType->isSuperTypeOf($pluginManagerType)
->yes()) {
return [];
}
$errors = [];
if ($this->isYamlDiscovery($node)) {
$errors = $this->inspectYamlPluginManager($node);
}
else {
// @todo inspect annotated plugin managers.
}
$hasAlterInfoSet = false;
foreach ($node->stmts as $stmt) {
if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name
->toString() === '__construct') {
foreach ($stmt->stmts ?? [] as $statement) {
if ($statement instanceof Node\Stmt\Expression) {
$statement = $statement->expr;
}
if ($statement instanceof Node\Expr\MethodCall && $statement->name instanceof Node\Identifier && $statement->name->name === 'alterInfo') {
$hasAlterInfoSet = true;
}
}
}
}
if (!$hasAlterInfoSet) {
$errors[] = 'Plugin definitions cannot be altered.';
}
return $errors;
}