From bce22e4c32d87597b8e5dbccf2fc0b988b113310 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 29 Dec 2020 10:10:10 +0100 Subject: [PATCH] Use named arguments --- src/Node/Expression/GetAttrExpression.php | 28 +++++++++++++++-------- tests/Node/Expression/GetAttrTest.php | 4 ++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/Node/Expression/GetAttrExpression.php b/src/Node/Expression/GetAttrExpression.php index e6a75ce94..4a993f098 100644 --- a/src/Node/Expression/GetAttrExpression.php +++ b/src/Node/Expression/GetAttrExpression.php @@ -70,17 +70,27 @@ class GetAttrExpression extends AbstractExpression ; if ($this->hasNode('arguments')) { - $compiler->raw(', ')->subcompile($this->getNode('arguments')); - } else { - $compiler->raw(', []'); + $compiler->raw(', arguments: ')->subcompile($this->getNode('arguments')); } - $compiler->raw(', ') - ->repr($this->getAttribute('type')) - ->raw(', ')->repr($this->getAttribute('is_defined_test')) - ->raw(', ')->repr($this->getAttribute('ignore_strict_check')) - ->raw(', ')->repr($env->hasExtension(SandboxExtension::class)) - ->raw(', ')->repr($this->getNode('node')->getTemplateLine()) + if (Template::ANY_CALL !== $type = $this->getAttribute('type')) { + $compiler->raw(', type: ')->repr($type); + } + + if ($this->getAttribute('is_defined_test')) { + $compiler->raw(', isDefinedTest: true'); + } + + if ($this->getAttribute('ignore_strict_check')) { + $compiler->raw(', ignoreStrictCheck: true'); + } + + if ($env->hasExtension(SandboxExtension::class)) { + $compiler->raw(', sandboxed: true'); + } + + $compiler + ->raw(', lineno: ')->repr($this->getNode('node')->getTemplateLine()) ->raw(')') ; } diff --git a/tests/Node/Expression/GetAttrTest.php b/tests/Node/Expression/GetAttrTest.php index c76fb3992..e69f78c80 100644 --- a/tests/Node/Expression/GetAttrTest.php +++ b/tests/Node/Expression/GetAttrTest.php @@ -43,7 +43,7 @@ class GetAttrTest extends NodeTestCase $attr = new ConstantExpression('bar', 1); $args = new ArrayExpression([], 1); $node = new GetAttrExpression($expr, $attr, $args, Template::ANY_CALL, 1); - $tests[] = [$node, sprintf('%s%s, "bar", [], "any", false, false, false, 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; + $tests[] = [$node, sprintf('%s%s, "bar", arguments: [], lineno: 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; $node = new GetAttrExpression($expr, $attr, $args, Template::ARRAY_CALL, 1); $tests[] = [$node, '(($__internal_%s = // line 1'."\n". @@ -53,7 +53,7 @@ class GetAttrTest extends NodeTestCase $args->addElement(new NameExpression('foo', 1)); $args->addElement(new ConstantExpression('bar', 1)); $node = new GetAttrExpression($expr, $attr, $args, Template::METHOD_CALL, 1); - $tests[] = [$node, sprintf('%s%s, "bar", [%s, "bar"], "method", false, false, false, 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))]; + $tests[] = [$node, sprintf('%s%s, "bar", arguments: [%s, "bar"], type: "method", lineno: 1)', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))]; return $tests; }