Skip to content

Commit

Permalink
Add error for no constant
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 23, 2024
1 parent 9509feb commit affdc25
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Rules/Node/ValidConstantFunctionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public function enterNode(Node $node, Environment $env): Node
// Try for named parameters
$argument = $arguments->getNode('constant');
} else {
$this->addError(
'The first param of the function "constant()" is required.',
$node,
'NoConstant'
);

return $node;
}
if (!$argument instanceof ConstantExpression) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public function testRule(): void
'ValidConstantFunction.ClassConstant:20' => 'You cannot use the function "constant()" to resolve class names.',
'ValidConstantFunction.ClassConstant:21' => 'You cannot use the function "constant()" to resolve class names.',
'ValidConstantFunction.StringConstant:22' => 'The first param of the function "constant()" must be a string.',
'ValidConstantFunction.NoConstant:24' => 'The first param of the function "constant()" is required.',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
{{ constant(constant='ThisDoesNotExist::CLASS') }}
{{ constant(constant=1) }}

{{ constant() }}
{{ notConstant('ThisDoesNotExist::class') }}
{% endblock %}

0 comments on commit affdc25

Please sign in to comment.