From d41d10ca28f7006fb4d00d0fe95b4d6d31bc55aa Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Sun, 13 Nov 2011 14:23:45 +0100 Subject: [PATCH] simplification --- lib/Twig/ExpressionParser.php | 10 +++------- test/Twig/Tests/ExpressionParserTest.php | 15 ++++++++------- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 169ffb4..2fc8306 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -184,14 +184,10 @@ class Twig_ExpressionParser } } - $expr = null; + $expr = array_shift($nodes); - foreach(array_reverse($nodes) as $node) { - if (null === $expr) { - $expr = $node; - } else { - $expr = new Twig_Node_Expression_Binary_Concat($node, $expr, $node->getLine()); - } + foreach($nodes as $node) { + $expr = new Twig_Node_Expression_Binary_Concat($expr, $node, $node->getLine()); } return $expr; diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php index f87dc78..ae5acb7 100644 --- a/test/Twig/Tests/ExpressionParserTest.php +++ b/test/Twig/Tests/ExpressionParserTest.php @@ -149,31 +149,32 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase ), array( '{{ "foo #{bar} baz" }}', new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), new Twig_Node_Expression_Name('bar', 1), - new Twig_Node_Expression_Constant(' baz', 1), 1 ), + new Twig_Node_Expression_Constant(' baz', 1), 1 - ), + ) ), + array( '{{ "foo #{"foo #{bar} baz"} baz" }}', new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), new Twig_Node_Expression_Binary_Concat( - new Twig_Node_Expression_Constant('foo ', 1), new Twig_Node_Expression_Binary_Concat( + new Twig_Node_Expression_Constant('foo ', 1), new Twig_Node_Expression_Name('bar', 1), - new Twig_Node_Expression_Constant(' baz', 1), 1 ), + new Twig_Node_Expression_Constant(' baz', 1), 1 ), - new Twig_Node_Expression_Constant(' baz', 1), 1 ), + new Twig_Node_Expression_Constant(' baz', 1), 1 ), ), -- 1.7.2.5