function PluginManagerInspectionRule::isYamlDiscovery
1 call to PluginManagerInspectionRule::isYamlDiscovery()
- PluginManagerInspectionRule::processNode in vendor/
mglaman/ phpstan-drupal/ src/ Rules/ Classes/ PluginManagerInspectionRule.php
File
-
vendor/
mglaman/ phpstan-drupal/ src/ Rules/ Classes/ PluginManagerInspectionRule.php, line 76
Class
- PluginManagerInspectionRule
- @implements \PHPStan\Rules\Rule<\PhpParser\Node\Stmt\Class_>
Namespace
mglaman\PHPStanDrupal\Rules\ClassesCode
private function isYamlDiscovery(Node\Stmt\Class_ $class) : bool {
foreach ($class->stmts as $stmt) {
// YAML discovery plugin managers must override getDiscovery.
if ($stmt instanceof Node\Stmt\ClassMethod && $stmt->name
->toString() === 'getDiscovery') {
foreach ($stmt->stmts ?? [] as $methodStmt) {
if ($methodStmt instanceof Node\Stmt\If_) {
foreach ($methodStmt->stmts as $ifStmt) {
if ($ifStmt instanceof Node\Stmt\Expression) {
$ifStmtExpr = $ifStmt->expr;
if ($ifStmtExpr instanceof Node\Expr\Assign) {
$ifStmtExprVar = $ifStmtExpr->var;
if ($ifStmtExprVar instanceof Node\Expr\PropertyFetch && $ifStmtExprVar->var instanceof Node\Expr\Variable && $ifStmtExprVar->name instanceof Node\Identifier && $ifStmtExprVar->name->name === 'discovery') {
$ifStmtExprExpr = $ifStmtExpr->expr;
if ($ifStmtExprExpr instanceof Node\Expr\New_ && $ifStmtExprExpr->class instanceof Node\Name && $ifStmtExprExpr->class
->toString() === 'Drupal\\Core\\Plugin\\Discovery\\YamlDiscovery') {
return true;
}
}
}
}
}
}
}
}
}
return false;
}