Skip to content

Commit cf936a7

Browse files
committed
Add notes for next steps in RenderCallbackRule
1 parent ea78bdc commit cf936a7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Rules/Drupal/RenderCallbackRule.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function processNode(Node $node, Scope $scope): array
6060

6161
$errors = [];
6262

63+
// @todo Move into its own rule.
6364
if ($keyChecked === '#lazy_builder') {
6465
if (!$value instanceof Node\Expr\Array_) {
6566
return [
@@ -73,10 +74,13 @@ public function processNode(Node $node, Scope $scope): array
7374
if ($value->items[0] === null) {
7475
return [];
7576
}
77+
// @todo take $value->items[1] and validate parameters against the callback.
7678
$errors[] = $this->doProcessNode($value->items[0]->value, $scope, $keyChecked, 0);
7779
} elseif ($keyChecked === '#access_callback') {
80+
// @todo move into its own rule.
7881
$errors[] = $this->doProcessNode($value, $scope, $keyChecked, 0);
7982
} else {
83+
// @todo keep here.
8084
if (!$value instanceof Node\Expr\Array_) {
8185
return [
8286
RuleErrorBuilder::message(sprintf('The "%s" render array value expects an array of callbacks.', $keyChecked))
@@ -114,7 +118,7 @@ private function doProcessNode(Node\Expr $node, Scope $scope, string $keyChecked
114118
}
115119
// We can determine if the callback is callable through the type system. However, we cannot determine
116120
// if it is just a function or a static class call (MyClass::staticFunc).
117-
if ($this->reflectionProvider->hasFunction(new \PhpParser\Node\Name($type->getValue()), null)) {
121+
if ($this->reflectionProvider->hasFunction(new Node\Name($type->getValue()), null)) {
118122
return RuleErrorBuilder::message(
119123
sprintf("%s callback %s at key '%s' is not trusted.", $keyChecked, $type->describe(VerbosityLevel::value()), $pos)
120124
)->line($errorLine)
@@ -185,6 +189,7 @@ private function doProcessNode(Node\Expr $node, Scope $scope, string $keyChecked
185189
return null;
186190
}
187191

192+
// @todo move to a helper, as Drupal uses `service:method` references a lot.
188193
private function getType(Node\Expr $node, Scope $scope): Type
189194
{
190195
$type = $scope->getType($node);

0 commit comments

Comments
 (0)