Skip to content

Commit

Permalink
Merge branch '3.x' into 4.x
Browse files Browse the repository at this point in the history
* 3.x:
  Simplify code even more
  • Loading branch information
fabpot committed Nov 28, 2024
2 parents edef082 + ef3dbab commit af8c63d
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/NodeVisitor/EscaperNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function leaveNode(Node $node, Environment $env): ?Node
} elseif ($node instanceof PrintNode && false !== $type = $this->needEscaping()) {
$expression = $node->getNode('expr');
if ($expression instanceof ConditionalExpression) {
$node->setNode('expr', $this->escapeConditional($expression, $env, $type));
$this->escapeConditional($expression, $env, $type);
} else {
$node->setNode('expr', $this->escapeExpression($expression, $env, $type));
}
Expand All @@ -99,22 +99,21 @@ public function leaveNode(Node $node, Environment $env): ?Node
return $node;
}

private function escapeConditional(ConditionalExpression $expression, Environment $env, string $type): ConditionalExpression
private function escapeConditional(ConditionalExpression $expression, Environment $env, string $type): void
{
$expr2 = $expression->getNode('expr2');
if ($expr2 instanceof ConditionalExpression) {
$expr2 = $this->escapeConditional($expr2, $env, $type);
$this->escapeConditional($expr2, $env, $type);
} else {
$expr2 = $this->escapeExpression($expr2, $env, $type);
$expression->setNode('expr2', $this->escapeExpression($expr2, $env, $type));
}

$expr3 = $expression->getNode('expr3');
if ($expr3 instanceof ConditionalExpression) {
$expr3 = $this->escapeConditional($expr3, $env, $type);
$this->escapeConditional($expr3, $env, $type);
} else {
$expr3 = $this->escapeExpression($expr3, $env, $type);
$expression->setNode('expr3', $this->escapeExpression($expr3, $env, $type));
}

return new ConditionalExpression($expression->getNode('expr1'), $expr2, $expr3, $expression->getTemplateLine());
}

private function escapeExpression(AbstractExpression $expression, Environment $env, string $type): AbstractExpression
Expand Down

0 comments on commit af8c63d

Please sign in to comment.