From c92feb6ab950011a0ca06af55ce54ed6f6a0d91d Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 16 Feb 2019 20:35:08 +0100 Subject: [PATCH 1/3] prepared use statements --- lib/Twig/Environment.php | 14 +++---- lib/Twig/Error/Loader.php | 4 +- lib/Twig/Extension/GlobalsInterface.php | 2 +- lib/Twig/Extension/InitRuntimeInterface.php | 2 +- lib/Twig/Loader/String.php | 2 +- lib/Twig/Node/Module.php | 18 ++++++++- lib/Twig/Node/Set.php | 2 +- lib/Twig/TemplateWrapper.php | 2 +- lib/Twig/Token.php | 2 +- lib/Twig/TokenParserBrokerInterface.php | 2 +- test/Twig/Tests/EnvironmentTest.php | 4 +- test/Twig/Tests/Node/ModuleTest.php | 45 ++++++++++++++++++--- 12 files changed, 75 insertions(+), 24 deletions(-) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index dfc44a9f4..d2fa42125 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -100,7 +100,7 @@ class Twig_Environment if (null !== $loader) { $this->setLoader($loader); } else { - @trigger_error('Not passing a Twig_LoaderInterface as the first constructor argument of Twig_Environment is deprecated since version 1.21.', E_USER_DEPRECATED); + @trigger_error('Not passing a "Twig\Lodaer\LoaderInterface" as the first constructor argument of "Twig\Environment" is deprecated since version 1.21.', E_USER_DEPRECATED); } $options = array_merge([ @@ -130,14 +130,14 @@ class Twig_Environment if (\is_string($this->originalCache)) { $r = new \ReflectionMethod($this, 'writeCacheFile'); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The \Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('The Twig\Environment::writeCacheFile method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); $this->bcWriteCacheFile = true; } $r = new \ReflectionMethod($this, 'getCacheFilename'); if (__CLASS__ !== $r->getDeclaringClass()->getName()) { - @trigger_error('The \Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); + @trigger_error('The Twig\Environment::getCacheFilename method is deprecated since version 1.22 and will be removed in Twig 2.0.', E_USER_DEPRECATED); $this->bcGetCacheFilename = true; } @@ -663,7 +663,7 @@ class Twig_Environment public function tokenize($source, $name = null) { if (!$source instanceof \Twig\Source) { - @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); $source = new \Twig\Source($source, $name); } @@ -763,7 +763,7 @@ class Twig_Environment public function compileSource($source, $name = null) { if (!$source instanceof \Twig\Source) { - @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); $source = new \Twig\Source($source, $name); } @@ -834,7 +834,7 @@ class Twig_Environment $m = new \ReflectionMethod($extension, 'initRuntime'); if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig_Extension_InitRuntimeInterface if needed (not recommended).', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Defining the initRuntime() method in the "%s" extension is deprecated since version 1.23. Use the `needs_environment` option to get the Twig_Environment instance in filters, functions, or tests; or explicitly implement Twig\Extension\InitRuntimeInterface if needed (not recommended).', $name), E_USER_DEPRECATED); } } @@ -1472,7 +1472,7 @@ class Twig_Environment $m = new \ReflectionMethod($extension, 'getGlobals'); if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { - @trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig_Extension_GlobalsInterface is deprecated since version 1.23.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Defining the getGlobals() method in the "%s" extension without explicitly implementing Twig\Extension\GlobalsInterface is deprecated since version 1.23.', $name), E_USER_DEPRECATED); } } diff --git a/lib/Twig/Error/Loader.php b/lib/Twig/Error/Loader.php index 281be82b1..e8db0c4e1 100644 --- a/lib/Twig/Error/Loader.php +++ b/lib/Twig/Error/Loader.php @@ -16,9 +16,9 @@ * if a template cannot be loaded, there is nothing to guess. * However, when a template is loaded from another one, then, we need * to find the current context and this is automatically done by - * \Twig\Template::displayWithErrorHandling(). + * Twig\Template::displayWithErrorHandling(). * - * This strategy makes \Twig\Environment::resolveTemplate() much faster. + * This strategy makes Twig\Environment::resolveTemplate() much faster. * * @author Fabien Potencier */ diff --git a/lib/Twig/Extension/GlobalsInterface.php b/lib/Twig/Extension/GlobalsInterface.php index 388216713..434582ecb 100644 --- a/lib/Twig/Extension/GlobalsInterface.php +++ b/lib/Twig/Extension/GlobalsInterface.php @@ -10,7 +10,7 @@ */ /** - * Enables usage of the deprecated \Twig\Extension\AbstractExtension::getGlobals() method. + * Enables usage of the deprecated Twig\Extension\AbstractExtension::getGlobals() method. * * Explicitly implement this interface if you really need to implement the * deprecated getGlobals() method in your extensions. diff --git a/lib/Twig/Extension/InitRuntimeInterface.php b/lib/Twig/Extension/InitRuntimeInterface.php index e33f544ed..515dd2da5 100644 --- a/lib/Twig/Extension/InitRuntimeInterface.php +++ b/lib/Twig/Extension/InitRuntimeInterface.php @@ -10,7 +10,7 @@ */ /** - * Enables usage of the deprecated \Twig\Extension\AbstractExtension::initRuntime() method. + * Enables usage of the deprecated Twig\Extension\AbstractExtension::initRuntime() method. * * Explicitly implement this interface if you really need to implement the * deprecated initRuntime() method in your extensions. diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index 571f4b7c4..7398aecc4 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use Twig_Loader_Array instead or \Twig\Environment::createTemplate().', E_USER_DEPRECATED); +@trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use "Twig\Loader\ArrayLoader" instead or "Twig\Environment::createTemplate()".', E_USER_DEPRECATED); /** * Loads a template from a string. diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index d4b9164f6..38ca4c04a 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -154,10 +154,26 @@ class Twig_Node_Module extends \Twig\Node\Node { $compiler ->write("\n\n") + ; + if (!$this->getAttribute('index')) { + $compiler + ->write("use Twig\Environment;\n") + ->write("use Twig\Error\LoaderError;\n") + ->write("use Twig\Error\RuntimeError;\n") + ->write("use Twig\Markup;\n") + ->write("use Twig\Sandbox\SecurityError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedTagError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFilterError;\n") + ->write("use Twig\Sandbox\SecurityNotAllowedFunctionError;\n") + ->write("use Twig\Source;\n") + ->write("use Twig\Template;\n\n") + ; + } + $compiler // if the template name contains */, add a blank to avoid a PHP parse error ->write('/* '.str_replace('*/', '* /', $this->source->getName())." */\n") ->write('class '.$compiler->getEnvironment()->getTemplateClass($this->source->getName(), $this->getAttribute('index'))) - ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) + ->raw(sprintf(" extends %s\n", $compiler->getEnvironment()->getBaseTemplateClass())) ->write("{\n") ->indent() ; diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index 700e5bd67..81f412e0b 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -23,7 +23,7 @@ class Twig_Node_Set extends \Twig\Node\Node implements \Twig\Node\NodeCaptureInt /* * Optimizes the node when capture is used for a large block of text. * - * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new \Twig\Markup("foo"); + * {% set foo %}foo{% endset %} is compiled to $context['foo'] = new Twig\Markup("foo"); */ if ($this->getAttribute('capture')) { $this->setAttribute('safe', true); diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php index 3805fc688..59aabf799 100644 --- a/lib/Twig/TemplateWrapper.php +++ b/lib/Twig/TemplateWrapper.php @@ -21,7 +21,7 @@ final class Twig_TemplateWrapper /** * This method is for internal use only and should never be called - * directly (use \Twig\Environment::load() instead). + * directly (use Twig\Environment::load() instead). * * @internal */ diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php index 4bcd76b91..2251d7066 100644 --- a/lib/Twig/Token.php +++ b/lib/Twig/Token.php @@ -159,7 +159,7 @@ class Twig_Token throw new \LogicException(sprintf('Token of type "%s" does not exist.', $type)); } - return $short ? $name : '\Twig\Token::'.$name; + return $short ? $name : 'Twig\Token::'.$name; } /** diff --git a/lib/Twig/TokenParserBrokerInterface.php b/lib/Twig/TokenParserBrokerInterface.php index 7a5d563ec..10f79209b 100644 --- a/lib/Twig/TokenParserBrokerInterface.php +++ b/lib/Twig/TokenParserBrokerInterface.php @@ -31,7 +31,7 @@ interface Twig_TokenParserBrokerInterface public function getTokenParser($tag); /** - * Calls \Twig\TokenParser\TokenParserInterface::setParser on all parsers the implementation knows of. + * Calls Twig\TokenParser\TokenParserInterface::setParser on all parsers the implementation knows of. */ public function setParser(Twig_ParserInterface $parser); diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index 78f226838..e63a42e00 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -381,7 +381,9 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase // should be replaced by the following in 2.0 (this current code is just to avoid a dep notice) // $extension = $this->getMockBuilder('\Twig\Extension\AbstractExtension')->getMock(); $extension = eval(<< 1,); + return array ( 30 => 1,); } /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ @@ -99,8 +110,19 @@ EOF $tests[] = [$node, << 1, 24 => 2, 11 => 1,); + return array ( 37 => 1, 35 => 2, 22 => 1,); } /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ @@ -170,8 +192,19 @@ EOF $tests[] = [$node, << 2, 15 => 4, 9 => 2,); + return array ( 28 => 2, 26 => 4, 20 => 2,); } /** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */ From 1ddb8253365138cd8934e40e99eb754d22abfaef Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Feb 2019 10:37:46 +0100 Subject: [PATCH 2/3] moved most FQCN to use statements --- lib/Twig/BaseNodeVisitor.php | 22 +- lib/Twig/Cache/Filesystem.php | 4 +- lib/Twig/Cache/Null.php | 4 +- lib/Twig/Compiler.php | 9 +- lib/Twig/ContainerRuntimeLoader.php | 4 +- lib/Twig/Environment.php | 235 ++++++++------ lib/Twig/Error.php | 15 +- lib/Twig/Error/Loader.php | 4 +- lib/Twig/Error/Runtime.php | 4 +- lib/Twig/Error/Syntax.php | 4 +- lib/Twig/ExpressionParser.php | 282 +++++++++-------- lib/Twig/Extension.php | 7 +- lib/Twig/Extension/Core.php | 287 ++++++++++-------- lib/Twig/Extension/Debug.php | 10 +- lib/Twig/Extension/Escaper.php | 13 +- lib/Twig/Extension/Optimizer.php | 7 +- lib/Twig/Extension/Profiler.php | 14 +- lib/Twig/Extension/Sandbox.php | 15 +- lib/Twig/Extension/Staging.php | 10 +- lib/Twig/Extension/StringLoader.php | 10 +- lib/Twig/ExtensionInterface.php | 19 +- lib/Twig/FactoryRuntimeLoader.php | 4 +- lib/Twig/Filter.php | 4 +- lib/Twig/Filter/Method.php | 4 +- lib/Twig/FilterInterface.php | 4 +- lib/Twig/Function.php | 4 +- lib/Twig/Function/Method.php | 4 +- lib/Twig/FunctionInterface.php | 4 +- lib/Twig/Lexer.php | 68 +++-- lib/Twig/LexerInterface.php | 10 +- lib/Twig/Loader/Array.php | 16 +- lib/Twig/Loader/Chain.php | 46 +-- lib/Twig/Loader/Filesystem.php | 32 +- lib/Twig/Loader/String.php | 7 +- lib/Twig/LoaderInterface.php | 8 +- lib/Twig/Node.php | 7 +- lib/Twig/Node/AutoEscape.php | 7 +- lib/Twig/Node/Block.php | 7 +- lib/Twig/Node/BlockReference.php | 8 +- lib/Twig/Node/Body.php | 4 +- lib/Twig/Node/CheckSecurity.php | 21 +- lib/Twig/Node/Deprecated.php | 13 +- lib/Twig/Node/Do.php | 10 +- lib/Twig/Node/Embed.php | 13 +- lib/Twig/Node/Expression.php | 4 +- lib/Twig/Node/Expression/Array.php | 16 +- lib/Twig/Node/Expression/AssignName.php | 7 +- lib/Twig/Node/Expression/Binary.php | 9 +- lib/Twig/Node/Expression/Binary/Add.php | 7 +- lib/Twig/Node/Expression/Binary/And.php | 7 +- .../Node/Expression/Binary/BitwiseAnd.php | 7 +- lib/Twig/Node/Expression/Binary/BitwiseOr.php | 7 +- .../Node/Expression/Binary/BitwiseXor.php | 7 +- lib/Twig/Node/Expression/Binary/Concat.php | 7 +- lib/Twig/Node/Expression/Binary/Div.php | 7 +- lib/Twig/Node/Expression/Binary/EndsWith.php | 9 +- lib/Twig/Node/Expression/Binary/Equal.php | 7 +- lib/Twig/Node/Expression/Binary/FloorDiv.php | 9 +- lib/Twig/Node/Expression/Binary/Greater.php | 7 +- .../Node/Expression/Binary/GreaterEqual.php | 7 +- lib/Twig/Node/Expression/Binary/In.php | 9 +- lib/Twig/Node/Expression/Binary/Less.php | 7 +- lib/Twig/Node/Expression/Binary/LessEqual.php | 7 +- lib/Twig/Node/Expression/Binary/Matches.php | 9 +- lib/Twig/Node/Expression/Binary/Mod.php | 7 +- lib/Twig/Node/Expression/Binary/Mul.php | 7 +- lib/Twig/Node/Expression/Binary/NotEqual.php | 7 +- lib/Twig/Node/Expression/Binary/NotIn.php | 9 +- lib/Twig/Node/Expression/Binary/Or.php | 7 +- lib/Twig/Node/Expression/Binary/Power.php | 9 +- lib/Twig/Node/Expression/Binary/Range.php | 9 +- .../Node/Expression/Binary/StartsWith.php | 9 +- lib/Twig/Node/Expression/Binary/Sub.php | 7 +- lib/Twig/Node/Expression/BlockReference.php | 14 +- lib/Twig/Node/Expression/Call.php | 34 ++- lib/Twig/Node/Expression/Conditional.php | 9 +- lib/Twig/Node/Expression/Constant.php | 7 +- .../Node/Expression/ExtensionReference.php | 7 +- lib/Twig/Node/Expression/Filter.php | 15 +- lib/Twig/Node/Expression/Filter/Default.php | 25 +- lib/Twig/Node/Expression/Function.php | 12 +- lib/Twig/Node/Expression/GetAttr.php | 12 +- lib/Twig/Node/Expression/MethodCall.php | 13 +- lib/Twig/Node/Expression/Name.php | 7 +- lib/Twig/Node/Expression/NullCoalesce.php | 21 +- lib/Twig/Node/Expression/Parent.php | 7 +- lib/Twig/Node/Expression/TempName.php | 7 +- lib/Twig/Node/Expression/Test.php | 14 +- lib/Twig/Node/Expression/Test/Constant.php | 7 +- lib/Twig/Node/Expression/Test/Defined.php | 32 +- lib/Twig/Node/Expression/Test/Divisibleby.php | 7 +- lib/Twig/Node/Expression/Test/Even.php | 7 +- lib/Twig/Node/Expression/Test/Null.php | 7 +- lib/Twig/Node/Expression/Test/Odd.php | 7 +- lib/Twig/Node/Expression/Test/Sameas.php | 7 +- lib/Twig/Node/Expression/Unary.php | 9 +- lib/Twig/Node/Expression/Unary/Neg.php | 7 +- lib/Twig/Node/Expression/Unary/Not.php | 7 +- lib/Twig/Node/Expression/Unary/Pos.php | 7 +- lib/Twig/Node/Flush.php | 7 +- lib/Twig/Node/For.php | 17 +- lib/Twig/Node/ForLoop.php | 7 +- lib/Twig/Node/If.php | 7 +- lib/Twig/Node/Import.php | 13 +- lib/Twig/Node/Include.php | 18 +- lib/Twig/Node/Macro.php | 13 +- lib/Twig/Node/Module.php | 83 ++--- lib/Twig/Node/Print.php | 11 +- lib/Twig/Node/Sandbox.php | 7 +- lib/Twig/Node/SandboxedPrint.php | 15 +- lib/Twig/Node/Set.php | 19 +- lib/Twig/Node/SetTemp.php | 7 +- lib/Twig/Node/Spaceless.php | 7 +- lib/Twig/Node/Text.php | 8 +- lib/Twig/Node/With.php | 12 +- lib/Twig/NodeInterface.php | 4 +- lib/Twig/NodeTraverser.php | 11 +- lib/Twig/NodeVisitor/Escaper.php | 54 ++-- lib/Twig/NodeVisitor/Optimizer.php | 77 +++-- lib/Twig/NodeVisitor/SafeAnalysis.php | 35 ++- lib/Twig/NodeVisitor/Sandbox.php | 33 +- lib/Twig/NodeVisitorInterface.php | 6 +- lib/Twig/Parser.php | 92 +++--- lib/Twig/ParserInterface.php | 10 +- lib/Twig/Profiler/Dumper/Base.php | 12 +- lib/Twig/Profiler/Dumper/Blackfire.php | 8 +- lib/Twig/Profiler/Dumper/Html.php | 13 +- lib/Twig/Profiler/Dumper/Text.php | 11 +- lib/Twig/Profiler/Node/EnterProfile.php | 10 +- lib/Twig/Profiler/Node/LeaveProfile.php | 7 +- lib/Twig/Profiler/NodeVisitor/Profiler.php | 39 ++- lib/Twig/Sandbox/SecurityError.php | 4 +- .../Sandbox/SecurityNotAllowedFilterError.php | 4 +- .../SecurityNotAllowedFunctionError.php | 4 +- .../Sandbox/SecurityNotAllowedMethodError.php | 4 +- .../SecurityNotAllowedPropertyError.php | 4 +- .../Sandbox/SecurityNotAllowedTagError.php | 4 +- lib/Twig/Sandbox/SecurityPolicy.php | 22 +- lib/Twig/SimpleFilter.php | 4 +- lib/Twig/SimpleFunction.php | 4 +- lib/Twig/SourceContextLoaderInterface.php | 7 +- lib/Twig/Template.php | 50 +-- lib/Twig/TemplateInterface.php | 4 +- lib/Twig/TemplateWrapper.php | 8 +- lib/Twig/Test/IntegrationTestCase.php | 33 +- lib/Twig/Test/Method.php | 4 +- lib/Twig/Test/NodeTestCase.php | 13 +- lib/Twig/TokenParser.php | 7 +- lib/Twig/TokenParser/AutoEscape.php | 28 +- lib/Twig/TokenParser/Block.php | 34 ++- lib/Twig/TokenParser/Deprecated.php | 12 +- lib/Twig/TokenParser/Do.php | 12 +- lib/Twig/TokenParser/Embed.php | 32 +- lib/Twig/TokenParser/Extends.php | 14 +- lib/Twig/TokenParser/Filter.php | 23 +- lib/Twig/TokenParser/Flush.php | 12 +- lib/Twig/TokenParser/For.php | 54 ++-- lib/Twig/TokenParser/From.php | 22 +- lib/Twig/TokenParser/If.php | 26 +- lib/Twig/TokenParser/Import.php | 15 +- lib/Twig/TokenParser/Include.php | 20 +- lib/Twig/TokenParser/Macro.php | 24 +- lib/Twig/TokenParser/Sandbox.php | 27 +- lib/Twig/TokenParser/Set.php | 25 +- lib/Twig/TokenParser/Spaceless.php | 16 +- lib/Twig/TokenParser/Use.php | 28 +- lib/Twig/TokenParser/With.php | 20 +- lib/Twig/TokenParserBroker.php | 10 +- lib/Twig/TokenParserBrokerInterface.php | 4 +- lib/Twig/TokenParserInterface.php | 10 +- lib/Twig/TokenStream.php | 32 +- lib/Twig/Util/DeprecationCollector.php | 13 +- test/Twig/Tests/Cache/FilesystemTest.php | 6 +- test/Twig/Tests/CompilerTest.php | 5 +- .../Twig/Tests/ContainerRuntimeLoaderTest.php | 6 +- test/Twig/Tests/CustomExtensionTest.php | 11 +- test/Twig/Tests/EnvironmentTest.php | 131 ++++---- test/Twig/Tests/ErrorTest.php | 47 +-- test/Twig/Tests/ExpressionParserTest.php | 216 ++++++------- test/Twig/Tests/Extension/CoreTest.php | 28 +- test/Twig/Tests/Extension/SandboxTest.php | 32 +- test/Twig/Tests/FactoryRuntimeLoaderTest.php | 6 +- test/Twig/Tests/FileCachingTest.php | 5 +- .../FileExtensionEscapingStrategyTest.php | 4 +- test/Twig/Tests/IntegrationTest.php | 76 +++-- test/Twig/Tests/LegacyIntegrationTest.php | 7 +- test/Twig/Tests/LexerTest.php | 191 ++++++------ test/Twig/Tests/Loader/ArrayTest.php | 24 +- test/Twig/Tests/Loader/ChainTest.php | 44 +-- test/Twig/Tests/Loader/FilesystemTest.php | 36 ++- test/Twig/Tests/NativeExtensionTest.php | 5 +- test/Twig/Tests/Node/AutoEscapeTest.php | 15 +- test/Twig/Tests/Node/BlockReferenceTest.php | 9 +- test/Twig/Tests/Node/BlockTest.php | 14 +- test/Twig/Tests/Node/DeprecatedTest.php | 35 ++- test/Twig/Tests/Node/DoTest.php | 14 +- test/Twig/Tests/Node/Expression/ArrayTest.php | 20 +- .../Tests/Node/Expression/AssignNameTest.php | 9 +- .../Tests/Node/Expression/Binary/AddTest.php | 18 +- .../Tests/Node/Expression/Binary/AndTest.php | 18 +- .../Node/Expression/Binary/ConcatTest.php | 18 +- .../Tests/Node/Expression/Binary/DivTest.php | 18 +- .../Node/Expression/Binary/FloorDivTest.php | 18 +- .../Tests/Node/Expression/Binary/ModTest.php | 18 +- .../Tests/Node/Expression/Binary/MulTest.php | 18 +- .../Tests/Node/Expression/Binary/OrTest.php | 18 +- .../Tests/Node/Expression/Binary/SubTest.php | 18 +- test/Twig/Tests/Node/Expression/CallTest.php | 4 +- .../Tests/Node/Expression/ConditionalTest.php | 22 +- .../Tests/Node/Expression/ConstantTest.php | 9 +- .../Twig/Tests/Node/Expression/FilterTest.php | 73 +++-- .../Tests/Node/Expression/FunctionTest.php | 53 ++-- .../Tests/Node/Expression/GetAttrTest.php | 41 +-- test/Twig/Tests/Node/Expression/NameTest.php | 16 +- .../Node/Expression/NullCoalesceTest.php | 13 +- .../Twig/Tests/Node/Expression/ParentTest.php | 9 +- test/Twig/Tests/Node/Expression/TestTest.php | 44 +-- .../Tests/Node/Expression/Unary/NegTest.php | 16 +- .../Tests/Node/Expression/Unary/NotTest.php | 14 +- .../Tests/Node/Expression/Unary/PosTest.php | 14 +- test/Twig/Tests/Node/ForTest.php | 70 +++-- test/Twig/Tests/Node/IfTest.php | 51 ++-- test/Twig/Tests/Node/ImportTest.php | 19 +- test/Twig/Tests/Node/IncludeTest.php | 43 +-- test/Twig/Tests/Node/MacroTest.php | 28 +- test/Twig/Tests/Node/ModuleTest.php | 76 +++-- test/Twig/Tests/Node/PrintTest.php | 12 +- test/Twig/Tests/Node/SandboxTest.php | 14 +- test/Twig/Tests/Node/SandboxedPrintTest.php | 10 +- test/Twig/Tests/Node/SetTest.php | 46 +-- test/Twig/Tests/Node/SpacelessTest.php | 15 +- test/Twig/Tests/Node/TextTest.php | 9 +- test/Twig/Tests/NodeVisitor/OptimizerTest.php | 22 +- test/Twig/Tests/ParserTest.php | 100 +++--- .../Tests/Profiler/Dumper/AbstractTest.php | 4 +- .../Tests/Profiler/Dumper/BlackfireTest.php | 4 +- test/Twig/Tests/Profiler/Dumper/HtmlTest.php | 4 +- test/Twig/Tests/Profiler/Dumper/TextTest.php | 4 +- test/Twig/Tests/Profiler/ProfileTest.php | 34 ++- test/Twig/Tests/TemplateTest.php | 85 +++--- test/Twig/Tests/TemplateWrapperTest.php | 20 +- test/Twig/Tests/TokenStreamTest.php | 31 +- .../Tests/Util/DeprecationCollectorTest.php | 10 +- 243 files changed, 3264 insertions(+), 2118 deletions(-) diff --git a/lib/Twig/BaseNodeVisitor.php b/lib/Twig/BaseNodeVisitor.php index 7cfe672da..a2cb1a466 100644 --- a/lib/Twig/BaseNodeVisitor.php +++ b/lib/Twig/BaseNodeVisitor.php @@ -9,25 +9,29 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Node\Node; +use Twig\Environment; + /** * Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x. * * @author Fabien Potencier */ -abstract class Twig_BaseNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface +abstract class Twig_BaseNodeVisitor implements NodeVisitorInterface { - final public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) + final public function enterNode(Twig_NodeInterface $node, Environment $env) { - if (!$node instanceof \Twig\Node\Node) { + if (!$node instanceof Node) { throw new \LogicException(sprintf('%s only supports Twig_Node instances.', __CLASS__)); } return $this->doEnterNode($node, $env); } - final public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env) + final public function leaveNode(Twig_NodeInterface $node, Environment $env) { - if (!$node instanceof \Twig\Node\Node) { + if (!$node instanceof Node) { throw new \LogicException(sprintf('%s only supports Twig_Node instances.', __CLASS__)); } @@ -37,16 +41,16 @@ abstract class Twig_BaseNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInte /** * Called before child nodes are visited. * - * @return \Twig\Node\Node The modified node + * @return Node The modified node */ - abstract protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env); + abstract protected function doEnterNode(Node $node, Environment $env); /** * Called after child nodes are visited. * - * @return \Twig\Node\Node|false The modified node or false if the node must be removed + * @return Node|false The modified node or false if the node must be removed */ - abstract protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env); + abstract protected function doLeaveNode(Node $node, Environment $env); } class_alias('Twig_BaseNodeVisitor', 'Twig\NodeVisitor\AbstractNodeVisitor', false); diff --git a/lib/Twig/Cache/Filesystem.php b/lib/Twig/Cache/Filesystem.php index 51e818834..188a46ed5 100644 --- a/lib/Twig/Cache/Filesystem.php +++ b/lib/Twig/Cache/Filesystem.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Cache\CacheInterface; + /** * Implements a cache on the filesystem. * * @author Andrew Tch */ -class Twig_Cache_Filesystem implements \Twig\Cache\CacheInterface +class Twig_Cache_Filesystem implements CacheInterface { const FORCE_BYTECODE_INVALIDATION = 1; diff --git a/lib/Twig/Cache/Null.php b/lib/Twig/Cache/Null.php index 59ab7a948..d06dcfb6c 100644 --- a/lib/Twig/Cache/Null.php +++ b/lib/Twig/Cache/Null.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Cache\CacheInterface; + /** * Implements a no-cache strategy. * @@ -16,7 +18,7 @@ * * @author Fabien Potencier */ -class Twig_Cache_Null implements \Twig\Cache\CacheInterface +class Twig_Cache_Null implements CacheInterface { public function generateKey($name, $className) { diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index aff2f1cfd..8c21bd285 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -10,6 +10,9 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Node\ModuleNode; + /** * Compiles a node to PHP code. * @@ -27,7 +30,7 @@ class Twig_Compiler implements Twig_CompilerInterface protected $filename; private $varNameSalt = 0; - public function __construct(\Twig\Environment $env) + public function __construct(Environment $env) { $this->env = $env; } @@ -45,7 +48,7 @@ class Twig_Compiler implements Twig_CompilerInterface /** * Returns the environment instance related to this compiler. * - * @return \Twig\Environment + * @return Environment */ public function getEnvironment() { @@ -80,7 +83,7 @@ class Twig_Compiler implements Twig_CompilerInterface $this->indentation = $indentation; $this->varNameSalt = 0; - if ($node instanceof \Twig\Node\ModuleNode) { + if ($node instanceof ModuleNode) { // to be removed in 2.0 $this->filename = $node->getTemplateName(); } diff --git a/lib/Twig/ContainerRuntimeLoader.php b/lib/Twig/ContainerRuntimeLoader.php index fe58e74c2..9f9bf351d 100644 --- a/lib/Twig/ContainerRuntimeLoader.php +++ b/lib/Twig/ContainerRuntimeLoader.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\RuntimeLoader\RuntimeLoaderInterface; + use Psr\Container\ContainerInterface; /** @@ -19,7 +21,7 @@ use Psr\Container\ContainerInterface; * @author Fabien Potencier * @author Robin Chalas */ -class Twig_ContainerRuntimeLoader implements \Twig\RuntimeLoader\RuntimeLoaderInterface +class Twig_ContainerRuntimeLoader implements RuntimeLoaderInterface { private $container; diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index d2fa42125..8c626f541 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -9,6 +9,39 @@ * file that was distributed with this source code. */ +use Twig\Extension\CoreExtension; +use Twig\Extension\EscaperExtension; +use Twig\Extension\OptimizerExtension; +use Twig\Extension\StagingExtension; +use Twig\Cache\CacheInterface; +use Twig\Cache\FilesystemCache; +use Twig\Cache\NullCache; +use Twig\Error\LoaderError; +use Twig\Error\SyntaxError; +use Twig\Error\RuntimeError; +use Twig\TemplateWrapper; +use Twig\Template; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Source; +use Twig\Loader\ChainLoader; +use Twig\Loader\ArrayLoader; +use Twig\Lexer; +use Twig\TokenStream; +use Twig\Parser; +use Twig\Node\ModuleNode; +use Twig\Compiler; +use Twig\Loader\LoaderInterface; +use Twig\Extension\InitRuntimeInterface; +use Twig\Extension\ExtensionInterface; +use Twig\TokenParser\TokenParserInterface; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\TwigFilter; +use Twig\TwigTest; +use Twig\TwigFunction; +use Twig\Extension\GlobalsInterface; +use Twig\RuntimeLoader\RuntimeLoaderInterface; +use Twig\Error\Error; + /** * Stores the Twig configuration. * @@ -95,7 +128,7 @@ class Twig_Environment * (default to -1 which means that all optimizations are enabled; * set it to 0 to disable). */ - public function __construct(\Twig\Loader\LoaderInterface $loader = null, $options = []) + public function __construct(LoaderInterface $loader = null, $options = []) { if (null !== $loader) { $this->setLoader($loader); @@ -121,10 +154,10 @@ class Twig_Environment $this->strictVariables = (bool) $options['strict_variables']; $this->setCache($options['cache']); - $this->addExtension(new \Twig\Extension\CoreExtension()); - $this->addExtension(new \Twig\Extension\EscaperExtension($options['autoescape'])); - $this->addExtension(new \Twig\Extension\OptimizerExtension($options['optimizations'])); - $this->staging = new \Twig\Extension\StagingExtension(); + $this->addExtension(new CoreExtension()); + $this->addExtension(new EscaperExtension($options['autoescape'])); + $this->addExtension(new OptimizerExtension($options['optimizations'])); + $this->staging = new StagingExtension(); // For BC if (\is_string($this->originalCache)) { @@ -252,7 +285,7 @@ class Twig_Environment * * @param bool $original Whether to return the original cache option or the real cache instance * - * @return \Twig\Cache\CacheInterface|string|false A Twig_CacheInterface implementation, + * @return CacheInterface|string|false A Twig_CacheInterface implementation, * an absolute path to the compiled templates, * or false to disable cache */ @@ -264,7 +297,7 @@ class Twig_Environment /** * Sets the current cache implementation. * - * @param \Twig\Cache\CacheInterface|string|false $cache A Twig_CacheInterface implementation, + * @param CacheInterface|string|false $cache A Twig_CacheInterface implementation, * an absolute path to the compiled templates, * or false to disable cache */ @@ -272,15 +305,15 @@ class Twig_Environment { if (\is_string($cache)) { $this->originalCache = $cache; - $this->cache = new \Twig\Cache\FilesystemCache($cache); + $this->cache = new FilesystemCache($cache); } elseif (false === $cache) { $this->originalCache = $cache; - $this->cache = new \Twig\Cache\NullCache(); + $this->cache = new NullCache(); } elseif (null === $cache) { @trigger_error('Using "null" as the cache strategy is deprecated since version 1.23 and will be removed in Twig 2.0.', E_USER_DEPRECATED); $this->originalCache = false; - $this->cache = new \Twig\Cache\NullCache(); - } elseif ($cache instanceof \Twig\Cache\CacheInterface) { + $this->cache = new NullCache(); + } elseif ($cache instanceof CacheInterface) { $this->originalCache = $this->cache = $cache; } else { throw new \LogicException(sprintf('Cache can only be a string, false, or a Twig_CacheInterface implementation.')); @@ -351,9 +384,9 @@ class Twig_Environment * * @return string The rendered template * - * @throws \Twig\Error\LoaderError When the template cannot be found - * @throws \Twig\Error\SyntaxError When an error occurred during compilation - * @throws \Twig\Error\RuntimeError When an error occurred during rendering + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering */ public function render($name, array $context = []) { @@ -366,9 +399,9 @@ class Twig_Environment * @param string $name The template name * @param array $context An array of parameters to pass to the template * - * @throws \Twig\Error\LoaderError When the template cannot be found - * @throws \Twig\Error\SyntaxError When an error occurred during compilation - * @throws \Twig\Error\RuntimeError When an error occurred during rendering + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation + * @throws RuntimeError When an error occurred during rendering */ public function display($name, array $context = []) { @@ -378,25 +411,25 @@ class Twig_Environment /** * Loads a template. * - * @param string|\Twig\TemplateWrapper|\Twig\Template $name The template name + * @param string|TemplateWrapper|\Twig\Template $name The template name * - * @throws \Twig\Error\LoaderError When the template cannot be found - * @throws \Twig\Error\RuntimeError When a previously generated cache is corrupted - * @throws \Twig\Error\SyntaxError When an error occurred during compilation + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation * - * @return \Twig\TemplateWrapper + * @return TemplateWrapper */ public function load($name) { - if ($name instanceof \Twig\TemplateWrapper) { + if ($name instanceof TemplateWrapper) { return $name; } - if ($name instanceof \Twig\Template) { - return new \Twig\TemplateWrapper($this, $name); + if ($name instanceof Template) { + return new TemplateWrapper($this, $name); } - return new \Twig\TemplateWrapper($this, $this->loadTemplate($name)); + return new TemplateWrapper($this, $this->loadTemplate($name)); } /** @@ -410,9 +443,9 @@ class Twig_Environment * * @return Twig_TemplateInterface A template instance representing the given template name * - * @throws \Twig\Error\LoaderError When the template cannot be found - * @throws \Twig\Error\RuntimeError When a previously generated cache is corrupted - * @throws \Twig\Error\SyntaxError When an error occurred during compilation + * @throws LoaderError When the template cannot be found + * @throws RuntimeError When a previously generated cache is corrupted + * @throws SyntaxError When an error occurred during compilation * * @internal */ @@ -440,8 +473,8 @@ class Twig_Environment if (!class_exists($cls, false)) { $loader = $this->getLoader(); - if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) { - $source = new \Twig\Source($loader->getSource($name), $name); + if (!$loader instanceof SourceContextLoaderInterface) { + $source = new Source($loader->getSource($name), $name); } else { $source = $loader->getSourceContext($name); } @@ -466,7 +499,7 @@ class Twig_Environment } if (!class_exists($cls, false)) { - throw new \Twig\Error\RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source); + throw new RuntimeError(sprintf('Failed to load Twig template "%s", index "%s": cache is corrupted.', $name, $index), -1, $source); } } @@ -475,7 +508,7 @@ class Twig_Environment } if (isset($this->loading[$cls])) { - throw new \Twig\Error\RuntimeError(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, [$name])))); + throw new RuntimeError(sprintf('Circular reference detected for Twig template "%s", path: %s.', $name, implode(' -> ', array_merge($this->loading, [$name])))); } $this->loading[$cls] = $name; @@ -499,17 +532,17 @@ class Twig_Environment * * @param string $template The template name * - * @return \Twig\Template A template instance representing the given template name + * @return Template A template instance representing the given template name * - * @throws \Twig\Error\LoaderError When the template cannot be found - * @throws \Twig\Error\SyntaxError When an error occurred during compilation + * @throws LoaderError When the template cannot be found + * @throws SyntaxError When an error occurred during compilation */ public function createTemplate($template) { $name = sprintf('__string_template__%s', hash('sha256', $template, false)); - $loader = new \Twig\Loader\ChainLoader([ - new \Twig\Loader\ArrayLoader([$name => $template]), + $loader = new ChainLoader([ + new ArrayLoader([$name => $template]), $current = $this->getLoader(), ]); @@ -562,12 +595,12 @@ class Twig_Environment * Similar to loadTemplate() but it also accepts instances of Twig_Template and * Twig_TemplateWrapper, and an array of templates where each is tried to be loaded. * - * @param string|\Twig\Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively + * @param string|Template|\Twig\TemplateWrapper|array $names A template or an array of templates to try consecutively * - * @return \Twig\Template|Twig_TemplateWrapper + * @return Template|Twig_TemplateWrapper * - * @throws \Twig\Error\LoaderError When none of the templates can be found - * @throws \Twig\Error\SyntaxError When an error occurred during compilation + * @throws LoaderError When none of the templates can be found + * @throws SyntaxError When an error occurred during compilation */ public function resolveTemplate($names) { @@ -576,17 +609,17 @@ class Twig_Environment } foreach ($names as $name) { - if ($name instanceof \Twig\Template) { + if ($name instanceof Template) { return $name; } - if ($name instanceof \Twig\TemplateWrapper) { + if ($name instanceof TemplateWrapper) { return $name; } try { return $this->loadTemplate($name); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { } } @@ -594,7 +627,7 @@ class Twig_Environment throw $e; } - throw new \Twig\Error\LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); + throw new LoaderError(sprintf('Unable to find one of the following templates: "%s".', implode('", "', $names))); } /** @@ -639,7 +672,7 @@ class Twig_Environment @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); if (null === $this->lexer) { - $this->lexer = new \Twig\Lexer($this); + $this->lexer = new Lexer($this); } return $this->lexer; @@ -653,22 +686,22 @@ class Twig_Environment /** * Tokenizes a source code. * - * @param string|\Twig\Source $source The template source code + * @param string|Source $source The template source code * @param string $name The template name (deprecated) * - * @return \Twig\TokenStream + * @return TokenStream * - * @throws \Twig\Error\SyntaxError When the code is syntactically wrong + * @throws SyntaxError When the code is syntactically wrong */ public function tokenize($source, $name = null) { - if (!$source instanceof \Twig\Source) { + if (!$source instanceof Source) { @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $source = new \Twig\Source($source, $name); + $source = new Source($source, $name); } if (null === $this->lexer) { - $this->lexer = new \Twig\Lexer($this); + $this->lexer = new Lexer($this); } return $this->lexer->tokenize($source); @@ -686,7 +719,7 @@ class Twig_Environment @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); if (null === $this->parser) { - $this->parser = new \Twig\Parser($this); + $this->parser = new Parser($this); } return $this->parser; @@ -700,14 +733,14 @@ class Twig_Environment /** * Converts a token stream to a node tree. * - * @return \Twig\Node\ModuleNode + * @return ModuleNode * - * @throws \Twig\Error\SyntaxError When the token stream is syntactically or semantically wrong + * @throws SyntaxError When the token stream is syntactically or semantically wrong */ - public function parse(\Twig\TokenStream $stream) + public function parse(TokenStream $stream) { if (null === $this->parser) { - $this->parser = new \Twig\Parser($this); + $this->parser = new Parser($this); } return $this->parser->parse($stream); @@ -725,7 +758,7 @@ class Twig_Environment @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); if (null === $this->compiler) { - $this->compiler = new \Twig\Compiler($this); + $this->compiler = new Compiler($this); } return $this->compiler; @@ -744,7 +777,7 @@ class Twig_Environment public function compile(Twig_NodeInterface $node) { if (null === $this->compiler) { - $this->compiler = new \Twig\Compiler($this); + $this->compiler = new Compiler($this); } return $this->compiler->compile($node)->getSource(); @@ -753,33 +786,33 @@ class Twig_Environment /** * Compiles a template source code. * - * @param string|\Twig\Source $source The template source code + * @param string|Source $source The template source code * @param string $name The template name (deprecated) * * @return string The compiled PHP source code * - * @throws \Twig\Error\SyntaxError When there was an error during tokenizing, parsing or compiling + * @throws SyntaxError When there was an error during tokenizing, parsing or compiling */ public function compileSource($source, $name = null) { - if (!$source instanceof \Twig\Source) { + if (!$source instanceof Source) { @trigger_error(sprintf('Passing a string as the $source argument of %s() is deprecated since version 1.27. Pass a Twig\Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $source = new \Twig\Source($source, $name); + $source = new Source($source, $name); } try { return $this->compile($this->parse($this->tokenize($source))); - } catch (\Twig\Error\Error $e) { + } catch (Error $e) { $e->setSourceContext($source); throw $e; } catch (\Exception $e) { - throw new \Twig\Error\SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); + throw new SyntaxError(sprintf('An exception has been thrown during the compilation of a template ("%s").', $e->getMessage()), -1, $source, $e); } } - public function setLoader(\Twig\Loader\LoaderInterface $loader) + public function setLoader(LoaderInterface $loader) { - if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { + if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { @trigger_error(sprintf('Twig loader "%s" should implement Twig_SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED); } @@ -789,7 +822,7 @@ class Twig_Environment /** * Gets the Loader instance. * - * @return \Twig\Loader\LoaderInterface + * @return LoaderInterface */ public function getLoader() { @@ -830,7 +863,7 @@ class Twig_Environment $this->runtimeInitialized = true; foreach ($this->getExtensions() as $name => $extension) { - if (!$extension instanceof \Twig\Extension\InitRuntimeInterface) { + if (!$extension instanceof InitRuntimeInterface) { $m = new \ReflectionMethod($extension, 'initRuntime'); if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { @@ -872,7 +905,7 @@ class Twig_Environment /** * Adds a runtime loader. */ - public function addRuntimeLoader(\Twig\RuntimeLoader\RuntimeLoaderInterface $loader) + public function addRuntimeLoader(RuntimeLoaderInterface $loader) { $this->runtimeLoaders[] = $loader; } @@ -882,7 +915,7 @@ class Twig_Environment * * @param string $class The extension class name * - * @return \Twig\Extension\ExtensionInterface + * @return ExtensionInterface */ public function getExtension($class) { @@ -902,7 +935,7 @@ class Twig_Environment } if (!isset($this->extensionsByClass[$class])) { - throw new \Twig\Error\RuntimeError(sprintf('The "%s" extension is not enabled.', $class)); + throw new RuntimeError(sprintf('The "%s" extension is not enabled.', $class)); } return $this->extensionsByClass[$class]; @@ -915,7 +948,7 @@ class Twig_Environment * * @return object The runtime implementation * - * @throws \Twig\Error\RuntimeError When the template cannot be found + * @throws RuntimeError When the template cannot be found */ public function getRuntime($class) { @@ -929,10 +962,10 @@ class Twig_Environment } } - throw new \Twig\Error\RuntimeError(sprintf('Unable to load the "%s" runtime.', $class)); + throw new RuntimeError(sprintf('Unable to load the "%s" runtime.', $class)); } - public function addExtension(\Twig\Extension\ExtensionInterface $extension) + public function addExtension(ExtensionInterface $extension) { if ($this->extensionInitialized) { throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); @@ -1003,14 +1036,14 @@ class Twig_Environment /** * Returns all registered extensions. * - * @return \Twig\Extension\ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) + * @return ExtensionInterface[] An array of extensions (keys are for internal usage only and should not be relied on) */ public function getExtensions() { return $this->extensions; } - public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser) + public function addTokenParser(TokenParserInterface $parser) { if ($this->extensionInitialized) { throw new \LogicException('Unable to add a token parser as extensions have already been initialized.'); @@ -1040,7 +1073,7 @@ class Twig_Environment * * Be warned that this method cannot return tags defined by Twig_TokenParserBrokerInterface classes. * - * @return \Twig\TokenParser\TokenParserInterface[] + * @return TokenParserInterface[] * * @internal */ @@ -1048,7 +1081,7 @@ class Twig_Environment { $tags = []; foreach ($this->getTokenParsers()->getParsers() as $parser) { - if ($parser instanceof \Twig\TokenParser\TokenParserInterface) { + if ($parser instanceof TokenParserInterface) { $tags[$parser->getTag()] = $parser; } } @@ -1056,7 +1089,7 @@ class Twig_Environment return $tags; } - public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) + public function addNodeVisitor(NodeVisitorInterface $visitor) { if ($this->extensionInitialized) { throw new \LogicException('Unable to add a node visitor as extensions have already been initialized.'); @@ -1068,7 +1101,7 @@ class Twig_Environment /** * Gets the registered Node Visitors. * - * @return \Twig\NodeVisitor\NodeVisitorInterface[] + * @return NodeVisitorInterface[] * * @internal */ @@ -1084,16 +1117,16 @@ class Twig_Environment /** * Registers a Filter. * - * @param string|\Twig\TwigFilter $name The filter name or a Twig_SimpleFilter instance - * @param Twig_FilterInterface|\Twig\TwigFilter $filter + * @param string|TwigFilter $name The filter name or a Twig_SimpleFilter instance + * @param Twig_FilterInterface|TwigFilter $filter */ public function addFilter($name, $filter = null) { - if (!$name instanceof \Twig\TwigFilter && !($filter instanceof \Twig\TwigFilter || $filter instanceof Twig_FilterInterface)) { + if (!$name instanceof TwigFilter && !($filter instanceof TwigFilter || $filter instanceof Twig_FilterInterface)) { throw new \LogicException('A filter must be an instance of Twig_FilterInterface or Twig_SimpleFilter.'); } - if ($name instanceof \Twig\TwigFilter) { + if ($name instanceof TwigFilter) { $filter = $name; $name = $filter->getName(); } else { @@ -1179,16 +1212,16 @@ class Twig_Environment /** * Registers a Test. * - * @param string|\Twig\TwigTest $name The test name or a Twig_SimpleTest instance - * @param Twig_TestInterface|\Twig\TwigTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance + * @param string|TwigTest $name The test name or a Twig_SimpleTest instance + * @param Twig_TestInterface|TwigTest $test A Twig_TestInterface instance or a Twig_SimpleTest instance */ public function addTest($name, $test = null) { - if (!$name instanceof \Twig\TwigTest && !($test instanceof \Twig\TwigTest || $test instanceof Twig_TestInterface)) { + if (!$name instanceof TwigTest && !($test instanceof TwigTest || $test instanceof Twig_TestInterface)) { throw new \LogicException('A test must be an instance of Twig_TestInterface or Twig_SimpleTest.'); } - if ($name instanceof \Twig\TwigTest) { + if ($name instanceof TwigTest) { $test = $name; $name = $test->getName(); } else { @@ -1256,16 +1289,16 @@ class Twig_Environment /** * Registers a Function. * - * @param string|\Twig\TwigFunction $name The function name or a Twig_SimpleFunction instance - * @param Twig_FunctionInterface|\Twig\TwigFunction $function + * @param string|TwigFunction $name The function name or a Twig_SimpleFunction instance + * @param Twig_FunctionInterface|TwigFunction $function */ public function addFunction($name, $function = null) { - if (!$name instanceof \Twig\TwigFunction && !($function instanceof \Twig\TwigFunction || $function instanceof Twig_FunctionInterface)) { + if (!$name instanceof TwigFunction && !($function instanceof TwigFunction || $function instanceof Twig_FunctionInterface)) { throw new \LogicException('A function must be an instance of Twig_FunctionInterface or Twig_SimpleFunction.'); } - if ($name instanceof \Twig\TwigFunction) { + if ($name instanceof TwigFunction) { $function = $name; $name = $function->getName(); } else { @@ -1458,7 +1491,7 @@ class Twig_Environment { @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); - return \Twig\Error\SyntaxError::computeAlternatives($name, $items); + return SyntaxError::computeAlternatives($name, $items); } /** @@ -1468,7 +1501,7 @@ class Twig_Environment { $globals = []; foreach ($this->extensions as $name => $extension) { - if (!$extension instanceof \Twig\Extension\GlobalsInterface) { + if (!$extension instanceof GlobalsInterface) { $m = new \ReflectionMethod($extension, 'getGlobals'); if ('Twig_Extension' !== $m->getDeclaringClass()->getName()) { @@ -1517,11 +1550,11 @@ class Twig_Environment /** * @internal */ - protected function initExtension(\Twig\Extension\ExtensionInterface $extension) + protected function initExtension(ExtensionInterface $extension) { // filters foreach ($extension->getFilters() as $name => $filter) { - if ($filter instanceof \Twig\TwigFilter) { + if ($filter instanceof TwigFilter) { $name = $filter->getName(); } else { @trigger_error(sprintf('Using an instance of "%s" for filter "%s" is deprecated since version 1.21. Use Twig_SimpleFilter instead.', \get_class($filter), $name), E_USER_DEPRECATED); @@ -1532,7 +1565,7 @@ class Twig_Environment // functions foreach ($extension->getFunctions() as $name => $function) { - if ($function instanceof \Twig\TwigFunction) { + if ($function instanceof TwigFunction) { $name = $function->getName(); } else { @trigger_error(sprintf('Using an instance of "%s" for function "%s" is deprecated since version 1.21. Use Twig_SimpleFunction instead.', \get_class($function), $name), E_USER_DEPRECATED); @@ -1543,7 +1576,7 @@ class Twig_Environment // tests foreach ($extension->getTests() as $name => $test) { - if ($test instanceof \Twig\TwigTest) { + if ($test instanceof TwigTest) { $name = $test->getName(); } else { @trigger_error(sprintf('Using an instance of "%s" for test "%s" is deprecated since version 1.21. Use Twig_SimpleTest instead.', \get_class($test), $name), E_USER_DEPRECATED); @@ -1554,7 +1587,7 @@ class Twig_Environment // token parsers foreach ($extension->getTokenParsers() as $parser) { - if ($parser instanceof \Twig\TokenParser\TokenParserInterface) { + if ($parser instanceof TokenParserInterface) { $this->parsers->addTokenParser($parser); } elseif ($parser instanceof Twig_TokenParserBrokerInterface) { @trigger_error('Registering a Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', E_USER_DEPRECATED); diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 81b95e913..4aa0a3e3e 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Source; +use Twig\Template; + /** * Twig base exception. * @@ -55,14 +58,14 @@ class Twig_Error extends \Exception * * @param string $message The error message * @param int $lineno The template line where the error occurred - * @param \Twig\Source|string|null $source The source context where the error occurred + * @param Source|string|null $source The source context where the error occurred * @param \Exception $previous The previous exception */ public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null) { if (null === $source) { $name = null; - } elseif (!$source instanceof \Twig\Source) { + } elseif (!$source instanceof Source) { // for compat with the Twig C ext., passing the template name as string is accepted $name = $source; } else { @@ -180,17 +183,17 @@ class Twig_Error extends \Exception /** * Gets the source context of the Twig template where the error occurred. * - * @return \Twig\Source|null + * @return Source|null */ public function getSourceContext() { - return $this->filename ? new \Twig\Source($this->sourceCode, $this->filename, $this->sourcePath) : null; + return $this->filename ? new Source($this->sourceCode, $this->filename, $this->sourcePath) : null; } /** * Sets the source context of the Twig template where the error occurred. */ - public function setSourceContext(\Twig\Source $source = null) + public function setSourceContext(Source $source = null) { if (null === $source) { $this->sourceCode = $this->filename = $this->sourcePath = null; @@ -273,7 +276,7 @@ class Twig_Error extends \Exception $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); foreach ($backtrace as $trace) { - if (isset($trace['object']) && $trace['object'] instanceof \Twig\Template && 'Twig_Template' !== \get_class($trace['object'])) { + if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) { $currentClass = \get_class($trace['object']); $isEmbedContainer = 0 === strpos($templateClass, $currentClass); if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) { diff --git a/lib/Twig/Error/Loader.php b/lib/Twig/Error/Loader.php index e8db0c4e1..ac95e6ca2 100644 --- a/lib/Twig/Error/Loader.php +++ b/lib/Twig/Error/Loader.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Error\Error; + /** * Exception thrown when an error occurs during template loading. * @@ -22,7 +24,7 @@ * * @author Fabien Potencier */ -class Twig_Error_Loader extends \Twig\Error\Error +class Twig_Error_Loader extends Error { public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null) { diff --git a/lib/Twig/Error/Runtime.php b/lib/Twig/Error/Runtime.php index 841086de3..72ac5a6e6 100644 --- a/lib/Twig/Error/Runtime.php +++ b/lib/Twig/Error/Runtime.php @@ -10,12 +10,14 @@ * file that was distributed with this source code. */ +use Twig\Error\Error; + /** * Exception thrown when an error occurs at runtime. * * @author Fabien Potencier */ -class Twig_Error_Runtime extends \Twig\Error\Error +class Twig_Error_Runtime extends Error { } diff --git a/lib/Twig/Error/Syntax.php b/lib/Twig/Error/Syntax.php index 682eacbeb..50fde8ceb 100644 --- a/lib/Twig/Error/Syntax.php +++ b/lib/Twig/Error/Syntax.php @@ -10,12 +10,14 @@ * file that was distributed with this source code. */ +use Twig\Error\Error; + /** * \Exception thrown when a syntax error occurs during lexing or parsing of a template. * * @author Fabien Potencier */ -class Twig_Error_Syntax extends \Twig\Error\Error +class Twig_Error_Syntax extends Error { /** * Tweaks the error message to include suggestions. diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 2e43b7c17..5bc2f5a9d 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -10,6 +10,30 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Error\SyntaxError; +use Twig\Node\Expression\Binary\ConcatBinary; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ParentExpression; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\MethodCallExpression; +use Twig\Node\Node; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Expression\Unary\NotUnary; +use Twig\TwigTest; +use Twig\TwigFunction; +use Twig\TwigFilter; +use Twig\Node\Expression\Unary\NegUnary; +use Twig\Node\Expression\Unary\PosUnary; +use Twig\Token; +use Twig\Lexer; +use Twig\Template; +use Twig\Parser; + /** * Parses expressions. * @@ -33,11 +57,11 @@ class Twig_ExpressionParser private $env; - public function __construct(\Twig\Parser $parser, $env = null) + public function __construct(Parser $parser, $env = null) { $this->parser = $parser; - if ($env instanceof \Twig\Environment) { + if ($env instanceof Environment) { $this->env = $env; $this->unaryOperators = $env->getUnaryOperators(); $this->binaryOperators = $env->getBinaryOperators(); @@ -91,10 +115,10 @@ class Twig_ExpressionParser $class = $operator['class']; return $this->parsePostfixExpression(new $class($expr, $token->getLine())); - } elseif ($token->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { + } elseif ($token->test(Token::PUNCTUATION_TYPE, '(')) { $this->parser->getStream()->next(); $expr = $this->parseExpression(); - $this->parser->getStream()->expect(\Twig\Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed'); + $this->parser->getStream()->expect(Token::PUNCTUATION_TYPE, ')', 'An opened parenthesis is not properly closed'); return $this->parsePostfixExpression($expr); } @@ -104,83 +128,83 @@ class Twig_ExpressionParser protected function parseConditionalExpression($expr) { - while ($this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, '?')) { - if (!$this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, ':')) { + while ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, '?')) { + if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) { $expr2 = $this->parseExpression(); - if ($this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, ':')) { + if ($this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ':')) { $expr3 = $this->parseExpression(); } else { - $expr3 = new \Twig\Node\Expression\ConstantExpression('', $this->parser->getCurrentToken()->getLine()); + $expr3 = new ConstantExpression('', $this->parser->getCurrentToken()->getLine()); } } else { $expr2 = $expr; $expr3 = $this->parseExpression(); } - $expr = new \Twig\Node\Expression\ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); + $expr = new ConditionalExpression($expr, $expr2, $expr3, $this->parser->getCurrentToken()->getLine()); } return $expr; } - protected function isUnary(\Twig\Token $token) + protected function isUnary(Token $token) { - return $token->test(\Twig\Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); + return $token->test(Token::OPERATOR_TYPE) && isset($this->unaryOperators[$token->getValue()]); } - protected function isBinary(\Twig\Token $token) + protected function isBinary(Token $token) { - return $token->test(\Twig\Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); + return $token->test(Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->getValue()]); } public function parsePrimaryExpression() { $token = $this->parser->getCurrentToken(); switch ($token->getType()) { - case \Twig\Token::NAME_TYPE: + case Token::NAME_TYPE: $this->parser->getStream()->next(); switch ($token->getValue()) { case 'true': case 'TRUE': - $node = new \Twig\Node\Expression\ConstantExpression(true, $token->getLine()); + $node = new ConstantExpression(true, $token->getLine()); break; case 'false': case 'FALSE': - $node = new \Twig\Node\Expression\ConstantExpression(false, $token->getLine()); + $node = new ConstantExpression(false, $token->getLine()); break; case 'none': case 'NONE': case 'null': case 'NULL': - $node = new \Twig\Node\Expression\ConstantExpression(null, $token->getLine()); + $node = new ConstantExpression(null, $token->getLine()); break; default: if ('(' === $this->parser->getCurrentToken()->getValue()) { $node = $this->getFunctionNode($token->getValue(), $token->getLine()); } else { - $node = new \Twig\Node\Expression\NameExpression($token->getValue(), $token->getLine()); + $node = new NameExpression($token->getValue(), $token->getLine()); } } break; - case \Twig\Token::NUMBER_TYPE: + case Token::NUMBER_TYPE: $this->parser->getStream()->next(); - $node = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); + $node = new ConstantExpression($token->getValue(), $token->getLine()); break; - case \Twig\Token::STRING_TYPE: - case \Twig\Token::INTERPOLATION_START_TYPE: + case Token::STRING_TYPE: + case Token::INTERPOLATION_START_TYPE: $node = $this->parseStringExpression(); break; - case \Twig\Token::OPERATOR_TYPE: - if (preg_match(\Twig\Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { + case Token::OPERATOR_TYPE: + if (preg_match(Lexer::REGEX_NAME, $token->getValue(), $matches) && $matches[0] == $token->getValue()) { // in this context, string operators are variable names $this->parser->getStream()->next(); - $node = new \Twig\Node\Expression\NameExpression($token->getValue(), $token->getLine()); + $node = new NameExpression($token->getValue(), $token->getLine()); break; } elseif (isset($this->unaryOperators[$token->getValue()])) { $class = $this->unaryOperators[$token->getValue()]['class']; @@ -189,7 +213,7 @@ class Twig_ExpressionParser $negClass = 'Twig_Node_Expression_Unary_Neg'; $posClass = 'Twig_Node_Expression_Unary_Pos'; if (!(\in_array($ref->getName(), [$negClass, $posClass]) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { - throw new \Twig\Error\SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + throw new SyntaxError(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } $this->parser->getStream()->next(); @@ -201,14 +225,14 @@ class Twig_ExpressionParser // no break default: - if ($token->test(\Twig\Token::PUNCTUATION_TYPE, '[')) { + if ($token->test(Token::PUNCTUATION_TYPE, '[')) { $node = $this->parseArrayExpression(); - } elseif ($token->test(\Twig\Token::PUNCTUATION_TYPE, '{')) { + } elseif ($token->test(Token::PUNCTUATION_TYPE, '{')) { $node = $this->parseHashExpression(); - } elseif ($token->test(\Twig\Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { - throw new \Twig\Error\SyntaxError(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + } elseif ($token->test(Token::OPERATOR_TYPE, '=') && ('==' === $this->parser->getStream()->look(-1)->getValue() || '!=' === $this->parser->getStream()->look(-1)->getValue())) { + throw new SyntaxError(sprintf('Unexpected operator of value "%s". Did you try to use "===" or "!==" for strict comparison? Use "is same as(value)" instead.', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } else { - throw new \Twig\Error\SyntaxError(sprintf('Unexpected token "%s" of value "%s".', \Twig\Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); + throw new SyntaxError(sprintf('Unexpected token "%s" of value "%s".', Token::typeToEnglish($token->getType()), $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } } @@ -223,12 +247,12 @@ class Twig_ExpressionParser // a string cannot be followed by another string in a single expression $nextCanBeString = true; while (true) { - if ($nextCanBeString && $token = $stream->nextIf(\Twig\Token::STRING_TYPE)) { - $nodes[] = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); + if ($nextCanBeString && $token = $stream->nextIf(Token::STRING_TYPE)) { + $nodes[] = new ConstantExpression($token->getValue(), $token->getLine()); $nextCanBeString = false; - } elseif ($stream->nextIf(\Twig\Token::INTERPOLATION_START_TYPE)) { + } elseif ($stream->nextIf(Token::INTERPOLATION_START_TYPE)) { $nodes[] = $this->parseExpression(); - $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); + $stream->expect(Token::INTERPOLATION_END_TYPE); $nextCanBeString = true; } else { break; @@ -237,7 +261,7 @@ class Twig_ExpressionParser $expr = array_shift($nodes); foreach ($nodes as $node) { - $expr = new \Twig\Node\Expression\Binary\ConcatBinary($expr, $node, $node->getTemplateLine()); + $expr = new ConcatBinary($expr, $node, $node->getTemplateLine()); } return $expr; @@ -246,16 +270,16 @@ class Twig_ExpressionParser public function parseArrayExpression() { $stream = $this->parser->getStream(); - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '[', 'An array element was expected'); + $stream->expect(Token::PUNCTUATION_TYPE, '[', 'An array element was expected'); - $node = new \Twig\Node\Expression\ArrayExpression([], $stream->getCurrent()->getLine()); + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); $first = true; - while (!$stream->test(\Twig\Token::PUNCTUATION_TYPE, ']')) { + while (!$stream->test(Token::PUNCTUATION_TYPE, ']')) { if (!$first) { - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma'); + $stream->expect(Token::PUNCTUATION_TYPE, ',', 'An array element must be followed by a comma'); // trailing ,? - if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, ']')) { + if ($stream->test(Token::PUNCTUATION_TYPE, ']')) { break; } } @@ -263,7 +287,7 @@ class Twig_ExpressionParser $node->addElement($this->parseExpression()); } - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed'); + $stream->expect(Token::PUNCTUATION_TYPE, ']', 'An opened array is not properly closed'); return $node; } @@ -271,16 +295,16 @@ class Twig_ExpressionParser public function parseHashExpression() { $stream = $this->parser->getStream(); - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '{', 'A hash element was expected'); + $stream->expect(Token::PUNCTUATION_TYPE, '{', 'A hash element was expected'); - $node = new \Twig\Node\Expression\ArrayExpression([], $stream->getCurrent()->getLine()); + $node = new ArrayExpression([], $stream->getCurrent()->getLine()); $first = true; - while (!$stream->test(\Twig\Token::PUNCTUATION_TYPE, '}')) { + while (!$stream->test(Token::PUNCTUATION_TYPE, '}')) { if (!$first) { - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma'); + $stream->expect(Token::PUNCTUATION_TYPE, ',', 'A hash value must be followed by a comma'); // trailing ,? - if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '}')) { + if ($stream->test(Token::PUNCTUATION_TYPE, '}')) { break; } } @@ -292,22 +316,22 @@ class Twig_ExpressionParser // * a string -- 'a' // * a name, which is equivalent to a string -- a // * an expression, which must be enclosed in parentheses -- (1 + 2) - if (($token = $stream->nextIf(\Twig\Token::STRING_TYPE)) || ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) || $token = $stream->nextIf(\Twig\Token::NUMBER_TYPE)) { - $key = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); - } elseif ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { + if (($token = $stream->nextIf(Token::STRING_TYPE)) || ($token = $stream->nextIf(Token::NAME_TYPE)) || $token = $stream->nextIf(Token::NUMBER_TYPE)) { + $key = new ConstantExpression($token->getValue(), $token->getLine()); + } elseif ($stream->test(Token::PUNCTUATION_TYPE, '(')) { $key = $this->parseExpression(); } else { $current = $stream->getCurrent(); - throw new \Twig\Error\SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', \Twig\Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('A hash key must be a quoted string, a number, a name, or an expression enclosed in parentheses (unexpected token "%s" of value "%s".', Token::typeToEnglish($current->getType()), $current->getValue()), $current->getLine(), $stream->getSourceContext()); } - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); + $stream->expect(Token::PUNCTUATION_TYPE, ':', 'A hash key must be followed by a colon (:)'); $value = $this->parseExpression(); $node->addElement($value, $key); } - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed'); + $stream->expect(Token::PUNCTUATION_TYPE, '}', 'An opened hash is not properly closed'); return $node; } @@ -316,7 +340,7 @@ class Twig_ExpressionParser { while (true) { $token = $this->parser->getCurrentToken(); - if (\Twig\Token::PUNCTUATION_TYPE == $token->getType()) { + if (Token::PUNCTUATION_TYPE == $token->getType()) { if ('.' == $token->getValue() || '[' == $token->getValue()) { $node = $this->parseSubscriptExpression($node); } elseif ('|' == $token->getValue()) { @@ -338,36 +362,36 @@ class Twig_ExpressionParser case 'parent': $this->parseArguments(); if (!\count($this->parser->getBlockStack())) { - throw new \Twig\Error\SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + throw new SyntaxError('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); } if (!$this->parser->getParent() && !$this->parser->hasTraits()) { - throw new \Twig\Error\SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); + throw new SyntaxError('Calling "parent" on a template that does not extend nor "use" another template is forbidden.', $line, $this->parser->getStream()->getSourceContext()); } - return new \Twig\Node\Expression\ParentExpression($this->parser->peekBlockStack(), $line); + return new ParentExpression($this->parser->peekBlockStack(), $line); case 'block': $args = $this->parseArguments(); if (\count($args) < 1) { - throw new \Twig\Error\SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); + throw new SyntaxError('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); } - return new \Twig\Node\Expression\BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); + return new BlockReferenceExpression($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); case 'attribute': $args = $this->parseArguments(); if (\count($args) < 2) { - throw new \Twig\Error\SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); + throw new SyntaxError('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); } - return new \Twig\Node\Expression\GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, \Twig\Template::ANY_CALL, $line); + return new GetAttrExpression($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Template::ANY_CALL, $line); default: if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { - $arguments = new \Twig\Node\Expression\ArrayExpression([], $line); + $arguments = new ArrayExpression([], $line); foreach ($this->parseArguments() as $n) { $arguments->addElement($n); } - $node = new \Twig\Node\Expression\MethodCallExpression($alias['node'], $alias['name'], $arguments, $line); + $node = new MethodCallExpression($alias['node'], $alias['name'], $arguments, $line); $node->setAttribute('safe', true); return $node; @@ -385,81 +409,81 @@ class Twig_ExpressionParser $stream = $this->parser->getStream(); $token = $stream->next(); $lineno = $token->getLine(); - $arguments = new \Twig\Node\Expression\ArrayExpression([], $lineno); - $type = \Twig\Template::ANY_CALL; + $arguments = new ArrayExpression([], $lineno); + $type = Template::ANY_CALL; if ('.' == $token->getValue()) { $token = $stream->next(); if ( - \Twig\Token::NAME_TYPE == $token->getType() + Token::NAME_TYPE == $token->getType() || - \Twig\Token::NUMBER_TYPE == $token->getType() + Token::NUMBER_TYPE == $token->getType() || - (\Twig\Token::OPERATOR_TYPE == $token->getType() && preg_match(\Twig\Lexer::REGEX_NAME, $token->getValue())) + (Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue())) ) { - $arg = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $lineno); + $arg = new ConstantExpression($token->getValue(), $lineno); - if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { - $type = \Twig\Template::METHOD_CALL; + if ($stream->test(Token::PUNCTUATION_TYPE, '(')) { + $type = Template::METHOD_CALL; foreach ($this->parseArguments() as $n) { $arguments->addElement($n); } } } else { - throw new \Twig\Error\SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext()); + throw new SyntaxError('Expected name or number.', $lineno, $stream->getSourceContext()); } - if ($node instanceof \Twig\Node\Expression\NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { - if (!$arg instanceof \Twig\Node\Expression\ConstantExpression) { - throw new \Twig\Error\SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); + if ($node instanceof NameExpression && null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))) { + if (!$arg instanceof ConstantExpression) { + throw new SyntaxError(sprintf('Dynamic macro names are not supported (called on "%s").', $node->getAttribute('name')), $token->getLine(), $stream->getSourceContext()); } $name = $arg->getAttribute('value'); if ($this->parser->isReservedMacroName($name)) { - throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('"%s" cannot be called as macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); } - $node = new \Twig\Node\Expression\MethodCallExpression($node, 'get'.$name, $arguments, $lineno); + $node = new MethodCallExpression($node, 'get'.$name, $arguments, $lineno); $node->setAttribute('safe', true); return $node; } } else { - $type = \Twig\Template::ARRAY_CALL; + $type = Template::ARRAY_CALL; // slice? $slice = false; - if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, ':')) { + if ($stream->test(Token::PUNCTUATION_TYPE, ':')) { $slice = true; - $arg = new \Twig\Node\Expression\ConstantExpression(0, $token->getLine()); + $arg = new ConstantExpression(0, $token->getLine()); } else { $arg = $this->parseExpression(); } - if ($stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ':')) { + if ($stream->nextIf(Token::PUNCTUATION_TYPE, ':')) { $slice = true; } if ($slice) { - if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, ']')) { - $length = new \Twig\Node\Expression\ConstantExpression(null, $token->getLine()); + if ($stream->test(Token::PUNCTUATION_TYPE, ']')) { + $length = new ConstantExpression(null, $token->getLine()); } else { $length = $this->parseExpression(); } $class = $this->getFilterNodeClass('slice', $token->getLine()); - $arguments = new \Twig\Node\Node([$arg, $length]); - $filter = new $class($node, new \Twig\Node\Expression\ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine()); + $arguments = new Node([$arg, $length]); + $filter = new $class($node, new ConstantExpression('slice', $token->getLine()), $arguments, $token->getLine()); - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ']'); + $stream->expect(Token::PUNCTUATION_TYPE, ']'); return $filter; } - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ']'); + $stream->expect(Token::PUNCTUATION_TYPE, ']'); } - return new \Twig\Node\Expression\GetAttrExpression($node, $arg, $arguments, $type, $lineno); + return new GetAttrExpression($node, $arg, $arguments, $type, $lineno); } public function parseFilterExpression($node) @@ -472,11 +496,11 @@ class Twig_ExpressionParser public function parseFilterExpressionRaw($node, $tag = null) { while (true) { - $token = $this->parser->getStream()->expect(\Twig\Token::NAME_TYPE); + $token = $this->parser->getStream()->expect(Token::NAME_TYPE); - $name = new \Twig\Node\Expression\ConstantExpression($token->getValue(), $token->getLine()); - if (!$this->parser->getStream()->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { - $arguments = new \Twig\Node\Node(); + $name = new ConstantExpression($token->getValue(), $token->getLine()); + if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '(')) { + $arguments = new Node(); } else { $arguments = $this->parseArguments(true); } @@ -485,7 +509,7 @@ class Twig_ExpressionParser $node = new $class($node, $name, $arguments, $token->getLine(), $tag); - if (!$this->parser->getStream()->test(\Twig\Token::PUNCTUATION_TYPE, '|')) { + if (!$this->parser->getStream()->test(Token::PUNCTUATION_TYPE, '|')) { break; } @@ -501,32 +525,32 @@ class Twig_ExpressionParser * @param bool $namedArguments Whether to allow named arguments or not * @param bool $definition Whether we are parsing arguments for a function definition * - * @return \Twig\Node\Node + * @return Node * - * @throws \Twig\Error\SyntaxError + * @throws SyntaxError */ public function parseArguments($namedArguments = false, $definition = false) { $args = []; $stream = $this->parser->getStream(); - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis'); - while (!$stream->test(\Twig\Token::PUNCTUATION_TYPE, ')')) { + $stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis'); + while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) { if (!empty($args)) { - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma'); + $stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma'); } if ($definition) { - $token = $stream->expect(\Twig\Token::NAME_TYPE, null, 'An argument must be a name'); - $value = new \Twig\Node\Expression\NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine()); + $token = $stream->expect(Token::NAME_TYPE, null, 'An argument must be a name'); + $value = new NameExpression($token->getValue(), $this->parser->getCurrentToken()->getLine()); } else { $value = $this->parseExpression(); } $name = null; - if ($namedArguments && $token = $stream->nextIf(\Twig\Token::OPERATOR_TYPE, '=')) { - if (!$value instanceof \Twig\Node\Expression\NameExpression) { - throw new \Twig\Error\SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); + if ($namedArguments && $token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) { + if (!$value instanceof NameExpression) { + throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); } $name = $value->getAttribute('name'); @@ -534,7 +558,7 @@ class Twig_ExpressionParser $value = $this->parsePrimaryExpression(); if (!$this->checkConstantExpression($value)) { - throw new \Twig\Error\SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('A default value for an argument must be a constant (a boolean, a string, a number, or an array).'), $token->getLine(), $stream->getSourceContext()); } } else { $value = $this->parseExpression(); @@ -544,7 +568,7 @@ class Twig_ExpressionParser if ($definition) { if (null === $name) { $name = $value->getAttribute('name'); - $value = new \Twig\Node\Expression\ConstantExpression(null, $this->parser->getCurrentToken()->getLine()); + $value = new ConstantExpression(null, $this->parser->getCurrentToken()->getLine()); } $args[$name] = $value; } else { @@ -555,9 +579,9 @@ class Twig_ExpressionParser } } } - $stream->expect(\Twig\Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis'); + $stream->expect(Token::PUNCTUATION_TYPE, ')', 'A list of arguments must be closed by a parenthesis'); - return new \Twig\Node\Node($args); + return new Node($args); } public function parseAssignmentExpression() @@ -565,19 +589,19 @@ class Twig_ExpressionParser $stream = $this->parser->getStream(); $targets = []; while (true) { - $token = $stream->expect(\Twig\Token::NAME_TYPE, null, 'Only variables can be assigned to'); + $token = $stream->expect(Token::NAME_TYPE, null, 'Only variables can be assigned to'); $value = $token->getValue(); if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) { - throw new \Twig\Error\SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); } - $targets[] = new \Twig\Node\Expression\AssignNameExpression($value, $token->getLine()); + $targets[] = new AssignNameExpression($value, $token->getLine()); - if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { break; } } - return new \Twig\Node\Node($targets); + return new Node($targets); } public function parseMultitargetExpression() @@ -585,17 +609,17 @@ class Twig_ExpressionParser $targets = []; while (true) { $targets[] = $this->parseExpression(); - if (!$this->parser->getStream()->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { + if (!$this->parser->getStream()->nextIf(Token::PUNCTUATION_TYPE, ',')) { break; } } - return new \Twig\Node\Node($targets); + return new Node($targets); } private function parseNotTestExpression(Twig_NodeInterface $node) { - return new \Twig\Node\Expression\Unary\NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); + return new NotUnary($this->parseTestExpression($node), $this->parser->getCurrentToken()->getLine()); } private function parseTestExpression(Twig_NodeInterface $node) @@ -605,7 +629,7 @@ class Twig_ExpressionParser $class = $this->getTestNodeClass($test); $arguments = null; - if ($stream->test(\Twig\Token::PUNCTUATION_TYPE, '(')) { + if ($stream->test(Token::PUNCTUATION_TYPE, '(')) { $arguments = $this->parser->getExpressionParser()->parseArguments(true); } @@ -615,13 +639,13 @@ class Twig_ExpressionParser private function getTest($line) { $stream = $this->parser->getStream(); - $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); if ($test = $this->env->getTest($name)) { return [$name, $test]; } - if ($stream->test(\Twig\Token::NAME_TYPE)) { + if ($stream->test(Token::NAME_TYPE)) { // try 2-words tests $name = $name.' '.$this->parser->getCurrentToken()->getValue(); @@ -632,7 +656,7 @@ class Twig_ExpressionParser } } - $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); + $e = new SyntaxError(sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext()); $e->addSuggestions($name, array_keys($this->env->getTests())); throw $e; @@ -640,7 +664,7 @@ class Twig_ExpressionParser private function getTestNodeClass($test) { - if ($test instanceof \Twig\TwigTest && $test->isDeprecated()) { + if ($test instanceof TwigTest && $test->isDeprecated()) { $stream = $this->parser->getStream(); $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); if (!\is_bool($test->getDeprecatedVersion())) { @@ -655,7 +679,7 @@ class Twig_ExpressionParser @trigger_error($message, E_USER_DEPRECATED); } - if ($test instanceof \Twig\TwigTest) { + if ($test instanceof TwigTest) { return $test->getNodeClass(); } @@ -665,13 +689,13 @@ class Twig_ExpressionParser protected function getFunctionNodeClass($name, $line) { if (false === $function = $this->env->getFunction($name)) { - $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e = new SyntaxError(sprintf('Unknown "%s" function.', $name), $line, $this->parser->getStream()->getSourceContext()); $e->addSuggestions($name, array_keys($this->env->getFunctions())); throw $e; } - if ($function instanceof \Twig\TwigFunction && $function->isDeprecated()) { + if ($function instanceof TwigFunction && $function->isDeprecated()) { $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); if (!\is_bool($function->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); @@ -685,7 +709,7 @@ class Twig_ExpressionParser @trigger_error($message, E_USER_DEPRECATED); } - if ($function instanceof \Twig\TwigFunction) { + if ($function instanceof TwigFunction) { return $function->getNodeClass(); } @@ -695,13 +719,13 @@ class Twig_ExpressionParser protected function getFilterNodeClass($name, $line) { if (false === $filter = $this->env->getFilter($name)) { - $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); + $e = new SyntaxError(sprintf('Unknown "%s" filter.', $name), $line, $this->parser->getStream()->getSourceContext()); $e->addSuggestions($name, array_keys($this->env->getFilters())); throw $e; } - if ($filter instanceof \Twig\TwigFilter && $filter->isDeprecated()) { + if ($filter instanceof TwigFilter && $filter->isDeprecated()) { $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); if (!\is_bool($filter->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); @@ -715,7 +739,7 @@ class Twig_ExpressionParser @trigger_error($message, E_USER_DEPRECATED); } - if ($filter instanceof \Twig\TwigFilter) { + if ($filter instanceof TwigFilter) { return $filter->getNodeClass(); } @@ -725,8 +749,8 @@ class Twig_ExpressionParser // checks that the node only contains "constant" elements protected function checkConstantExpression(Twig_NodeInterface $node) { - if (!($node instanceof \Twig\Node\Expression\ConstantExpression || $node instanceof \Twig\Node\Expression\ArrayExpression - || $node instanceof \Twig\Node\Expression\Unary\NegUnary || $node instanceof \Twig\Node\Expression\Unary\PosUnary + if (!($node instanceof ConstantExpression || $node instanceof ArrayExpression + || $node instanceof NegUnary || $node instanceof PosUnary )) { return false; } diff --git a/lib/Twig/Extension.php b/lib/Twig/Extension.php index 58cc53503..862062e6b 100644 --- a/lib/Twig/Extension.php +++ b/lib/Twig/Extension.php @@ -9,12 +9,15 @@ * file that was distributed with this source code. */ -abstract class Twig_Extension implements \Twig\Extension\ExtensionInterface +use Twig\Extension\ExtensionInterface; +use Twig\Environment; + +abstract class Twig_Extension implements ExtensionInterface { /** * @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead */ - public function initRuntime(\Twig\Environment $environment) + public function initRuntime(Environment $environment) { } diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index cea654618..e15515d3c 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -13,10 +13,39 @@ if (!\defined('ENT_SUBSTITUTE')) { * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\TokenParser\ForTokenParser; +use Twig\TokenParser\IfTokenParser; +use Twig\TokenParser\ExtendsTokenParser; +use Twig\TokenParser\IncludeTokenParser; +use Twig\TokenParser\BlockTokenParser; +use Twig\TokenParser\UseTokenParser; +use Twig\TokenParser\FilterTokenParser; +use Twig\TokenParser\MacroTokenParser; +use Twig\TokenParser\ImportTokenParser; +use Twig\TokenParser\FromTokenParser; +use Twig\TokenParser\SetTokenParser; +use Twig\TokenParser\SpacelessTokenParser; +use Twig\TokenParser\FlushTokenParser; +use Twig\TokenParser\DoTokenParser; +use Twig\TokenParser\EmbedTokenParser; +use Twig\TokenParser\WithTokenParser; +use Twig\TokenParser\DeprecatedTokenParser; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; +use Twig\Error\RuntimeError; +use Twig\Markup; +use Twig\Node\Expression\ConstantExpression; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\ExpressionParser; +use Twig\Environment; +use Twig\Error\LoaderError; + /** * @final */ -class Twig_Extension_Core extends \Twig\Extension\AbstractExtension +class Twig_Extension_Core extends AbstractExtension { protected $dateFormats = ['F j, Y H:i', '%d days']; protected $numberFormat = [0, '.', ',']; @@ -120,23 +149,23 @@ class Twig_Extension_Core extends \Twig\Extension\AbstractExtension public function getTokenParsers() { return [ - new \Twig\TokenParser\ForTokenParser(), - new \Twig\TokenParser\IfTokenParser(), - new \Twig\TokenParser\ExtendsTokenParser(), - new \Twig\TokenParser\IncludeTokenParser(), - new \Twig\TokenParser\BlockTokenParser(), - new \Twig\TokenParser\UseTokenParser(), - new \Twig\TokenParser\FilterTokenParser(), - new \Twig\TokenParser\MacroTokenParser(), - new \Twig\TokenParser\ImportTokenParser(), - new \Twig\TokenParser\FromTokenParser(), - new \Twig\TokenParser\SetTokenParser(), - new \Twig\TokenParser\SpacelessTokenParser(), - new \Twig\TokenParser\FlushTokenParser(), - new \Twig\TokenParser\DoTokenParser(), - new \Twig\TokenParser\EmbedTokenParser(), - new \Twig\TokenParser\WithTokenParser(), - new \Twig\TokenParser\DeprecatedTokenParser(), + new ForTokenParser(), + new IfTokenParser(), + new ExtendsTokenParser(), + new IncludeTokenParser(), + new BlockTokenParser(), + new UseTokenParser(), + new FilterTokenParser(), + new MacroTokenParser(), + new ImportTokenParser(), + new FromTokenParser(), + new SetTokenParser(), + new SpacelessTokenParser(), + new FlushTokenParser(), + new DoTokenParser(), + new EmbedTokenParser(), + new WithTokenParser(), + new DeprecatedTokenParser(), ]; } @@ -144,54 +173,54 @@ class Twig_Extension_Core extends \Twig\Extension\AbstractExtension { $filters = [ // formatting filters - new \Twig\TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('format', 'sprintf'), - new \Twig\TwigFilter('replace', 'twig_replace_filter'), - new \Twig\TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('abs', 'abs'), - new \Twig\TwigFilter('round', 'twig_round'), + new TwigFilter('date', 'twig_date_format_filter', ['needs_environment' => true]), + new TwigFilter('date_modify', 'twig_date_modify_filter', ['needs_environment' => true]), + new TwigFilter('format', 'sprintf'), + new TwigFilter('replace', 'twig_replace_filter'), + new TwigFilter('number_format', 'twig_number_format_filter', ['needs_environment' => true]), + new TwigFilter('abs', 'abs'), + new TwigFilter('round', 'twig_round'), // encoding - new \Twig\TwigFilter('url_encode', 'twig_urlencode_filter'), - new \Twig\TwigFilter('json_encode', 'twig_jsonencode_filter'), - new \Twig\TwigFilter('convert_encoding', 'twig_convert_encoding'), + new TwigFilter('url_encode', 'twig_urlencode_filter'), + new TwigFilter('json_encode', 'twig_jsonencode_filter'), + new TwigFilter('convert_encoding', 'twig_convert_encoding'), // string filters - new \Twig\TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('upper', 'strtoupper'), - new \Twig\TwigFilter('lower', 'strtolower'), - new \Twig\TwigFilter('striptags', 'strip_tags'), - new \Twig\TwigFilter('trim', 'twig_trim_filter'), - new \Twig\TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), + new TwigFilter('title', 'twig_title_string_filter', ['needs_environment' => true]), + new TwigFilter('capitalize', 'twig_capitalize_string_filter', ['needs_environment' => true]), + new TwigFilter('upper', 'strtoupper'), + new TwigFilter('lower', 'strtolower'), + new TwigFilter('striptags', 'strip_tags'), + new TwigFilter('trim', 'twig_trim_filter'), + new TwigFilter('nl2br', 'nl2br', ['pre_escape' => 'html', 'is_safe' => ['html']]), // array helpers - new \Twig\TwigFilter('join', 'twig_join_filter'), - new \Twig\TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('sort', 'twig_sort_filter'), - new \Twig\TwigFilter('merge', 'twig_array_merge'), - new \Twig\TwigFilter('batch', 'twig_array_batch'), + new TwigFilter('join', 'twig_join_filter'), + new TwigFilter('split', 'twig_split_filter', ['needs_environment' => true]), + new TwigFilter('sort', 'twig_sort_filter'), + new TwigFilter('merge', 'twig_array_merge'), + new TwigFilter('batch', 'twig_array_batch'), // string/array filters - new \Twig\TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]), - new \Twig\TwigFilter('slice', 'twig_slice', ['needs_environment' => true]), - new \Twig\TwigFilter('first', 'twig_first', ['needs_environment' => true]), - new \Twig\TwigFilter('last', 'twig_last', ['needs_environment' => true]), + new TwigFilter('reverse', 'twig_reverse_filter', ['needs_environment' => true]), + new TwigFilter('length', 'twig_length_filter', ['needs_environment' => true]), + new TwigFilter('slice', 'twig_slice', ['needs_environment' => true]), + new TwigFilter('first', 'twig_first', ['needs_environment' => true]), + new TwigFilter('last', 'twig_last', ['needs_environment' => true]), // iteration and runtime - new \Twig\TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']), - new \Twig\TwigFilter('keys', 'twig_get_array_keys_filter'), + new TwigFilter('default', '_twig_default_filter', ['node_class' => '\Twig\Node\Expression\Filter\DefaultFilter']), + new TwigFilter('keys', 'twig_get_array_keys_filter'), // escaping - new \Twig\TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), - new \Twig\TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('escape', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), + new TwigFilter('e', 'twig_escape_filter', ['needs_environment' => true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), ]; if (\function_exists('mb_get_info')) { - $filters[] = new \Twig\TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); - $filters[] = new \Twig\TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); + $filters[] = new TwigFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); + $filters[] = new TwigFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); } return $filters; @@ -200,33 +229,33 @@ class Twig_Extension_Core extends \Twig\Extension\AbstractExtension public function getFunctions() { return [ - new \Twig\TwigFunction('max', 'max'), - new \Twig\TwigFunction('min', 'min'), - new \Twig\TwigFunction('range', 'range'), - new \Twig\TwigFunction('constant', 'twig_constant'), - new \Twig\TwigFunction('cycle', 'twig_cycle'), - new \Twig\TwigFunction('random', 'twig_random', ['needs_environment' => true]), - new \Twig\TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]), - new \Twig\TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), - new \Twig\TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), + new TwigFunction('max', 'max'), + new TwigFunction('min', 'min'), + new TwigFunction('range', 'range'), + new TwigFunction('constant', 'twig_constant'), + new TwigFunction('cycle', 'twig_cycle'), + new TwigFunction('random', 'twig_random', ['needs_environment' => true]), + new TwigFunction('date', 'twig_date_converter', ['needs_environment' => true]), + new TwigFunction('include', 'twig_include', ['needs_environment' => true, 'needs_context' => true, 'is_safe' => ['all']]), + new TwigFunction('source', 'twig_source', ['needs_environment' => true, 'is_safe' => ['all']]), ]; } public function getTests() { return [ - new \Twig\TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']), - new \Twig\TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']), - new \Twig\TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']), - new \Twig\TwigTest('sameas', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest', 'deprecated' => '1.21', 'alternative' => 'same as']), - new \Twig\TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']), - new \Twig\TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), - new \Twig\TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), - new \Twig\TwigTest('divisibleby', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest', 'deprecated' => '1.21', 'alternative' => 'divisible by']), - new \Twig\TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']), - new \Twig\TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']), - new \Twig\TwigTest('empty', 'twig_test_empty'), - new \Twig\TwigTest('iterable', 'twig_test_iterable'), + new TwigTest('even', null, ['node_class' => '\Twig\Node\Expression\Test\EvenTest']), + new TwigTest('odd', null, ['node_class' => '\Twig\Node\Expression\Test\OddTest']), + new TwigTest('defined', null, ['node_class' => '\Twig\Node\Expression\Test\DefinedTest']), + new TwigTest('sameas', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest', 'deprecated' => '1.21', 'alternative' => 'same as']), + new TwigTest('same as', null, ['node_class' => '\Twig\Node\Expression\Test\SameasTest']), + new TwigTest('none', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), + new TwigTest('null', null, ['node_class' => '\Twig\Node\Expression\Test\NullTest']), + new TwigTest('divisibleby', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest', 'deprecated' => '1.21', 'alternative' => 'divisible by']), + new TwigTest('divisible by', null, ['node_class' => '\Twig\Node\Expression\Test\DivisiblebyTest']), + new TwigTest('constant', null, ['node_class' => '\Twig\Node\Expression\Test\ConstantTest']), + new TwigTest('empty', 'twig_test_empty'), + new TwigTest('iterable', 'twig_test_iterable'), ]; } @@ -239,34 +268,34 @@ class Twig_Extension_Core extends \Twig\Extension\AbstractExtension '+' => ['precedence' => 500, 'class' => '\Twig\Node\Expression\Unary\PosUnary'], ], [ - 'or' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'and' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'b-or' => ['precedence' => 16, 'class' => '\Twig\Node\Expression\Binary\BitwiseOrBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'b-xor' => ['precedence' => 17, 'class' => '\Twig\Node\Expression\Binary\BitwiseXorBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'b-and' => ['precedence' => 18, 'class' => '\Twig\Node\Expression\Binary\BitwiseAndBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '==' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '!=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '<' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '>' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '>=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '<=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'not in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotInBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\InBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'matches' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\MatchesBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'starts with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\StartsWithBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'ends with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EndsWithBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '..' => ['precedence' => 25, 'class' => '\Twig\Node\Expression\Binary\RangeBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '+' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\AddBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '-' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\SubBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '~' => ['precedence' => 40, 'class' => '\Twig\Node\Expression\Binary\ConcatBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '*' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\MulBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '/' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\DivBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '//' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\FloorDivBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '%' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'is' => ['precedence' => 100, 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - 'is not' => ['precedence' => 100, 'associativity' => \Twig\ExpressionParser::OPERATOR_LEFT], - '**' => ['precedence' => 200, 'class' => '\Twig\Node\Expression\Binary\PowerBinary', 'associativity' => \Twig\ExpressionParser::OPERATOR_RIGHT], - '??' => ['precedence' => 300, 'class' => '\Twig\Node\Expression\NullCoalesceExpression', 'associativity' => \Twig\ExpressionParser::OPERATOR_RIGHT], + 'or' => ['precedence' => 10, 'class' => '\Twig\Node\Expression\Binary\OrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'and' => ['precedence' => 15, 'class' => '\Twig\Node\Expression\Binary\AndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-or' => ['precedence' => 16, 'class' => '\Twig\Node\Expression\Binary\BitwiseOrBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-xor' => ['precedence' => 17, 'class' => '\Twig\Node\Expression\Binary\BitwiseXorBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'b-and' => ['precedence' => 18, 'class' => '\Twig\Node\Expression\Binary\BitwiseAndBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '==' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '!=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '>=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\GreaterEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '<=' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\LessEqualBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'not in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\NotInBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'in' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\InBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'matches' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\MatchesBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'starts with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\StartsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'ends with' => ['precedence' => 20, 'class' => '\Twig\Node\Expression\Binary\EndsWithBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '..' => ['precedence' => 25, 'class' => '\Twig\Node\Expression\Binary\RangeBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '+' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\AddBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '-' => ['precedence' => 30, 'class' => '\Twig\Node\Expression\Binary\SubBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '~' => ['precedence' => 40, 'class' => '\Twig\Node\Expression\Binary\ConcatBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '*' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\MulBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '/' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\DivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '//' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\FloorDivBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + '%' => ['precedence' => 60, 'class' => '\Twig\Node\Expression\Binary\ModBinary', 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + 'is not' => ['precedence' => 100, 'associativity' => ExpressionParser::OPERATOR_LEFT], + '**' => ['precedence' => 200, 'class' => '\Twig\Node\Expression\Binary\PowerBinary', 'associativity' => ExpressionParser::OPERATOR_RIGHT], + '??' => ['precedence' => 300, 'class' => '\Twig\Node\Expression\NullCoalesceExpression', 'associativity' => ExpressionParser::OPERATOR_RIGHT], ], ]; } @@ -302,7 +331,7 @@ function twig_cycle($values, $position) * * @param \Traversable|array|int|float|string $values The values to pick a random item from * - * @throws \Twig\Error\RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) + * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) * * @return mixed A random value from the given sequence */ @@ -346,7 +375,7 @@ function twig_random(Twig_Environment $env, $values = null) } if (0 === \count($values)) { - throw new \Twig\Error\RuntimeError('The random function cannot pick from an empty array.'); + throw new RuntimeError('The random function cannot pick from an empty array.'); } return $values[array_rand($values, 1)]; @@ -471,7 +500,7 @@ function twig_replace_filter($str, $from, $to = null) return strtr($str, $from, $to); } elseif (!\is_array($from)) { - throw new \Twig\Error\RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); + throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); } return strtr($str, $from); @@ -493,7 +522,7 @@ function twig_round($value, $precision = 0, $method = 'common') } if ('ceil' != $method && 'floor' != $method) { - throw new \Twig\Error\RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); + throw new RuntimeError('The round filter only supports the "common", "ceil", and "floor" methods.'); } return $method($value * pow(10, $precision)) / pow(10, $precision); @@ -561,7 +590,7 @@ function twig_urlencode_filter($url) */ function twig_jsonencode_filter($value, $options = 0) { - if ($value instanceof \Twig\Markup) { + if ($value instanceof Markup) { $value = (string) $value; } elseif (\is_array($value)) { array_walk_recursive($value, '_twig_markup2string'); @@ -572,7 +601,7 @@ function twig_jsonencode_filter($value, $options = 0) function _twig_markup2string(&$value) { - if ($value instanceof \Twig\Markup) { + if ($value instanceof Markup) { $value = (string) $value; } } @@ -596,13 +625,13 @@ function twig_array_merge($arr1, $arr2) if ($arr1 instanceof \Traversable) { $arr1 = iterator_to_array($arr1); } elseif (!\is_array($arr1)) { - throw new \Twig\Error\RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1))); } if ($arr2 instanceof \Traversable) { $arr2 = iterator_to_array($arr2); } elseif (!\is_array($arr2)) { - throw new \Twig\Error\RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); + throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); } return array_merge($arr1, $arr2); @@ -881,7 +910,7 @@ function twig_sort_filter($array) if ($array instanceof \Traversable) { $array = iterator_to_array($array); } elseif (!\is_array($array)) { - throw new \Twig\Error\RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); + throw new RuntimeError(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); } asort($array); @@ -924,7 +953,7 @@ function twig_in_filter($value, $compare) * * @return string * - * @throws \Twig\Error\RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') + * @throws RuntimeError When an invalid trimming side is used (not a string or not 'left', 'right', or 'both') */ function twig_trim_filter($string, $characterMask = null, $side = 'both') { @@ -940,7 +969,7 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both') case 'right': return rtrim($string, $characterMask); default: - throw new \Twig\Error\RuntimeError('Trimming side must be "left", "right" or "both".'); + throw new RuntimeError('Trimming side must be "left", "right" or "both".'); } } @@ -956,7 +985,7 @@ function twig_trim_filter($string, $characterMask = null, $side = 'both') */ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $charset = null, $autoescape = false) { - if ($autoescape && $string instanceof \Twig\Markup) { + if ($autoescape && $string instanceof Markup) { return $string; } @@ -1024,7 +1053,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (!preg_match('//u', $string)) { - throw new \Twig\Error\RuntimeError('The string to escape is not a valid UTF-8 string.'); + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); } $string = preg_replace_callback('#[^a-zA-Z0-9,\._]#Su', '_twig_escape_js_callback', $string); @@ -1041,7 +1070,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (!preg_match('//u', $string)) { - throw new \Twig\Error\RuntimeError('The string to escape is not a valid UTF-8 string.'); + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); } $string = preg_replace_callback('#[^a-zA-Z0-9]#Su', '_twig_escape_css_callback', $string); @@ -1058,7 +1087,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (!preg_match('//u', $string)) { - throw new \Twig\Error\RuntimeError('The string to escape is not a valid UTF-8 string.'); + throw new RuntimeError('The string to escape is not a valid UTF-8 string.'); } $string = preg_replace_callback('#[^a-zA-Z0-9,\.\-_]#Su', '_twig_escape_html_attr_callback', $string); @@ -1085,7 +1114,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); - throw new \Twig\Error\RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); + throw new RuntimeError(sprintf('Invalid escaping strategy "%s" (valid ones: %s).', $strategy, $validStrategies)); } } @@ -1095,7 +1124,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', function twig_escape_filter_is_safe(Twig_Node $filterArgs) { foreach ($filterArgs as $arg) { - if ($arg instanceof \Twig\Node\Expression\ConstantExpression) { + if ($arg instanceof ConstantExpression) { return [$arg->getAttribute('value')]; } @@ -1118,7 +1147,7 @@ if (\function_exists('mb_convert_encoding')) { } else { function twig_convert_encoding($string, $to, $from) { - throw new \Twig\Error\RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); + throw new RuntimeError('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).'); } } @@ -1246,7 +1275,7 @@ if (\function_exists('mb_get_info')) { * * @return int The length of the value */ - function twig_length_filter(\Twig\Environment $env, $thing) + function twig_length_filter(Environment $env, $thing) { if (null === $thing) { return 0; @@ -1282,7 +1311,7 @@ if (\function_exists('mb_get_info')) { * * @return string The uppercased string */ - function twig_upper_filter(\Twig\Environment $env, $string) + function twig_upper_filter(Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_strtoupper($string, $charset); @@ -1298,7 +1327,7 @@ if (\function_exists('mb_get_info')) { * * @return string The lowercased string */ - function twig_lower_filter(\Twig\Environment $env, $string) + function twig_lower_filter(Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_strtolower($string, $charset); @@ -1314,7 +1343,7 @@ if (\function_exists('mb_get_info')) { * * @return string The titlecased string */ - function twig_title_string_filter(\Twig\Environment $env, $string) + function twig_title_string_filter(Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_convert_case($string, MB_CASE_TITLE, $charset); @@ -1330,7 +1359,7 @@ if (\function_exists('mb_get_info')) { * * @return string The capitalized string */ - function twig_capitalize_string_filter(\Twig\Environment $env, $string) + function twig_capitalize_string_filter(Environment $env, $string) { if (null !== $charset = $env->getCharset()) { return mb_strtoupper(mb_substr($string, 0, 1, $charset), $charset).mb_strtolower(mb_substr($string, 1, mb_strlen($string, $charset), $charset), $charset); @@ -1348,7 +1377,7 @@ else { * * @return int The length of the value */ - function twig_length_filter(\Twig\Environment $env, $thing) + function twig_length_filter(Environment $env, $thing) { if (null === $thing) { return 0; @@ -1384,7 +1413,7 @@ else { * * @return string The titlecased string */ - function twig_title_string_filter(\Twig\Environment $env, $string) + function twig_title_string_filter(Environment $env, $string) { return ucwords(strtolower($string)); } @@ -1396,7 +1425,7 @@ else { * * @return string The capitalized string */ - function twig_capitalize_string_filter(\Twig\Environment $env, $string) + function twig_capitalize_string_filter(Environment $env, $string) { return ucfirst(strtolower($string)); } @@ -1486,7 +1515,7 @@ function twig_include(Twig_Environment $env, $context, $template, $variables = [ $result = ''; try { $result = $env->resolveTemplate($template)->render($variables); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { if (!$ignoreMissing) { if ($isSandboxed && !$alreadySandboxed) { $sandbox->disableSandbox(); @@ -1527,12 +1556,12 @@ function twig_source(Twig_Environment $env, $name, $ignoreMissing = false) { $loader = $env->getLoader(); try { - if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) { + if (!$loader instanceof SourceContextLoaderInterface) { return $loader->getSource($name); } else { return $loader->getSourceContext($name)->getCode(); } - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { if (!$ignoreMissing) { throw $e; } diff --git a/lib/Twig/Extension/Debug.php b/lib/Twig/Extension/Debug.php index 16c4afdda..3efeaaed2 100644 --- a/lib/Twig/Extension/Debug.php +++ b/lib/Twig/Extension/Debug.php @@ -9,10 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; +use Twig\Template; + /** * @final */ -class Twig_Extension_Debug extends \Twig\Extension\AbstractExtension +class Twig_Extension_Debug extends AbstractExtension { public function getFunctions() { @@ -27,7 +31,7 @@ class Twig_Extension_Debug extends \Twig\Extension\AbstractExtension ; return [ - new \Twig\TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]), + new TwigFunction('dump', 'twig_var_dump', ['is_safe' => $isDumpOutputHtmlSafe ? ['html'] : [], 'needs_context' => true, 'needs_environment' => true]), ]; } @@ -49,7 +53,7 @@ function twig_var_dump(Twig_Environment $env, $context) if (2 === $count) { $vars = []; foreach ($context as $key => $value) { - if (!$value instanceof \Twig\Template) { + if (!$value instanceof Template) { $vars[$key] = $value; } } diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index a06075c0d..0fcc7e7f5 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -9,10 +9,15 @@ * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\TokenParser\AutoEscapeTokenParser; +use Twig\NodeVisitor\EscaperNodeVisitor; +use Twig\TwigFilter; + /** * @final */ -class Twig_Extension_Escaper extends \Twig\Extension\AbstractExtension +class Twig_Extension_Escaper extends AbstractExtension { protected $defaultStrategy; @@ -28,18 +33,18 @@ class Twig_Extension_Escaper extends \Twig\Extension\AbstractExtension public function getTokenParsers() { - return [new \Twig\TokenParser\AutoEscapeTokenParser()]; + return [new AutoEscapeTokenParser()]; } public function getNodeVisitors() { - return [new \Twig\NodeVisitor\EscaperNodeVisitor()]; + return [new EscaperNodeVisitor()]; } public function getFilters() { return [ - new \Twig\TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), + new TwigFilter('raw', 'twig_raw_filter', ['is_safe' => ['all']]), ]; } diff --git a/lib/Twig/Extension/Optimizer.php b/lib/Twig/Extension/Optimizer.php index 48e53b3ad..d6f247454 100644 --- a/lib/Twig/Extension/Optimizer.php +++ b/lib/Twig/Extension/Optimizer.php @@ -9,10 +9,13 @@ * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\NodeVisitor\OptimizerNodeVisitor; + /** * @final */ -class Twig_Extension_Optimizer extends \Twig\Extension\AbstractExtension +class Twig_Extension_Optimizer extends AbstractExtension { protected $optimizers; @@ -23,7 +26,7 @@ class Twig_Extension_Optimizer extends \Twig\Extension\AbstractExtension public function getNodeVisitors() { - return [new \Twig\NodeVisitor\OptimizerNodeVisitor($this->optimizers)]; + return [new OptimizerNodeVisitor($this->optimizers)]; } public function getName() diff --git a/lib/Twig/Extension/Profiler.php b/lib/Twig/Extension/Profiler.php index 1b7004cf4..c80430226 100644 --- a/lib/Twig/Extension/Profiler.php +++ b/lib/Twig/Extension/Profiler.php @@ -9,22 +9,26 @@ * file that was distributed with this source code. */ -class Twig_Extension_Profiler extends \Twig\Extension\AbstractExtension +use Twig\Extension\AbstractExtension; +use Twig\Profiler\NodeVisitor\ProfilerNodeVisitor; +use Twig\Profiler\Profile; + +class Twig_Extension_Profiler extends AbstractExtension { private $actives = []; - public function __construct(\Twig\Profiler\Profile $profile) + public function __construct(Profile $profile) { $this->actives[] = $profile; } - public function enter(\Twig\Profiler\Profile $profile) + public function enter(Profile $profile) { $this->actives[0]->addProfile($profile); array_unshift($this->actives, $profile); } - public function leave(\Twig\Profiler\Profile $profile) + public function leave(Profile $profile) { $profile->leave(); array_shift($this->actives); @@ -36,7 +40,7 @@ class Twig_Extension_Profiler extends \Twig\Extension\AbstractExtension public function getNodeVisitors() { - return [new \Twig\Profiler\NodeVisitor\ProfilerNodeVisitor(\get_class($this))]; + return [new ProfilerNodeVisitor(\get_class($this))]; } public function getName() diff --git a/lib/Twig/Extension/Sandbox.php b/lib/Twig/Extension/Sandbox.php index a12a56327..a4b5572b5 100644 --- a/lib/Twig/Extension/Sandbox.php +++ b/lib/Twig/Extension/Sandbox.php @@ -9,16 +9,21 @@ * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\TokenParser\SandboxTokenParser; +use Twig\NodeVisitor\SandboxNodeVisitor; +use Twig\Sandbox\SecurityPolicyInterface; + /** * @final */ -class Twig_Extension_Sandbox extends \Twig\Extension\AbstractExtension +class Twig_Extension_Sandbox extends AbstractExtension { protected $sandboxedGlobally; protected $sandboxed; protected $policy; - public function __construct(\Twig\Sandbox\SecurityPolicyInterface $policy, $sandboxed = false) + public function __construct(SecurityPolicyInterface $policy, $sandboxed = false) { $this->policy = $policy; $this->sandboxedGlobally = $sandboxed; @@ -26,12 +31,12 @@ class Twig_Extension_Sandbox extends \Twig\Extension\AbstractExtension public function getTokenParsers() { - return [new \Twig\TokenParser\SandboxTokenParser()]; + return [new SandboxTokenParser()]; } public function getNodeVisitors() { - return [new \Twig\NodeVisitor\SandboxNodeVisitor()]; + return [new SandboxNodeVisitor()]; } public function enableSandbox() @@ -54,7 +59,7 @@ class Twig_Extension_Sandbox extends \Twig\Extension\AbstractExtension return $this->sandboxedGlobally; } - public function setSecurityPolicy(\Twig\Sandbox\SecurityPolicyInterface $policy) + public function setSecurityPolicy(SecurityPolicyInterface $policy) { $this->policy = $policy; } diff --git a/lib/Twig/Extension/Staging.php b/lib/Twig/Extension/Staging.php index 84ccf92b5..837879813 100644 --- a/lib/Twig/Extension/Staging.php +++ b/lib/Twig/Extension/Staging.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\TokenParser\TokenParserInterface; + /** * Internal class. * @@ -18,7 +22,7 @@ * * @internal */ -class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension +class Twig_Extension_Staging extends AbstractExtension { protected $functions = []; protected $filters = []; @@ -55,7 +59,7 @@ class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension return $this->filters; } - public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) + public function addNodeVisitor(NodeVisitorInterface $visitor) { $this->visitors[] = $visitor; } @@ -65,7 +69,7 @@ class Twig_Extension_Staging extends \Twig\Extension\AbstractExtension return $this->visitors; } - public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser) + public function addTokenParser(TokenParserInterface $parser) { if (isset($this->tokenParsers[$parser->getTag()])) { @trigger_error(sprintf('Overriding tag "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $parser->getTag()), E_USER_DEPRECATED); diff --git a/lib/Twig/Extension/StringLoader.php b/lib/Twig/Extension/StringLoader.php index 0b2213910..b75e51a9c 100644 --- a/lib/Twig/Extension/StringLoader.php +++ b/lib/Twig/Extension/StringLoader.php @@ -9,15 +9,19 @@ * file that was distributed with this source code. */ +use Twig\Extension\AbstractExtension; +use Twig\TwigFunction; +use Twig\Template; + /** * @final */ -class Twig_Extension_StringLoader extends \Twig\Extension\AbstractExtension +class Twig_Extension_StringLoader extends AbstractExtension { public function getFunctions() { return [ - new \Twig\TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]), + new TwigFunction('template_from_string', 'twig_template_from_string', ['needs_environment' => true]), ]; } @@ -34,7 +38,7 @@ class Twig_Extension_StringLoader extends \Twig\Extension\AbstractExtension * * @param string $template A template as a string or object implementing __toString() * - * @return \Twig\Template + * @return Template */ function twig_template_from_string(Twig_Environment $env, $template) { diff --git a/lib/Twig/ExtensionInterface.php b/lib/Twig/ExtensionInterface.php index 6e8d1960c..2731e6ad5 100644 --- a/lib/Twig/ExtensionInterface.php +++ b/lib/Twig/ExtensionInterface.php @@ -9,6 +9,13 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\TokenParserInterface; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\TwigFilter; +use Twig\TwigTest; +use Twig\TwigFunction; +use Twig\Environment; + /** * Interface implemented by extension classes. * @@ -23,40 +30,40 @@ interface Twig_ExtensionInterface * * @deprecated since 1.23 (to be removed in 2.0), implement Twig_Extension_InitRuntimeInterface instead */ - public function initRuntime(\Twig\Environment $environment); + public function initRuntime(Environment $environment); /** * Returns the token parser instances to add to the existing list. * - * @return \Twig\TokenParser\TokenParserInterface[] + * @return TokenParserInterface[] */ public function getTokenParsers(); /** * Returns the node visitor instances to add to the existing list. * - * @return \Twig\NodeVisitor\NodeVisitorInterface[] + * @return NodeVisitorInterface[] */ public function getNodeVisitors(); /** * Returns a list of filters to add to the existing list. * - * @return \Twig\TwigFilter[] + * @return TwigFilter[] */ public function getFilters(); /** * Returns a list of tests to add to the existing list. * - * @return \Twig\TwigTest[] + * @return TwigTest[] */ public function getTests(); /** * Returns a list of functions to add to the existing list. * - * @return \Twig\TwigFunction[] + * @return TwigFunction[] */ public function getFunctions(); diff --git a/lib/Twig/FactoryRuntimeLoader.php b/lib/Twig/FactoryRuntimeLoader.php index afd373d55..172fd7b19 100644 --- a/lib/Twig/FactoryRuntimeLoader.php +++ b/lib/Twig/FactoryRuntimeLoader.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\RuntimeLoader\RuntimeLoaderInterface; + /** * Lazy loads the runtime implementations for a Twig element. * * @author Robin Chalas */ -class Twig_FactoryRuntimeLoader implements \Twig\RuntimeLoader\RuntimeLoaderInterface +class Twig_FactoryRuntimeLoader implements RuntimeLoaderInterface { private $map; diff --git a/lib/Twig/Filter.php b/lib/Twig/Filter.php index 6a1aa3111..2cd66cc09 100644 --- a/lib/Twig/Filter.php +++ b/lib/Twig/Filter.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + @trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.', E_USER_DEPRECATED); /** @@ -56,7 +58,7 @@ abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableI return $this->options['needs_context']; } - public function getSafe(\Twig\Node\Node $filterArgs) + public function getSafe(Node $filterArgs) { if (isset($this->options['is_safe'])) { return $this->options['is_safe']; diff --git a/lib/Twig/Filter/Method.php b/lib/Twig/Filter/Method.php index 8121e129d..431ea8282 100644 --- a/lib/Twig/Filter/Method.php +++ b/lib/Twig/Filter/Method.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Extension\ExtensionInterface; + @trigger_error('The Twig_Filter_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFilter instead.', E_USER_DEPRECATED); /** @@ -25,7 +27,7 @@ class Twig_Filter_Method extends Twig_Filter protected $extension; protected $method; - public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = []) + public function __construct(ExtensionInterface $extension, $method, array $options = []) { $options['callable'] = [$extension, $method]; diff --git a/lib/Twig/FilterInterface.php b/lib/Twig/FilterInterface.php index 94db8dc64..f1c131be7 100644 --- a/lib/Twig/FilterInterface.php +++ b/lib/Twig/FilterInterface.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + /** * Represents a template filter. * @@ -31,7 +33,7 @@ interface Twig_FilterInterface public function needsContext(); - public function getSafe(\Twig\Node\Node $filterArgs); + public function getSafe(Node $filterArgs); public function getPreservesSafety(); diff --git a/lib/Twig/Function.php b/lib/Twig/Function.php index 245689ab9..488ed7563 100644 --- a/lib/Twig/Function.php +++ b/lib/Twig/Function.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + @trigger_error('The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.', E_USER_DEPRECATED); /** @@ -54,7 +56,7 @@ abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCal return $this->options['needs_context']; } - public function getSafe(\Twig\Node\Node $functionArgs) + public function getSafe(Node $functionArgs) { if (isset($this->options['is_safe'])) { return $this->options['is_safe']; diff --git a/lib/Twig/Function/Method.php b/lib/Twig/Function/Method.php index 1c58a87ec..38ccd4427 100644 --- a/lib/Twig/Function/Method.php +++ b/lib/Twig/Function/Method.php @@ -10,6 +10,8 @@ * file that was distributed with this source code. */ +use Twig\Extension\ExtensionInterface; + @trigger_error('The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleFunction instead.', E_USER_DEPRECATED); /** @@ -26,7 +28,7 @@ class Twig_Function_Method extends Twig_Function protected $extension; protected $method; - public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = []) + public function __construct(ExtensionInterface $extension, $method, array $options = []) { $options['callable'] = [$extension, $method]; diff --git a/lib/Twig/FunctionInterface.php b/lib/Twig/FunctionInterface.php index 9677ca8ca..3d2730d7d 100644 --- a/lib/Twig/FunctionInterface.php +++ b/lib/Twig/FunctionInterface.php @@ -10,6 +10,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + /** * Represents a template function. * @@ -32,7 +34,7 @@ interface Twig_FunctionInterface public function needsContext(); - public function getSafe(\Twig\Node\Node $filterArgs); + public function getSafe(Node $filterArgs); public function setArguments($arguments); diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 363db6c8c..541b4d0ab 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -10,6 +10,12 @@ * file that was distributed with this source code. */ +use Twig\Source; +use Twig\Error\SyntaxError; +use Twig\TokenStream; +use Twig\Token; +use Twig\Environment; + /** * Lexes a template string. * @@ -49,7 +55,7 @@ class Twig_Lexer implements Twig_LexerInterface const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; const PUNCTUATION = '()[]{}?:.,|'; - public function __construct(\Twig\Environment $env, array $options = []) + public function __construct(Environment $env, array $options = []) { $this->env = $env; @@ -77,9 +83,9 @@ class Twig_Lexer implements Twig_LexerInterface public function tokenize($code, $name = null) { - if (!$code instanceof \Twig\Source) { + if (!$code instanceof Source) { @trigger_error(sprintf('Passing a string as the $code argument of %s() is deprecated since version 1.27 and will be removed in 2.0. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $this->source = new \Twig\Source($code, $name); + $this->source = new Source($code, $name); } else { $this->source = $code; } @@ -136,25 +142,25 @@ class Twig_Lexer implements Twig_LexerInterface } } - $this->pushToken(\Twig\Token::EOF_TYPE); + $this->pushToken(Token::EOF_TYPE); if (!empty($this->brackets)) { list($expect, $lineno) = array_pop($this->brackets); - throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } if ($mbEncoding) { mb_internal_encoding($mbEncoding); } - return new \Twig\TokenStream($this->tokens, $this->source); + return new TokenStream($this->tokens, $this->source); } protected function lexData() { // if no matches are left we return the rest of the template as simple text token if ($this->position == \count($this->positions[0]) - 1) { - $this->pushToken(\Twig\Token::TEXT_TYPE, substr($this->code, $this->cursor)); + $this->pushToken(Token::TEXT_TYPE, substr($this->code, $this->cursor)); $this->cursor = $this->end; return; @@ -174,7 +180,7 @@ class Twig_Lexer implements Twig_LexerInterface if (isset($this->positions[2][$this->position][0])) { $text = rtrim($text); } - $this->pushToken(\Twig\Token::TEXT_TYPE, $text); + $this->pushToken(Token::TEXT_TYPE, $text); $this->moveCursor($textContent.$position[0]); switch ($this->positions[1][$this->position][0]) { @@ -192,14 +198,14 @@ class Twig_Lexer implements Twig_LexerInterface $this->moveCursor($match[0]); $this->lineno = (int) $match[1]; } else { - $this->pushToken(\Twig\Token::BLOCK_START_TYPE); + $this->pushToken(Token::BLOCK_START_TYPE); $this->pushState(self::STATE_BLOCK); $this->currentVarBlockLine = $this->lineno; } break; case $this->options['tag_variable'][0]: - $this->pushToken(\Twig\Token::VAR_START_TYPE); + $this->pushToken(Token::VAR_START_TYPE); $this->pushState(self::STATE_VAR); $this->currentVarBlockLine = $this->lineno; break; @@ -209,7 +215,7 @@ class Twig_Lexer implements Twig_LexerInterface protected function lexBlock() { if (empty($this->brackets) && preg_match($this->regexes['lex_block'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(\Twig\Token::BLOCK_END_TYPE); + $this->pushToken(Token::BLOCK_END_TYPE); $this->moveCursor($match[0]); $this->popState(); } else { @@ -220,7 +226,7 @@ class Twig_Lexer implements Twig_LexerInterface protected function lexVar() { if (empty($this->brackets) && preg_match($this->regexes['lex_var'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(\Twig\Token::VAR_END_TYPE); + $this->pushToken(Token::VAR_END_TYPE); $this->moveCursor($match[0]); $this->popState(); } else { @@ -235,18 +241,18 @@ class Twig_Lexer implements Twig_LexerInterface $this->moveCursor($match[0]); if ($this->cursor >= $this->end) { - throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); + throw new SyntaxError(sprintf('Unclosed "%s".', self::STATE_BLOCK === $this->state ? 'block' : 'variable'), $this->currentVarBlockLine, $this->source); } } // operators if (preg_match($this->regexes['operator'], $this->code, $match, null, $this->cursor)) { - $this->pushToken(\Twig\Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0])); + $this->pushToken(Token::OPERATOR_TYPE, preg_replace('/\s+/', ' ', $match[0])); $this->moveCursor($match[0]); } // names elseif (preg_match(self::REGEX_NAME, $this->code, $match, null, $this->cursor)) { - $this->pushToken(\Twig\Token::NAME_TYPE, $match[0]); + $this->pushToken(Token::NAME_TYPE, $match[0]); $this->moveCursor($match[0]); } // numbers @@ -255,7 +261,7 @@ class Twig_Lexer implements Twig_LexerInterface if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { $number = (int) $match[0]; // integers lower than the maximum } - $this->pushToken(\Twig\Token::NUMBER_TYPE, $number); + $this->pushToken(Token::NUMBER_TYPE, $number); $this->moveCursor($match[0]); } // punctuation @@ -267,21 +273,21 @@ class Twig_Lexer implements Twig_LexerInterface // closing bracket elseif (false !== strpos(')]}', $this->code[$this->cursor])) { if (empty($this->brackets)) { - throw new \Twig\Error\SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + throw new SyntaxError(sprintf('Unexpected "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); } list($expect, $lineno) = array_pop($this->brackets); if ($this->code[$this->cursor] != strtr($expect, '([{', ')]}')) { - throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } } - $this->pushToken(\Twig\Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); + $this->pushToken(Token::PUNCTUATION_TYPE, $this->code[$this->cursor]); ++$this->cursor; } // strings elseif (preg_match(self::REGEX_STRING, $this->code, $match, null, $this->cursor)) { - $this->pushToken(\Twig\Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); + $this->pushToken(Token::STRING_TYPE, stripcslashes(substr($match[0], 1, -1))); $this->moveCursor($match[0]); } // opening double quoted string @@ -292,7 +298,7 @@ class Twig_Lexer implements Twig_LexerInterface } // unlexable else { - throw new \Twig\Error\SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); } } @@ -303,7 +309,7 @@ class Twig_Lexer implements Twig_LexerInterface } if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new \Twig\Error\SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); + throw new SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); } $text = substr($this->code, $this->cursor, $match[0][1] - $this->cursor); @@ -313,13 +319,13 @@ class Twig_Lexer implements Twig_LexerInterface $text = rtrim($text); } - $this->pushToken(\Twig\Token::TEXT_TYPE, $text); + $this->pushToken(Token::TEXT_TYPE, $text); } protected function lexComment() { if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { - throw new \Twig\Error\SyntaxError('Unclosed comment.', $this->lineno, $this->source); + throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source); } $this->moveCursor(substr($this->code, $this->cursor, $match[0][1] - $this->cursor).$match[0][0]); @@ -329,23 +335,23 @@ class Twig_Lexer implements Twig_LexerInterface { if (preg_match($this->regexes['interpolation_start'], $this->code, $match, null, $this->cursor)) { $this->brackets[] = [$this->options['interpolation'][0], $this->lineno]; - $this->pushToken(\Twig\Token::INTERPOLATION_START_TYPE); + $this->pushToken(Token::INTERPOLATION_START_TYPE); $this->moveCursor($match[0]); $this->pushState(self::STATE_INTERPOLATION); } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, null, $this->cursor) && \strlen($match[0]) > 0) { - $this->pushToken(\Twig\Token::STRING_TYPE, stripcslashes($match[0])); + $this->pushToken(Token::STRING_TYPE, stripcslashes($match[0])); $this->moveCursor($match[0]); } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { list($expect, $lineno) = array_pop($this->brackets); if ('"' != $this->code[$this->cursor]) { - throw new \Twig\Error\SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); + throw new SyntaxError(sprintf('Unclosed "%s".', $expect), $lineno, $this->source); } $this->popState(); ++$this->cursor; } else { // unlexable - throw new \Twig\Error\SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); + throw new SyntaxError(sprintf('Unexpected character "%s".', $this->code[$this->cursor]), $this->lineno, $this->source); } } @@ -354,7 +360,7 @@ class Twig_Lexer implements Twig_LexerInterface $bracket = end($this->brackets); if ($this->options['interpolation'][0] === $bracket[0] && preg_match($this->regexes['interpolation_end'], $this->code, $match, null, $this->cursor)) { array_pop($this->brackets); - $this->pushToken(\Twig\Token::INTERPOLATION_END_TYPE); + $this->pushToken(Token::INTERPOLATION_END_TYPE); $this->moveCursor($match[0]); $this->popState(); } else { @@ -365,11 +371,11 @@ class Twig_Lexer implements Twig_LexerInterface protected function pushToken($type, $value = '') { // do not push empty text tokens - if (\Twig\Token::TEXT_TYPE === $type && '' === $value) { + if (Token::TEXT_TYPE === $type && '' === $value) { return; } - $this->tokens[] = new \Twig\Token($type, $value, $this->lineno); + $this->tokens[] = new Token($type, $value, $this->lineno); } protected function moveCursor($text) diff --git a/lib/Twig/LexerInterface.php b/lib/Twig/LexerInterface.php index 2dbcebc28..3e04d8cb5 100644 --- a/lib/Twig/LexerInterface.php +++ b/lib/Twig/LexerInterface.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\TokenStream; +use Twig\Error\SyntaxError; +use Twig\Source; + /** * Interface implemented by lexer classes. * @@ -21,12 +25,12 @@ interface Twig_LexerInterface /** * Tokenizes a source code. * - * @param string|\Twig\Source $code The source code + * @param string|Source $code The source code * @param string $name A unique identifier for the source code * - * @return \Twig\TokenStream + * @return TokenStream * - * @throws \Twig\Error\SyntaxError When the code is syntactically wrong + * @throws SyntaxError When the code is syntactically wrong */ public function tokenize($code, $name = null); } diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 1791e1825..215dbf9c9 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Loader\LoaderInterface; +use Twig\Error\LoaderError; +use Twig\Source; + /** * Loads a template from an array. * @@ -23,7 +27,7 @@ * * @author Fabien Potencier */ -class Twig_Loader_Array implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_Array implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { protected $templates = []; @@ -52,7 +56,7 @@ class Twig_Loader_Array implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad $name = (string) $name; if (!isset($this->templates[$name])) { - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); } return $this->templates[$name]; @@ -62,10 +66,10 @@ class Twig_Loader_Array implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad { $name = (string) $name; if (!isset($this->templates[$name])) { - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); } - return new \Twig\Source($this->templates[$name], $name); + return new Source($this->templates[$name], $name); } public function exists($name) @@ -77,7 +81,7 @@ class Twig_Loader_Array implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad { $name = (string) $name; if (!isset($this->templates[$name])) { - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); } return $name.':'.$this->templates[$name]; @@ -87,7 +91,7 @@ class Twig_Loader_Array implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad { $name = (string) $name; if (!isset($this->templates[$name])) { - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined.', $name)); + throw new LoaderError(sprintf('Template "%s" is not defined.', $name)); } return true; diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index 9cc327ff5..48592c6c5 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\Loader\LoaderInterface; +use Twig\Loader\ExistsLoaderInterface; +use Twig\Error\LoaderError; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Source; + /** * Loads templates from other loaders. * @@ -16,13 +22,13 @@ * * @author Fabien Potencier */ -class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_Chain implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { private $hasSourceCache = []; protected $loaders = []; /** - * @param \Twig\Loader\LoaderInterface[] $loaders + * @param LoaderInterface[] $loaders */ public function __construct(array $loaders = []) { @@ -31,7 +37,7 @@ class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad } } - public function addLoader(\Twig\Loader\LoaderInterface $loader) + public function addLoader(LoaderInterface $loader) { $this->loaders[] = $loader; $this->hasSourceCache = []; @@ -43,40 +49,40 @@ class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { return $loader->getSource($name); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { $exceptions[] = $e->getMessage(); } } - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } public function getSourceContext($name) { $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { - if ($loader instanceof \Twig\Loader\SourceContextLoaderInterface) { + if ($loader instanceof SourceContextLoaderInterface) { return $loader->getSourceContext($name); } - return new \Twig\Source($loader->getSource($name), $name); - } catch (\Twig\Error\LoaderError $e) { + return new Source($loader->getSource($name), $name); + } catch (LoaderError $e) { $exceptions[] = $e->getMessage(); } } - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } public function exists($name) @@ -88,7 +94,7 @@ class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad } foreach ($this->loaders as $loader) { - if ($loader instanceof \Twig\Loader\ExistsLoaderInterface) { + if ($loader instanceof ExistsLoaderInterface) { if ($loader->exists($name)) { return $this->hasSourceCache[$name] = true; } @@ -97,14 +103,14 @@ class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad } try { - if ($loader instanceof \Twig\Loader\SourceContextLoaderInterface) { + if ($loader instanceof SourceContextLoaderInterface) { $loader->getSourceContext($name); } else { $loader->getSource($name); } return $this->hasSourceCache[$name] = true; - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { } } @@ -115,36 +121,36 @@ class Twig_Loader_Chain implements \Twig\Loader\LoaderInterface, Twig_ExistsLoad { $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { return $loader->getCacheKey($name); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { $exceptions[] = \get_class($loader).': '.$e->getMessage(); } } - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } public function isFresh($name, $time) { $exceptions = []; foreach ($this->loaders as $loader) { - if ($loader instanceof \Twig\Loader\ExistsLoaderInterface && !$loader->exists($name)) { + if ($loader instanceof ExistsLoaderInterface && !$loader->exists($name)) { continue; } try { return $loader->isFresh($name, $time); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { $exceptions[] = \get_class($loader).': '.$e->getMessage(); } } - throw new \Twig\Error\LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); + throw new LoaderError(sprintf('Template "%s" is not defined%s.', $name, $exceptions ? ' ('.implode(', ', $exceptions).')' : '')); } } diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index e4ffd1440..8d5a2bf92 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -9,12 +9,16 @@ * file that was distributed with this source code. */ +use Twig\Loader\LoaderInterface; +use Twig\Error\LoaderError; +use Twig\Source; + /** * Loads template from the filesystem. * * @author Fabien Potencier */ -class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_Filesystem implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { /** Identifier of the main namespace. */ const MAIN_NAMESPACE = '__main__'; @@ -89,7 +93,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist * @param string $path A path where to look for templates * @param string $namespace A path namespace * - * @throws \Twig\Error\LoaderError + * @throws LoaderError */ public function addPath($path, $namespace = self::MAIN_NAMESPACE) { @@ -98,7 +102,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; if (!is_dir($checkPath)) { - throw new \Twig\Error\LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); } $this->paths[$namespace][] = rtrim($path, '/\\'); @@ -110,7 +114,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist * @param string $path A path where to look for templates * @param string $namespace A path namespace * - * @throws \Twig\Error\LoaderError + * @throws LoaderError */ public function prependPath($path, $namespace = self::MAIN_NAMESPACE) { @@ -119,7 +123,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist $checkPath = $this->isAbsolutePath($path) ? $path : $this->rootPath.$path; if (!is_dir($checkPath)) { - throw new \Twig\Error\LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); + throw new LoaderError(sprintf('The "%s" directory does not exist ("%s").', $path, $checkPath)); } $path = rtrim($path, '/\\'); @@ -142,7 +146,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist { $path = $this->findTemplate($name); - return new \Twig\Source(file_get_contents($path), $name, $path); + return new Source(file_get_contents($path), $name, $path); } public function getCacheKey($name) @@ -166,7 +170,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist try { return false !== $this->findTemplate($name, false); - } catch (\Twig\Error\LoaderError $exception) { + } catch (LoaderError $exception) { @trigger_error(sprintf('In %s::findTemplate(), you must accept a second argument that when set to "false" returns "false" instead of throwing an exception. Not supporting this argument is deprecated since version 1.27.', \get_class($this)), E_USER_DEPRECATED); return false; @@ -192,14 +196,14 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist return false; } - throw new \Twig\Error\LoaderError($this->errorCache[$name]); + throw new LoaderError($this->errorCache[$name]); } try { $this->validateName($name); list($namespace, $shortname) = $this->parseName($name); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { if (!$throw) { return false; } @@ -214,7 +218,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist return false; } - throw new \Twig\Error\LoaderError($this->errorCache[$name]); + throw new LoaderError($this->errorCache[$name]); } foreach ($this->paths[$namespace] as $path) { @@ -237,14 +241,14 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist return false; } - throw new \Twig\Error\LoaderError($this->errorCache[$name]); + throw new LoaderError($this->errorCache[$name]); } protected function parseName($name, $default = self::MAIN_NAMESPACE) { if (isset($name[0]) && '@' == $name[0]) { if (false === $pos = strpos($name, '/')) { - throw new \Twig\Error\LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); + throw new LoaderError(sprintf('Malformed namespaced template name "%s" (expecting "@namespace/template_name").', $name)); } $namespace = substr($name, 1, $pos - 1); @@ -264,7 +268,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist protected function validateName($name) { if (false !== strpos($name, "\0")) { - throw new \Twig\Error\LoaderError('A template name cannot contain NUL bytes.'); + throw new LoaderError('A template name cannot contain NUL bytes.'); } $name = ltrim($name, '/'); @@ -278,7 +282,7 @@ class Twig_Loader_Filesystem implements \Twig\Loader\LoaderInterface, Twig_Exist } if ($level < 0) { - throw new \Twig\Error\LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); + throw new LoaderError(sprintf('Looks like you try to load a template outside configured directories (%s).', $name)); } } } diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index 7398aecc4..e7e046c42 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Loader\LoaderInterface; +use Twig\Source; + @trigger_error('The Twig_Loader_String class is deprecated since version 1.18.1 and will be removed in 2.0. Use "Twig\Loader\ArrayLoader" instead or "Twig\Environment::createTemplate()".', E_USER_DEPRECATED); /** @@ -27,7 +30,7 @@ * * @author Fabien Potencier */ -class Twig_Loader_String implements \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +class Twig_Loader_String implements LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { public function getSource($name) { @@ -38,7 +41,7 @@ class Twig_Loader_String implements \Twig\Loader\LoaderInterface, Twig_ExistsLoa public function getSourceContext($name) { - return new \Twig\Source($name, $name); + return new Source($name, $name); } public function exists($name) diff --git a/lib/Twig/LoaderInterface.php b/lib/Twig/LoaderInterface.php index 66817f294..e78a2d951 100644 --- a/lib/Twig/LoaderInterface.php +++ b/lib/Twig/LoaderInterface.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Error\LoaderError; + /** * Interface all loaders must implement. * @@ -23,7 +25,7 @@ interface Twig_LoaderInterface * * @return string The template source code * - * @throws \Twig\Error\LoaderError When $name is not found + * @throws LoaderError When $name is not found * * @deprecated since 1.27 (to be removed in 2.0), implement Twig_SourceContextLoaderInterface */ @@ -36,7 +38,7 @@ interface Twig_LoaderInterface * * @return string The cache key * - * @throws \Twig\Error\LoaderError When $name is not found + * @throws LoaderError When $name is not found */ public function getCacheKey($name); @@ -49,7 +51,7 @@ interface Twig_LoaderInterface * * @return bool true if the template is fresh, false otherwise * - * @throws \Twig\Error\LoaderError When $name is not found + * @throws LoaderError When $name is not found */ public function isFresh($name, $time); } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index b4853522b..d53bbf72a 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -10,6 +10,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a node in the AST. * @@ -111,7 +114,7 @@ class Twig_Node implements Twig_NodeInterface return $asDom ? $dom : $dom->saveXML(); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { foreach ($this->nodes as $node) { $node->compile($compiler); @@ -181,7 +184,7 @@ class Twig_Node implements Twig_NodeInterface } /** - * @return \Twig\Node\Node + * @return Node */ public function getNode($name) { diff --git a/lib/Twig/Node/AutoEscape.php b/lib/Twig/Node/AutoEscape.php index beb0486c2..7f5451a4c 100644 --- a/lib/Twig/Node/AutoEscape.php +++ b/lib/Twig/Node/AutoEscape.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents an autoescape node. * @@ -20,14 +23,14 @@ * * @author Fabien Potencier */ -class Twig_Node_AutoEscape extends \Twig\Node\Node +class Twig_Node_AutoEscape extends Node { public function __construct($value, Twig_NodeInterface $body, $lineno, $tag = 'autoescape') { parent::__construct(['body' => $body], ['value' => $value], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->subcompile($this->getNode('body')); } diff --git a/lib/Twig/Node/Block.php b/lib/Twig/Node/Block.php index 68f8f3121..e2cefe6d5 100644 --- a/lib/Twig/Node/Block.php +++ b/lib/Twig/Node/Block.php @@ -10,19 +10,22 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a block node. * * @author Fabien Potencier */ -class Twig_Node_Block extends \Twig\Node\Node +class Twig_Node_Block extends Node { public function __construct($name, Twig_NodeInterface $body, $lineno, $tag = null) { parent::__construct(['body' => $body], ['name' => $name], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/BlockReference.php b/lib/Twig/Node/BlockReference.php index c56f37ee6..232ac960d 100644 --- a/lib/Twig/Node/BlockReference.php +++ b/lib/Twig/Node/BlockReference.php @@ -10,19 +10,23 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\NodeOutputInterface; +use Twig\Compiler; + /** * Represents a block call node. * * @author Fabien Potencier */ -class Twig_Node_BlockReference extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface +class Twig_Node_BlockReference extends Node implements NodeOutputInterface { public function __construct($name, $lineno, $tag = null) { parent::__construct([], ['name' => $name], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Body.php b/lib/Twig/Node/Body.php index 5314fa1c9..d9132ace1 100644 --- a/lib/Twig/Node/Body.php +++ b/lib/Twig/Node/Body.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + /** * Represents a body node. * * @author Fabien Potencier */ -class Twig_Node_Body extends \Twig\Node\Node +class Twig_Node_Body extends Node { } diff --git a/lib/Twig/Node/CheckSecurity.php b/lib/Twig/Node/CheckSecurity.php index 570735929..54d56422f 100644 --- a/lib/Twig/Node/CheckSecurity.php +++ b/lib/Twig/Node/CheckSecurity.php @@ -9,10 +9,17 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Sandbox\SecurityNotAllowedTagError; +use Twig\Sandbox\SecurityNotAllowedFilterError; +use Twig\Sandbox\SecurityNotAllowedFunctionError; +use Twig\Compiler; +use Twig\Sandbox\SecurityError; + /** * @author Fabien Potencier */ -class Twig_Node_CheckSecurity extends \Twig\Node\Node +class Twig_Node_CheckSecurity extends Node { protected $usedFilters; protected $usedTags; @@ -27,12 +34,12 @@ class Twig_Node_CheckSecurity extends \Twig\Node\Node parent::__construct(); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $tags = $filters = $functions = []; foreach (['tags', 'filters', 'functions'] as $type) { foreach ($this->{'used'.ucfirst($type)} as $name => $node) { - if ($node instanceof \Twig\Node\Node) { + if ($node instanceof Node) { ${$type}[$name] = $node->getTemplateLine(); } else { ${$type}[$node] = null; @@ -54,18 +61,18 @@ class Twig_Node_CheckSecurity extends \Twig\Node\Node ->outdent() ->write(");\n") ->outdent() - ->write("} catch (\Twig\Sandbox\SecurityError \$e) {\n") + ->write("} catch (SecurityError \$e) {\n") ->indent() ->write("\$e->setSourceContext(\$this->getSourceContext());\n\n") - ->write("if (\$e instanceof \Twig\Sandbox\SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") + ->write("if (\$e instanceof SecurityNotAllowedTagError && isset(\$tags[\$e->getTagName()])) {\n") ->indent() ->write("\$e->setTemplateLine(\$tags[\$e->getTagName()]);\n") ->outdent() - ->write("} elseif (\$e instanceof \Twig\Sandbox\SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") + ->write("} elseif (\$e instanceof SecurityNotAllowedFilterError && isset(\$filters[\$e->getFilterName()])) {\n") ->indent() ->write("\$e->setTemplateLine(\$filters[\$e->getFilterName()]);\n") ->outdent() - ->write("} elseif (\$e instanceof \Twig\Sandbox\SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") + ->write("} elseif (\$e instanceof SecurityNotAllowedFunctionError && isset(\$functions[\$e->getFunctionName()])) {\n") ->indent() ->write("\$e->setTemplateLine(\$functions[\$e->getFunctionName()]);\n") ->outdent() diff --git a/lib/Twig/Node/Deprecated.php b/lib/Twig/Node/Deprecated.php index f793e74b5..94bd7906b 100644 --- a/lib/Twig/Node/Deprecated.php +++ b/lib/Twig/Node/Deprecated.php @@ -9,25 +9,30 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; + /** * Represents a deprecated node. * * @author Yonel Ceruto */ -class Twig_Node_Deprecated extends \Twig\Node\Node +class Twig_Node_Deprecated extends Node { - public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) + public function __construct(AbstractExpression $expr, $lineno, $tag = null) { parent::__construct(['expr' => $expr], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); $expr = $this->getNode('expr'); - if ($expr instanceof \Twig\Node\Expression\ConstantExpression) { + if ($expr instanceof ConstantExpression) { $compiler->write('@trigger_error(') ->subcompile($expr); } else { diff --git a/lib/Twig/Node/Do.php b/lib/Twig/Node/Do.php index 28e7ab0ee..f5973dcb8 100644 --- a/lib/Twig/Node/Do.php +++ b/lib/Twig/Node/Do.php @@ -9,19 +9,23 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; + /** * Represents a do node. * * @author Fabien Potencier */ -class Twig_Node_Do extends \Twig\Node\Node +class Twig_Node_Do extends Node { - public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) + public function __construct(AbstractExpression $expr, $lineno, $tag = null) { parent::__construct(['expr' => $expr], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Embed.php b/lib/Twig/Node/Embed.php index f32c3bc25..b4a77d535 100644 --- a/lib/Twig/Node/Embed.php +++ b/lib/Twig/Node/Embed.php @@ -9,17 +9,22 @@ * file that was distributed with this source code. */ +use Twig\Node\IncludeNode; +use Twig\Node\Expression\ConstantExpression; +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + /** * Represents an embed node. * * @author Fabien Potencier */ -class Twig_Node_Embed extends \Twig\Node\IncludeNode +class Twig_Node_Embed extends IncludeNode { // we don't inject the module to avoid node visitors to traverse it twice (as it will be already visited in the main module) - public function __construct($name, $index, \Twig\Node\Expression\AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) + public function __construct($name, $index, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) { - parent::__construct(new \Twig\Node\Expression\ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); + parent::__construct(new ConstantExpression('not_used', $lineno), $variables, $only, $ignoreMissing, $lineno, $tag); $this->setAttribute('name', $name); // to be removed in 2.0, used name instead @@ -27,7 +32,7 @@ class Twig_Node_Embed extends \Twig\Node\IncludeNode $this->setAttribute('index', $index); } - protected function addGetTemplate(\Twig\Compiler $compiler) + protected function addGetTemplate(Compiler $compiler) { $compiler ->write('$this->loadTemplate(') diff --git a/lib/Twig/Node/Expression.php b/lib/Twig/Node/Expression.php index 4fd85c570..bbef64f59 100644 --- a/lib/Twig/Node/Expression.php +++ b/lib/Twig/Node/Expression.php @@ -10,12 +10,14 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + /** * Abstract class for all nodes that represents an expression. * * @author Fabien Potencier */ -abstract class Twig_Node_Expression extends \Twig\Node\Node +abstract class Twig_Node_Expression extends Node { } diff --git a/lib/Twig/Node/Expression/Array.php b/lib/Twig/Node/Expression/Array.php index 0ff671c9e..092997869 100644 --- a/lib/Twig/Node/Expression/Array.php +++ b/lib/Twig/Node/Expression/Array.php @@ -8,7 +8,11 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Array extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Compiler; +class Twig_Node_Expression_Array extends AbstractExpression { protected $index; @@ -18,7 +22,7 @@ class Twig_Node_Expression_Array extends \Twig\Node\Expression\AbstractExpressio $this->index = -1; foreach ($this->getKeyValuePairs() as $pair) { - if ($pair['key'] instanceof \Twig\Node\Expression\ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { + if ($pair['key'] instanceof ConstantExpression && ctype_digit((string) $pair['key']->getAttribute('value')) && $pair['key']->getAttribute('value') > $this->index) { $this->index = $pair['key']->getAttribute('value'); } } @@ -38,7 +42,7 @@ class Twig_Node_Expression_Array extends \Twig\Node\Expression\AbstractExpressio return $pairs; } - public function hasElement(\Twig\Node\Expression\AbstractExpression $key) + public function hasElement(AbstractExpression $key) { foreach ($this->getKeyValuePairs() as $pair) { // we compare the string representation of the keys @@ -51,16 +55,16 @@ class Twig_Node_Expression_Array extends \Twig\Node\Expression\AbstractExpressio return false; } - public function addElement(\Twig\Node\Expression\AbstractExpression $value, \Twig\Node\Expression\AbstractExpression $key = null) + public function addElement(AbstractExpression $value, AbstractExpression $key = null) { if (null === $key) { - $key = new \Twig\Node\Expression\ConstantExpression(++$this->index, $value->getTemplateLine()); + $key = new ConstantExpression(++$this->index, $value->getTemplateLine()); } array_push($this->nodes, $key, $value); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->raw('['); $first = true; diff --git a/lib/Twig/Node/Expression/AssignName.php b/lib/Twig/Node/Expression/AssignName.php index e67b91ebf..48f8aac65 100644 --- a/lib/Twig/Node/Expression/AssignName.php +++ b/lib/Twig/Node/Expression/AssignName.php @@ -10,9 +10,12 @@ * file that was distributed with this source code. */ -class Twig_Node_Expression_AssignName extends \Twig\Node\Expression\NameExpression +use Twig\Node\Expression\NameExpression; +use Twig\Compiler; + +class Twig_Node_Expression_AssignName extends NameExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('$context[') diff --git a/lib/Twig/Node/Expression/Binary.php b/lib/Twig/Node/Expression/Binary.php index 2b1fcfe76..c7fcbd50a 100644 --- a/lib/Twig/Node/Expression/Binary.php +++ b/lib/Twig/Node/Expression/Binary.php @@ -9,14 +9,17 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -abstract class Twig_Node_Expression_Binary extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +abstract class Twig_Node_Expression_Binary extends AbstractExpression { public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) { parent::__construct(['left' => $left, 'right' => $right], [], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(') @@ -31,7 +34,7 @@ abstract class Twig_Node_Expression_Binary extends \Twig\Node\Expression\Abstrac ; } - abstract public function operator(\Twig\Compiler $compiler); + abstract public function operator(Compiler $compiler); } class_alias('Twig_Node_Expression_Binary', 'Twig\Node\Expression\Binary\AbstractBinary', false); diff --git a/lib/Twig/Node/Expression/Binary/Add.php b/lib/Twig/Node/Expression/Binary/Add.php index 6444f5d44..fc46803f0 100644 --- a/lib/Twig/Node/Expression/Binary/Add.php +++ b/lib/Twig/Node/Expression/Binary/Add.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Add extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Add extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('+'); } diff --git a/lib/Twig/Node/Expression/Binary/And.php b/lib/Twig/Node/Expression/Binary/And.php index 9dc35f638..b5d64fa94 100644 --- a/lib/Twig/Node/Expression/Binary/And.php +++ b/lib/Twig/Node/Expression/Binary/And.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_And extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_And extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('&&'); } diff --git a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php index a766102bb..ca3795a3e 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_BitwiseAnd extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_BitwiseAnd extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('&'); } diff --git a/lib/Twig/Node/Expression/Binary/BitwiseOr.php b/lib/Twig/Node/Expression/Binary/BitwiseOr.php index cf30c8e02..36f40d2b0 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseOr.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseOr.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_BitwiseOr extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_BitwiseOr extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('|'); } diff --git a/lib/Twig/Node/Expression/Binary/BitwiseXor.php b/lib/Twig/Node/Expression/Binary/BitwiseXor.php index 6cd953dac..b3b5e72e1 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseXor.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseXor.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_BitwiseXor extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_BitwiseXor extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('^'); } diff --git a/lib/Twig/Node/Expression/Binary/Concat.php b/lib/Twig/Node/Expression/Binary/Concat.php index 071cb3fb1..fc499c5c4 100644 --- a/lib/Twig/Node/Expression/Binary/Concat.php +++ b/lib/Twig/Node/Expression/Binary/Concat.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Concat extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Concat extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('.'); } diff --git a/lib/Twig/Node/Expression/Binary/Div.php b/lib/Twig/Node/Expression/Binary/Div.php index 5304a6042..b93ebdfc7 100644 --- a/lib/Twig/Node/Expression/Binary/Div.php +++ b/lib/Twig/Node/Expression/Binary/Div.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Div extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Div extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('/'); } diff --git a/lib/Twig/Node/Expression/Binary/EndsWith.php b/lib/Twig/Node/Expression/Binary/EndsWith.php index 85cacfe01..501966111 100644 --- a/lib/Twig/Node/Expression/Binary/EndsWith.php +++ b/lib/Twig/Node/Expression/Binary/EndsWith.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_EndsWith extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_EndsWith extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $left = $compiler->getVarName(); $right = $compiler->getVarName(); @@ -23,7 +26,7 @@ class Twig_Node_Expression_Binary_EndsWith extends \Twig\Node\Expression\Binary\ ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw(''); } diff --git a/lib/Twig/Node/Expression/Binary/Equal.php b/lib/Twig/Node/Expression/Binary/Equal.php index 96ef71798..54e3af9c1 100644 --- a/lib/Twig/Node/Expression/Binary/Equal.php +++ b/lib/Twig/Node/Expression/Binary/Equal.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Equal extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Equal extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('=='); } diff --git a/lib/Twig/Node/Expression/Binary/FloorDiv.php b/lib/Twig/Node/Expression/Binary/FloorDiv.php index 46eeb4cc1..193c38319 100644 --- a/lib/Twig/Node/Expression/Binary/FloorDiv.php +++ b/lib/Twig/Node/Expression/Binary/FloorDiv.php @@ -8,16 +8,19 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_FloorDiv extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_FloorDiv extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->raw('(int) floor('); parent::compile($compiler); $compiler->raw(')'); } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('/'); } diff --git a/lib/Twig/Node/Expression/Binary/Greater.php b/lib/Twig/Node/Expression/Binary/Greater.php index 7c2272c75..bdc056ea0 100644 --- a/lib/Twig/Node/Expression/Binary/Greater.php +++ b/lib/Twig/Node/Expression/Binary/Greater.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Greater extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Greater extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('>'); } diff --git a/lib/Twig/Node/Expression/Binary/GreaterEqual.php b/lib/Twig/Node/Expression/Binary/GreaterEqual.php index be48bec7a..2ee5fc14d 100644 --- a/lib/Twig/Node/Expression/Binary/GreaterEqual.php +++ b/lib/Twig/Node/Expression/Binary/GreaterEqual.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_GreaterEqual extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_GreaterEqual extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('>='); } diff --git a/lib/Twig/Node/Expression/Binary/In.php b/lib/Twig/Node/Expression/Binary/In.php index ebb986c19..a9b91424a 100644 --- a/lib/Twig/Node/Expression/Binary/In.php +++ b/lib/Twig/Node/Expression/Binary/In.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_In extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_In extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('twig_in_filter(') @@ -21,7 +24,7 @@ class Twig_Node_Expression_Binary_In extends \Twig\Node\Expression\Binary\Abstra ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('in'); } diff --git a/lib/Twig/Node/Expression/Binary/Less.php b/lib/Twig/Node/Expression/Binary/Less.php index 79de38cbd..1726e23da 100644 --- a/lib/Twig/Node/Expression/Binary/Less.php +++ b/lib/Twig/Node/Expression/Binary/Less.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Less extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Less extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('<'); } diff --git a/lib/Twig/Node/Expression/Binary/LessEqual.php b/lib/Twig/Node/Expression/Binary/LessEqual.php index 77d1b2cbf..e59e8d756 100644 --- a/lib/Twig/Node/Expression/Binary/LessEqual.php +++ b/lib/Twig/Node/Expression/Binary/LessEqual.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_LessEqual extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_LessEqual extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('<='); } diff --git a/lib/Twig/Node/Expression/Binary/Matches.php b/lib/Twig/Node/Expression/Binary/Matches.php index 0e5cde297..eadae82d9 100644 --- a/lib/Twig/Node/Expression/Binary/Matches.php +++ b/lib/Twig/Node/Expression/Binary/Matches.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Matches extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Matches extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('preg_match(') @@ -21,7 +24,7 @@ class Twig_Node_Expression_Binary_Matches extends \Twig\Node\Expression\Binary\A ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw(''); } diff --git a/lib/Twig/Node/Expression/Binary/Mod.php b/lib/Twig/Node/Expression/Binary/Mod.php index e577277f7..2519e492c 100644 --- a/lib/Twig/Node/Expression/Binary/Mod.php +++ b/lib/Twig/Node/Expression/Binary/Mod.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Mod extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Mod extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('%'); } diff --git a/lib/Twig/Node/Expression/Binary/Mul.php b/lib/Twig/Node/Expression/Binary/Mul.php index 8d39682f2..985e6387b 100644 --- a/lib/Twig/Node/Expression/Binary/Mul.php +++ b/lib/Twig/Node/Expression/Binary/Mul.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Mul extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Mul extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('*'); } diff --git a/lib/Twig/Node/Expression/Binary/NotEqual.php b/lib/Twig/Node/Expression/Binary/NotEqual.php index d79d60f26..0a59fc556 100644 --- a/lib/Twig/Node/Expression/Binary/NotEqual.php +++ b/lib/Twig/Node/Expression/Binary/NotEqual.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_NotEqual extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_NotEqual extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('!='); } diff --git a/lib/Twig/Node/Expression/Binary/NotIn.php b/lib/Twig/Node/Expression/Binary/NotIn.php index 5139d9c68..764e412d8 100644 --- a/lib/Twig/Node/Expression/Binary/NotIn.php +++ b/lib/Twig/Node/Expression/Binary/NotIn.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_NotIn extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_NotIn extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('!twig_in_filter(') @@ -21,7 +24,7 @@ class Twig_Node_Expression_Binary_NotIn extends \Twig\Node\Expression\Binary\Abs ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('not in'); } diff --git a/lib/Twig/Node/Expression/Binary/Or.php b/lib/Twig/Node/Expression/Binary/Or.php index f02517f15..9f9d925ed 100644 --- a/lib/Twig/Node/Expression/Binary/Or.php +++ b/lib/Twig/Node/Expression/Binary/Or.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Or extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Or extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('||'); } diff --git a/lib/Twig/Node/Expression/Binary/Power.php b/lib/Twig/Node/Expression/Binary/Power.php index 67c45bddb..a2f0da65a 100644 --- a/lib/Twig/Node/Expression/Binary/Power.php +++ b/lib/Twig/Node/Expression/Binary/Power.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Power extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Power extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { if (PHP_VERSION_ID >= 50600) { return parent::compile($compiler); @@ -25,7 +28,7 @@ class Twig_Node_Expression_Binary_Power extends \Twig\Node\Expression\Binary\Abs ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('**'); } diff --git a/lib/Twig/Node/Expression/Binary/Range.php b/lib/Twig/Node/Expression/Binary/Range.php index 9ef312e06..e1f7bb9a6 100644 --- a/lib/Twig/Node/Expression/Binary/Range.php +++ b/lib/Twig/Node/Expression/Binary/Range.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Range extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Range extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('range(') @@ -21,7 +24,7 @@ class Twig_Node_Expression_Binary_Range extends \Twig\Node\Expression\Binary\Abs ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('..'); } diff --git a/lib/Twig/Node/Expression/Binary/StartsWith.php b/lib/Twig/Node/Expression/Binary/StartsWith.php index 140cd772b..f0f3c55c2 100644 --- a/lib/Twig/Node/Expression/Binary/StartsWith.php +++ b/lib/Twig/Node/Expression/Binary/StartsWith.php @@ -8,9 +8,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_StartsWith extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_StartsWith extends AbstractBinary { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $left = $compiler->getVarName(); $right = $compiler->getVarName(); @@ -23,7 +26,7 @@ class Twig_Node_Expression_Binary_StartsWith extends \Twig\Node\Expression\Binar ; } - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw(''); } diff --git a/lib/Twig/Node/Expression/Binary/Sub.php b/lib/Twig/Node/Expression/Binary/Sub.php index 098b6a0ae..adb1ca12a 100644 --- a/lib/Twig/Node/Expression/Binary/Sub.php +++ b/lib/Twig/Node/Expression/Binary/Sub.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Binary_Sub extends \Twig\Node\Expression\Binary\AbstractBinary + +use Twig\Node\Expression\Binary\AbstractBinary; +use Twig\Compiler; +class Twig_Node_Expression_Binary_Sub extends AbstractBinary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { return $compiler->raw('-'); } diff --git a/lib/Twig/Node/Expression/BlockReference.php b/lib/Twig/Node/Expression/BlockReference.php index b753104f9..463d93462 100644 --- a/lib/Twig/Node/Expression/BlockReference.php +++ b/lib/Twig/Node/Expression/BlockReference.php @@ -10,15 +10,19 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a block call node. * * @author Fabien Potencier */ -class Twig_Node_Expression_BlockReference extends \Twig\Node\Expression\AbstractExpression +class Twig_Node_Expression_BlockReference extends AbstractExpression { /** - * @param \Twig\Node\Node|null $template + * @param Node|null $template */ public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null) { @@ -36,7 +40,7 @@ class Twig_Node_Expression_BlockReference extends \Twig\Node\Expression\Abstract parent::__construct($nodes, ['is_defined_test' => false, 'output' => false], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { if ($this->getAttribute('is_defined_test')) { $this->compileTemplateCall($compiler, 'hasBlock'); @@ -53,7 +57,7 @@ class Twig_Node_Expression_BlockReference extends \Twig\Node\Expression\Abstract } } - private function compileTemplateCall(\Twig\Compiler $compiler, $method) + private function compileTemplateCall(Compiler $compiler, $method) { if (!$this->hasNode('template')) { $compiler->write('$this'); @@ -75,7 +79,7 @@ class Twig_Node_Expression_BlockReference extends \Twig\Node\Expression\Abstract return $compiler; } - private function compileBlockArguments(\Twig\Compiler $compiler) + private function compileBlockArguments(Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 2626a28d8..e670fe242 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -8,11 +8,19 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Extension\ExtensionInterface; +use Twig\Error\SyntaxError; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Node; +use Twig\Compiler; +abstract class Twig_Node_Expression_Call extends AbstractExpression { private $reflector; - protected function compileCallable(\Twig\Compiler $compiler) + protected function compileCallable(Compiler $compiler) { $closingParenthesis = false; $isArray = false; @@ -27,7 +35,7 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE } else { $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); } - } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof \Twig\Extension\ExtensionInterface) { + } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof ExtensionInterface) { $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($callable[0]), $callable[1])); } else { $type = ucfirst($this->getAttribute('type')); @@ -47,7 +55,7 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE } } - protected function compileArguments(\Twig\Compiler $compiler, $isArray = false) + protected function compileArguments(Compiler $compiler, $isArray = false) { $compiler->raw($isArray ? '[' : '('); @@ -113,7 +121,7 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE $named = true; $name = $this->normalizeName($name); } elseif ($named) { - throw new \Twig\Error\SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine()); + throw new SyntaxError(sprintf('Positional arguments cannot be used after named arguments for %s "%s".', $callType, $callName), $this->getTemplateLine()); } $parameters[$name] = $node; @@ -145,11 +153,11 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE if (\array_key_exists($name, $parameters)) { if (\array_key_exists($pos, $parameters)) { - throw new \Twig\Error\SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); + throw new SyntaxError(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); } if (\count($missingArguments)) { - throw new \Twig\Error\SyntaxError(sprintf( + throw new SyntaxError(sprintf( 'Argument "%s" could not be assigned for %s "%s(%s)" because it is mapped to an internal PHP function which cannot determine default value for optional argument%s "%s".', $name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) ), $this->getTemplateLine()); @@ -166,7 +174,7 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE $optionalArguments = []; ++$pos; } elseif ($callableParameter->isDefaultValueAvailable()) { - $optionalArguments[] = new \Twig\Node\Expression\ConstantExpression($callableParameter->getDefaultValue(), -1); + $optionalArguments[] = new ConstantExpression($callableParameter->getDefaultValue(), -1); } elseif ($callableParameter->isOptional()) { if (empty($parameters)) { break; @@ -174,17 +182,17 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE $missingArguments[] = $name; } } else { - throw new \Twig\Error\SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); + throw new SyntaxError(sprintf('Value for argument "%s" is required for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); } } if ($isVariadic) { - $arbitraryArguments = new \Twig\Node\Expression\ArrayExpression([], -1); + $arbitraryArguments = new ArrayExpression([], -1); foreach ($parameters as $key => $value) { if (\is_int($key)) { $arbitraryArguments->addElement($value); } else { - $arbitraryArguments->addElement($value, new \Twig\Node\Expression\ConstantExpression($key, -1)); + $arbitraryArguments->addElement($value, new ConstantExpression($key, -1)); } unset($parameters[$key]); } @@ -198,13 +206,13 @@ abstract class Twig_Node_Expression_Call extends \Twig\Node\Expression\AbstractE if (!empty($parameters)) { $unknownParameter = null; foreach ($parameters as $parameter) { - if ($parameter instanceof \Twig\Node\Node) { + if ($parameter instanceof Node) { $unknownParameter = $parameter; break; } } - throw new \Twig\Error\SyntaxError(sprintf( + throw new SyntaxError(sprintf( 'Unknown argument%s "%s" for %s "%s(%s)".', \count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) ), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine()); diff --git a/lib/Twig/Node/Expression/Conditional.php b/lib/Twig/Node/Expression/Conditional.php index 7f3a6c9a2..1a535d9f4 100644 --- a/lib/Twig/Node/Expression/Conditional.php +++ b/lib/Twig/Node/Expression/Conditional.php @@ -9,14 +9,17 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Conditional extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +class Twig_Node_Expression_Conditional extends AbstractExpression { - public function __construct(\Twig\Node\Expression\AbstractExpression $expr1, \Twig\Node\Expression\AbstractExpression $expr2, \Twig\Node\Expression\AbstractExpression $expr3, $lineno) + public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, $lineno) { parent::__construct(['expr1' => $expr1, 'expr2' => $expr2, 'expr3' => $expr3], [], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('((') diff --git a/lib/Twig/Node/Expression/Constant.php b/lib/Twig/Node/Expression/Constant.php index cd0180576..90a6b51b2 100644 --- a/lib/Twig/Node/Expression/Constant.php +++ b/lib/Twig/Node/Expression/Constant.php @@ -9,14 +9,17 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Constant extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +class Twig_Node_Expression_Constant extends AbstractExpression { public function __construct($value, $lineno) { parent::__construct([], ['value' => $value], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->repr($this->getAttribute('value')); } diff --git a/lib/Twig/Node/Expression/ExtensionReference.php b/lib/Twig/Node/Expression/ExtensionReference.php index dfec4214a..1296aa1ca 100644 --- a/lib/Twig/Node/Expression/ExtensionReference.php +++ b/lib/Twig/Node/Expression/ExtensionReference.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; + @trigger_error('The Twig_Node_Expression_ExtensionReference class is deprecated since version 1.23 and will be removed in 2.0.', E_USER_DEPRECATED); /** @@ -18,14 +21,14 @@ * * @deprecated since 1.23 and will be removed in 2.0. */ -class Twig_Node_Expression_ExtensionReference extends \Twig\Node\Expression\AbstractExpression +class Twig_Node_Expression_ExtensionReference extends AbstractExpression { public function __construct($name, $lineno, $tag = null) { parent::__construct([], ['name' => $name], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->raw(sprintf("\$this->env->getExtension('%s')", $this->getAttribute('name'))); } diff --git a/lib/Twig/Node/Expression/Filter.php b/lib/Twig/Node/Expression/Filter.php index 2efaf3ca0..3023d3d7d 100644 --- a/lib/Twig/Node/Expression/Filter.php +++ b/lib/Twig/Node/Expression/Filter.php @@ -9,14 +9,19 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Filter extends \Twig\Node\Expression\CallExpression + +use Twig\Node\Expression\CallExpression; +use Twig\TwigFilter; +use Twig\Compiler; +use Twig\Node\Expression\ConstantExpression; +class Twig_Node_Expression_Filter extends CallExpression { - public function __construct(Twig_NodeInterface $node, \Twig\Node\Expression\ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) + public function __construct(Twig_NodeInterface $node, ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) { parent::__construct(['node' => $node, 'filter' => $filterName, 'arguments' => $arguments], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $name = $this->getNode('filter')->getAttribute('value'); $filter = $compiler->getEnvironment()->getFilter($name); @@ -27,10 +32,10 @@ class Twig_Node_Expression_Filter extends \Twig\Node\Expression\CallExpression $this->setAttribute('needs_environment', $filter->needsEnvironment()); $this->setAttribute('needs_context', $filter->needsContext()); $this->setAttribute('arguments', $filter->getArguments()); - if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof \Twig\TwigFilter) { + if ($filter instanceof Twig_FilterCallableInterface || $filter instanceof TwigFilter) { $this->setAttribute('callable', $filter->getCallable()); } - if ($filter instanceof \Twig\TwigFilter) { + if ($filter instanceof TwigFilter) { $this->setAttribute('is_variadic', $filter->isVariadic()); } diff --git a/lib/Twig/Node/Expression/Filter/Default.php b/lib/Twig/Node/Expression/Filter/Default.php index ebc7d6bb0..0ee12f660 100644 --- a/lib/Twig/Node/Expression/Filter/Default.php +++ b/lib/Twig/Node/Expression/Filter/Default.php @@ -9,6 +9,15 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\Test\DefinedTest; +use Twig\Node\Node; +use Twig\Node\Expression\ConditionalExpression; +use Twig\Compiler; + /** * Returns the value or the default value when it is undefined or empty. * @@ -16,17 +25,17 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Filter_Default extends \Twig\Node\Expression\FilterExpression +class Twig_Node_Expression_Filter_Default extends FilterExpression { - public function __construct(Twig_NodeInterface $node, \Twig\Node\Expression\ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) + public function __construct(Twig_NodeInterface $node, ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) { - $default = new \Twig\Node\Expression\FilterExpression($node, new \Twig\Node\Expression\ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); + $default = new FilterExpression($node, new ConstantExpression('default', $node->getTemplateLine()), $arguments, $node->getTemplateLine()); - if ('default' === $filterName->getAttribute('value') && ($node instanceof \Twig\Node\Expression\NameExpression || $node instanceof \Twig\Node\Expression\GetAttrExpression)) { - $test = new \Twig\Node\Expression\Test\DefinedTest(clone $node, 'defined', new \Twig\Node\Node(), $node->getTemplateLine()); - $false = \count($arguments) ? $arguments->getNode(0) : new \Twig\Node\Expression\ConstantExpression('', $node->getTemplateLine()); + if ('default' === $filterName->getAttribute('value') && ($node instanceof NameExpression || $node instanceof GetAttrExpression)) { + $test = new DefinedTest(clone $node, 'defined', new Node(), $node->getTemplateLine()); + $false = \count($arguments) ? $arguments->getNode(0) : new ConstantExpression('', $node->getTemplateLine()); - $node = new \Twig\Node\Expression\ConditionalExpression($test, $default, $false, $node->getTemplateLine()); + $node = new ConditionalExpression($test, $default, $false, $node->getTemplateLine()); } else { $node = $default; } @@ -34,7 +43,7 @@ class Twig_Node_Expression_Filter_Default extends \Twig\Node\Expression\FilterEx parent::__construct($node, $filterName, $arguments, $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->subcompile($this->getNode('node')); } diff --git a/lib/Twig/Node/Expression/Function.php b/lib/Twig/Node/Expression/Function.php index e73c51ae1..a8fa8f183 100644 --- a/lib/Twig/Node/Expression/Function.php +++ b/lib/Twig/Node/Expression/Function.php @@ -8,14 +8,18 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Function extends \Twig\Node\Expression\CallExpression + +use Twig\Node\Expression\CallExpression; +use Twig\TwigFunction; +use Twig\Compiler; +class Twig_Node_Expression_Function extends CallExpression { public function __construct($name, Twig_NodeInterface $arguments, $lineno) { parent::__construct(['arguments' => $arguments], ['name' => $name, 'is_defined_test' => false], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $name = $this->getAttribute('name'); $function = $compiler->getEnvironment()->getFunction($name); @@ -26,7 +30,7 @@ class Twig_Node_Expression_Function extends \Twig\Node\Expression\CallExpression $this->setAttribute('needs_environment', $function->needsEnvironment()); $this->setAttribute('needs_context', $function->needsContext()); $this->setAttribute('arguments', $function->getArguments()); - if ($function instanceof Twig_FunctionCallableInterface || $function instanceof \Twig\TwigFunction) { + if ($function instanceof Twig_FunctionCallableInterface || $function instanceof TwigFunction) { $callable = $function->getCallable(); if ('constant' === $name && $this->getAttribute('is_defined_test')) { $callable = 'twig_constant_is_defined'; @@ -34,7 +38,7 @@ class Twig_Node_Expression_Function extends \Twig\Node\Expression\CallExpression $this->setAttribute('callable', $callable); } - if ($function instanceof \Twig\TwigFunction) { + if ($function instanceof TwigFunction) { $this->setAttribute('is_variadic', $function->isVariadic()); } diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index 7da9f032d..2fd4ec748 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -9,9 +9,13 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_GetAttr extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Template; +use Twig\Compiler; +class Twig_Node_Expression_GetAttr extends AbstractExpression { - public function __construct(\Twig\Node\Expression\AbstractExpression $node, \Twig\Node\Expression\AbstractExpression $attribute, \Twig\Node\Expression\AbstractExpression $arguments = null, $type, $lineno) + public function __construct(AbstractExpression $node, AbstractExpression $attribute, AbstractExpression $arguments = null, $type, $lineno) { $nodes = ['node' => $node, 'attribute' => $attribute]; if (null !== $arguments) { @@ -21,7 +25,7 @@ class Twig_Node_Expression_GetAttr extends \Twig\Node\Expression\AbstractExpress parent::__construct($nodes, ['type' => $type, 'is_defined_test' => false, 'ignore_strict_check' => false, 'disable_c_ext' => false], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { if ($this->getAttribute('disable_c_ext')) { @trigger_error(sprintf('Using the "disable_c_ext" attribute on %s is deprecated since version 1.30 and will be removed in 2.0.', __CLASS__), E_USER_DEPRECATED); @@ -44,7 +48,7 @@ class Twig_Node_Expression_GetAttr extends \Twig\Node\Expression\AbstractExpress // only generate optional arguments when needed (to make generated code more readable) $needFourth = $this->getAttribute('ignore_strict_check'); $needThird = $needFourth || $this->getAttribute('is_defined_test'); - $needSecond = $needThird || \Twig\Template::ANY_CALL !== $this->getAttribute('type'); + $needSecond = $needThird || Template::ANY_CALL !== $this->getAttribute('type'); $needFirst = $needSecond || $this->hasNode('arguments'); if ($needFirst) { diff --git a/lib/Twig/Node/Expression/MethodCall.php b/lib/Twig/Node/Expression/MethodCall.php index 9048fff29..2b0222618 100644 --- a/lib/Twig/Node/Expression/MethodCall.php +++ b/lib/Twig/Node/Expression/MethodCall.php @@ -8,18 +8,23 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_MethodCall extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Compiler; +use Twig\Node\Expression\ArrayExpression; +class Twig_Node_Expression_MethodCall extends AbstractExpression { - public function __construct(\Twig\Node\Expression\AbstractExpression $node, $method, \Twig\Node\Expression\ArrayExpression $arguments, $lineno) + public function __construct(AbstractExpression $node, $method, ArrayExpression $arguments, $lineno) { parent::__construct(['node' => $node, 'arguments' => $arguments], ['method' => $method, 'safe' => false], $lineno); - if ($node instanceof \Twig\Node\Expression\NameExpression) { + if ($node instanceof NameExpression) { $node->setAttribute('always_defined', true); } } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->subcompile($this->getNode('node')) diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index c6ef9936e..0138b0af3 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -9,7 +9,10 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Name extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +class Twig_Node_Expression_Name extends AbstractExpression { protected $specialVars = [ '_self' => '$this', @@ -22,7 +25,7 @@ class Twig_Node_Expression_Name extends \Twig\Node\Expression\AbstractExpression parent::__construct([], ['name' => $name, 'is_defined_test' => false, 'ignore_strict_check' => false, 'always_defined' => false], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $name = $this->getAttribute('name'); diff --git a/lib/Twig/Node/Expression/NullCoalesce.php b/lib/Twig/Node/Expression/NullCoalesce.php index 5d022154c..583976683 100644 --- a/lib/Twig/Node/Expression/NullCoalesce.php +++ b/lib/Twig/Node/Expression/NullCoalesce.php @@ -8,20 +8,29 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_NullCoalesce extends \Twig\Node\Expression\ConditionalExpression + +use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\Binary\AndBinary; +use Twig\Node\Expression\Test\DefinedTest; +use Twig\Node\Node; +use Twig\Node\Expression\Unary\NotUnary; +use Twig\Node\Expression\Test\NullTest; +use Twig\Node\Expression\NameExpression; +use Twig\Compiler; +class Twig_Node_Expression_NullCoalesce extends ConditionalExpression { public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) { - $test = new \Twig\Node\Expression\Binary\AndBinary( - new \Twig\Node\Expression\Test\DefinedTest(clone $left, 'defined', new \Twig\Node\Node(), $left->getTemplateLine()), - new \Twig\Node\Expression\Unary\NotUnary(new \Twig\Node\Expression\Test\NullTest($left, 'null', new \Twig\Node\Node(), $left->getTemplateLine()), $left->getTemplateLine()), + $test = new AndBinary( + new DefinedTest(clone $left, 'defined', new Node(), $left->getTemplateLine()), + new NotUnary(new NullTest($left, 'null', new Node(), $left->getTemplateLine()), $left->getTemplateLine()), $left->getTemplateLine() ); parent::__construct($test, $left, $right, $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { /* * This optimizes only one case. PHP 7 also supports more complex expressions @@ -30,7 +39,7 @@ class Twig_Node_Expression_NullCoalesce extends \Twig\Node\Expression\Conditiona * cases might be implemented as an optimizer node visitor, but has not been done * as benefits are probably not worth the added complexity. */ - if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof \Twig\Node\Expression\NameExpression) { + if (PHP_VERSION_ID >= 70000 && $this->getNode('expr2') instanceof NameExpression) { $this->getNode('expr2')->setAttribute('always_defined', true); $compiler ->raw('((') diff --git a/lib/Twig/Node/Expression/Parent.php b/lib/Twig/Node/Expression/Parent.php index 59d857792..c5f77d640 100644 --- a/lib/Twig/Node/Expression/Parent.php +++ b/lib/Twig/Node/Expression/Parent.php @@ -10,19 +10,22 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; + /** * Represents a parent node. * * @author Fabien Potencier */ -class Twig_Node_Expression_Parent extends \Twig\Node\Expression\AbstractExpression +class Twig_Node_Expression_Parent extends AbstractExpression { public function __construct($name, $lineno, $tag = null) { parent::__construct([], ['output' => false, 'name' => $name], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { if ($this->getAttribute('output')) { $compiler diff --git a/lib/Twig/Node/Expression/TempName.php b/lib/Twig/Node/Expression/TempName.php index 1184eaae1..9565d34e1 100644 --- a/lib/Twig/Node/Expression/TempName.php +++ b/lib/Twig/Node/Expression/TempName.php @@ -8,14 +8,17 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_TempName extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +class Twig_Node_Expression_TempName extends AbstractExpression { public function __construct($name, $lineno) { parent::__construct([], ['name' => $name], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('$_') diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index 04bc83125..b60b45c48 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -8,7 +8,11 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Test extends \Twig\Node\Expression\CallExpression + +use Twig\Node\Expression\CallExpression; +use Twig\TwigTest; +use Twig\Compiler; +class Twig_Node_Expression_Test extends CallExpression { public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) { @@ -20,7 +24,7 @@ class Twig_Node_Expression_Test extends \Twig\Node\Expression\CallExpression parent::__construct($nodes, ['name' => $name], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $name = $this->getAttribute('name'); $test = $compiler->getEnvironment()->getTest($name); @@ -28,13 +32,13 @@ class Twig_Node_Expression_Test extends \Twig\Node\Expression\CallExpression $this->setAttribute('name', $name); $this->setAttribute('type', 'test'); $this->setAttribute('thing', $test); - if ($test instanceof \Twig\TwigTest) { + if ($test instanceof TwigTest) { $this->setAttribute('arguments', $test->getArguments()); } - if ($test instanceof Twig_TestCallableInterface || $test instanceof \Twig\TwigTest) { + if ($test instanceof Twig_TestCallableInterface || $test instanceof TwigTest) { $this->setAttribute('callable', $test->getCallable()); } - if ($test instanceof \Twig\TwigTest) { + if ($test instanceof TwigTest) { $this->setAttribute('is_variadic', $test->isVariadic()); } diff --git a/lib/Twig/Node/Expression/Test/Constant.php b/lib/Twig/Node/Expression/Test/Constant.php index 12b9b2747..aee1da123 100644 --- a/lib/Twig/Node/Expression/Test/Constant.php +++ b/lib/Twig/Node/Expression/Test/Constant.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Compiler; + /** * Checks if a variable is the exact same value as a constant. * @@ -18,9 +21,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Constant extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Constant extends TestExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Test/Defined.php b/lib/Twig/Node/Expression/Test/Defined.php index f9056ec38..6e505243f 100644 --- a/lib/Twig/Node/Expression/Test/Defined.php +++ b/lib/Twig/Node/Expression/Test/Defined.php @@ -9,6 +9,16 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\FunctionExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Error\SyntaxError; +use Twig\Compiler; + /** * Checks if a variable is defined in the current context. * @@ -19,38 +29,38 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Defined extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Defined extends TestExpression { public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) { - if ($node instanceof \Twig\Node\Expression\NameExpression) { + if ($node instanceof NameExpression) { $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof \Twig\Node\Expression\GetAttrExpression) { + } elseif ($node instanceof GetAttrExpression) { $node->setAttribute('is_defined_test', true); $this->changeIgnoreStrictCheck($node); - } elseif ($node instanceof \Twig\Node\Expression\BlockReferenceExpression) { + } elseif ($node instanceof BlockReferenceExpression) { $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof \Twig\Node\Expression\FunctionExpression && 'constant' === $node->getAttribute('name')) { + } elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) { $node->setAttribute('is_defined_test', true); - } elseif ($node instanceof \Twig\Node\Expression\ConstantExpression || $node instanceof \Twig\Node\Expression\ArrayExpression) { - $node = new \Twig\Node\Expression\ConstantExpression(true, $node->getTemplateLine()); + } elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) { + $node = new ConstantExpression(true, $node->getTemplateLine()); } else { - throw new \Twig\Error\SyntaxError('The "defined" test only works with simple variables.', $this->getTemplateLine()); + throw new SyntaxError('The "defined" test only works with simple variables.', $this->getTemplateLine()); } parent::__construct($node, $name, $arguments, $lineno); } - protected function changeIgnoreStrictCheck(\Twig\Node\Expression\GetAttrExpression $node) + protected function changeIgnoreStrictCheck(GetAttrExpression $node) { $node->setAttribute('ignore_strict_check', true); - if ($node->getNode('node') instanceof \Twig\Node\Expression\GetAttrExpression) { + if ($node->getNode('node') instanceof GetAttrExpression) { $this->changeIgnoreStrictCheck($node->getNode('node')); } } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->subcompile($this->getNode('node')); } diff --git a/lib/Twig/Node/Expression/Test/Divisibleby.php b/lib/Twig/Node/Expression/Test/Divisibleby.php index 02b4999e1..2c901f0df 100644 --- a/lib/Twig/Node/Expression/Test/Divisibleby.php +++ b/lib/Twig/Node/Expression/Test/Divisibleby.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Compiler; + /** * Checks if a variable is divisible by a number. * @@ -16,9 +19,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Divisibleby extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Divisibleby extends TestExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(0 == ') diff --git a/lib/Twig/Node/Expression/Test/Even.php b/lib/Twig/Node/Expression/Test/Even.php index b059b18de..e40578396 100644 --- a/lib/Twig/Node/Expression/Test/Even.php +++ b/lib/Twig/Node/Expression/Test/Even.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Compiler; + /** * Checks if a number is even. * @@ -16,9 +19,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Even extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Even extends TestExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Test/Null.php b/lib/Twig/Node/Expression/Test/Null.php index a5bf54763..0be47dc6d 100644 --- a/lib/Twig/Node/Expression/Test/Null.php +++ b/lib/Twig/Node/Expression/Test/Null.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Compiler; + /** * Checks that a variable is null. * @@ -16,9 +19,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Null extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Null extends TestExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(null === ') diff --git a/lib/Twig/Node/Expression/Test/Odd.php b/lib/Twig/Node/Expression/Test/Odd.php index 2752a4125..55e6e4d05 100644 --- a/lib/Twig/Node/Expression/Test/Odd.php +++ b/lib/Twig/Node/Expression/Test/Odd.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Compiler; + /** * Checks if a number is odd. * @@ -16,9 +19,9 @@ * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Odd extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Odd extends TestExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Test/Sameas.php b/lib/Twig/Node/Expression/Test/Sameas.php index b8cbaad11..5cd339ccd 100644 --- a/lib/Twig/Node/Expression/Test/Sameas.php +++ b/lib/Twig/Node/Expression/Test/Sameas.php @@ -9,14 +9,17 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\TestExpression; +use Twig\Compiler; + /** * Checks if a variable is the same as another one (=== in PHP). * * @author Fabien Potencier */ -class Twig_Node_Expression_Test_Sameas extends \Twig\Node\Expression\TestExpression +class Twig_Node_Expression_Test_Sameas extends TestExpression { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->raw('(') diff --git a/lib/Twig/Node/Expression/Unary.php b/lib/Twig/Node/Expression/Unary.php index 88575e23c..8fff798f8 100644 --- a/lib/Twig/Node/Expression/Unary.php +++ b/lib/Twig/Node/Expression/Unary.php @@ -9,21 +9,24 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -abstract class Twig_Node_Expression_Unary extends \Twig\Node\Expression\AbstractExpression + +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +abstract class Twig_Node_Expression_Unary extends AbstractExpression { public function __construct(Twig_NodeInterface $node, $lineno) { parent::__construct(['node' => $node], [], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->raw(' '); $this->operator($compiler); $compiler->subcompile($this->getNode('node')); } - abstract public function operator(\Twig\Compiler $compiler); + abstract public function operator(Compiler $compiler); } class_alias('Twig_Node_Expression_Unary', 'Twig\Node\Expression\Unary\AbstractUnary', false); diff --git a/lib/Twig/Node/Expression/Unary/Neg.php b/lib/Twig/Node/Expression/Unary/Neg.php index 92a36c06a..fa7b4f4b2 100644 --- a/lib/Twig/Node/Expression/Unary/Neg.php +++ b/lib/Twig/Node/Expression/Unary/Neg.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Unary_Neg extends \Twig\Node\Expression\Unary\AbstractUnary + +use Twig\Node\Expression\Unary\AbstractUnary; +use Twig\Compiler; +class Twig_Node_Expression_Unary_Neg extends AbstractUnary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { $compiler->raw('-'); } diff --git a/lib/Twig/Node/Expression/Unary/Not.php b/lib/Twig/Node/Expression/Unary/Not.php index ec6269615..8004c842a 100644 --- a/lib/Twig/Node/Expression/Unary/Not.php +++ b/lib/Twig/Node/Expression/Unary/Not.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Unary_Not extends \Twig\Node\Expression\Unary\AbstractUnary + +use Twig\Node\Expression\Unary\AbstractUnary; +use Twig\Compiler; +class Twig_Node_Expression_Unary_Not extends AbstractUnary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { $compiler->raw('!'); } diff --git a/lib/Twig/Node/Expression/Unary/Pos.php b/lib/Twig/Node/Expression/Unary/Pos.php index 2d5267d3d..6624925dc 100644 --- a/lib/Twig/Node/Expression/Unary/Pos.php +++ b/lib/Twig/Node/Expression/Unary/Pos.php @@ -9,9 +9,12 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ -class Twig_Node_Expression_Unary_Pos extends \Twig\Node\Expression\Unary\AbstractUnary + +use Twig\Node\Expression\Unary\AbstractUnary; +use Twig\Compiler; +class Twig_Node_Expression_Unary_Pos extends AbstractUnary { - public function operator(\Twig\Compiler $compiler) + public function operator(Compiler $compiler) { $compiler->raw('+'); } diff --git a/lib/Twig/Node/Flush.php b/lib/Twig/Node/Flush.php index a05f805c6..2d680f3b0 100644 --- a/lib/Twig/Node/Flush.php +++ b/lib/Twig/Node/Flush.php @@ -9,19 +9,22 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a flush node. * * @author Fabien Potencier */ -class Twig_Node_Flush extends \Twig\Node\Node +class Twig_Node_Flush extends Node { public function __construct($lineno, $tag) { parent::__construct([], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index 5978e0140..111eeddf1 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -10,21 +10,28 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\ForLoopNode; +use Twig\Node\IfNode; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + /** * Represents a for node. * * @author Fabien Potencier */ -class Twig_Node_For extends \Twig\Node\Node +class Twig_Node_For extends Node { protected $loop; - public function __construct(\Twig\Node\Expression\AssignNameExpression $keyTarget, \Twig\Node\Expression\AssignNameExpression $valueTarget, \Twig\Node\Expression\AbstractExpression $seq, \Twig\Node\Expression\AbstractExpression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null) + public function __construct(AssignNameExpression $keyTarget, AssignNameExpression $valueTarget, AbstractExpression $seq, AbstractExpression $ifexpr = null, Twig_NodeInterface $body, Twig_NodeInterface $else = null, $lineno, $tag = null) { - $body = new \Twig\Node\Node([$body, $this->loop = new \Twig\Node\ForLoopNode($lineno, $tag)]); + $body = new Node([$body, $this->loop = new ForLoopNode($lineno, $tag)]); if (null !== $ifexpr) { - $body = new \Twig\Node\IfNode(new \Twig\Node\Node([$ifexpr, $body]), null, $lineno, $tag); + $body = new IfNode(new Node([$ifexpr, $body]), null, $lineno, $tag); } $nodes = ['key_target' => $keyTarget, 'value_target' => $valueTarget, 'seq' => $seq, 'body' => $body]; @@ -35,7 +42,7 @@ class Twig_Node_For extends \Twig\Node\Node parent::__construct($nodes, ['with_loop' => true, 'ifexpr' => null !== $ifexpr], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/ForLoop.php b/lib/Twig/Node/ForLoop.php index d5bb816b9..b67cb54c6 100644 --- a/lib/Twig/Node/ForLoop.php +++ b/lib/Twig/Node/ForLoop.php @@ -9,19 +9,22 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Internal node used by the for node. * * @author Fabien Potencier */ -class Twig_Node_ForLoop extends \Twig\Node\Node +class Twig_Node_ForLoop extends Node { public function __construct($lineno, $tag = null) { parent::__construct([], ['with_loop' => false, 'ifexpr' => false, 'else' => false], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { if ($this->getAttribute('else')) { $compiler->write("\$context['_iterated'] = true;\n"); diff --git a/lib/Twig/Node/If.php b/lib/Twig/Node/If.php index 6bdc9e8f3..6bb8fc6df 100644 --- a/lib/Twig/Node/If.php +++ b/lib/Twig/Node/If.php @@ -10,12 +10,15 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents an if node. * * @author Fabien Potencier */ -class Twig_Node_If extends \Twig\Node\Node +class Twig_Node_If extends Node { public function __construct(Twig_NodeInterface $tests, Twig_NodeInterface $else = null, $lineno, $tag = null) { @@ -27,7 +30,7 @@ class Twig_Node_If extends \Twig\Node\Node parent::__construct($nodes, [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) { diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php index 1317e3074..4fae3314b 100644 --- a/lib/Twig/Node/Import.php +++ b/lib/Twig/Node/Import.php @@ -9,19 +9,24 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; + /** * Represents an import node. * * @author Fabien Potencier */ -class Twig_Node_Import extends \Twig\Node\Node +class Twig_Node_Import extends Node { - public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \Twig\Node\Expression\AbstractExpression $var, $lineno, $tag = null) + public function __construct(AbstractExpression $expr, AbstractExpression $var, $lineno, $tag = null) { parent::__construct(['expr' => $expr, 'var' => $var], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -30,7 +35,7 @@ class Twig_Node_Import extends \Twig\Node\Node ->raw(' = ') ; - if ($this->getNode('expr') instanceof \Twig\Node\Expression\NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) { + if ($this->getNode('expr') instanceof NameExpression && '_self' === $this->getNode('expr')->getAttribute('name')) { $compiler->raw('$this'); } else { $compiler diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index f3bef8a0d..0ed783750 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -10,14 +10,20 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\NodeOutputInterface; +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; +use Twig\Error\LoaderError; + /** * Represents an include node. * * @author Fabien Potencier */ -class Twig_Node_Include extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface +class Twig_Node_Include extends Node implements NodeOutputInterface { - public function __construct(\Twig\Node\Expression\AbstractExpression $expr, \Twig\Node\Expression\AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) + public function __construct(AbstractExpression $expr, AbstractExpression $variables = null, $only = false, $ignoreMissing = false, $lineno, $tag = null) { $nodes = ['expr' => $expr]; if (null !== $variables) { @@ -27,7 +33,7 @@ class Twig_Node_Include extends \Twig\Node\Node implements \Twig\Node\NodeOutput parent::__construct($nodes, ['only' => (bool) $only, 'ignore_missing' => (bool) $ignoreMissing], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); @@ -49,7 +55,7 @@ class Twig_Node_Include extends \Twig\Node\Node implements \Twig\Node\NodeOutput if ($this->getAttribute('ignore_missing')) { $compiler ->outdent() - ->write("} catch (\Twig\Error\LoaderError \$e) {\n") + ->write("} catch (LoaderError \$e) {\n") ->indent() ->write("// ignore missing template\n") ->outdent() @@ -58,7 +64,7 @@ class Twig_Node_Include extends \Twig\Node\Node implements \Twig\Node\NodeOutput } } - protected function addGetTemplate(\Twig\Compiler $compiler) + protected function addGetTemplate(Compiler $compiler) { $compiler ->write('$this->loadTemplate(') @@ -71,7 +77,7 @@ class Twig_Node_Include extends \Twig\Node\Node implements \Twig\Node\NodeOutput ; } - protected function addTemplateArguments(\Twig\Compiler $compiler) + protected function addTemplateArguments(Compiler $compiler) { if (!$this->hasNode('variables')) { $compiler->raw(false === $this->getAttribute('only') ? '$context' : '[]'); diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 68ba03d35..248cd75d5 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -9,12 +9,17 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Error\SyntaxError; +use Twig\Markup; +use Twig\Compiler; + /** * Represents a macro node. * * @author Fabien Potencier */ -class Twig_Node_Macro extends \Twig\Node\Node +class Twig_Node_Macro extends Node { const VARARGS_NAME = 'varargs'; @@ -22,14 +27,14 @@ class Twig_Node_Macro extends \Twig\Node\Node { foreach ($arguments as $argumentName => $argument) { if (self::VARARGS_NAME === $argumentName) { - throw new \Twig\Error\SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine()); + throw new SyntaxError(sprintf('The argument "%s" in macro "%s" cannot be defined because the variable "%s" is reserved for arbitrary arguments.', self::VARARGS_NAME, $name, self::VARARGS_NAME), $argument->getTemplateLine()); } } parent::__construct(['body' => $body, 'arguments' => $arguments], ['name' => $name], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -115,7 +120,7 @@ class Twig_Node_Macro extends \Twig\Node\Node ->write("throw \$e;\n") ->outdent() ->write("}\n\n") - ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset());\n") + ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset());\n") ->outdent() ->write("}\n\n") ; diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 38ca4c04a..d131ae67a 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -10,6 +10,17 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Source; +use Twig\Node\Expression\ConstantExpression; +use Twig\Error\RuntimeError; +use Twig\Node\BodyNode; +use Twig\Node\TextNode; +use Twig\Node\BlockReferenceNode; +use Twig\Compiler; +use Twig\Environment; +use Twig\Node\Expression\AbstractExpression; + /** * Represents a module node. * @@ -19,15 +30,15 @@ * * @author Fabien Potencier */ -class Twig_Node_Module extends \Twig\Node\Node +class Twig_Node_Module extends Node { private $source; - public function __construct(Twig_NodeInterface $body, \Twig\Node\Expression\AbstractExpression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') + public function __construct(Twig_NodeInterface $body, AbstractExpression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $name, $source = '') { - if (!$name instanceof \Twig\Source) { + if (!$name instanceof Source) { @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); - $this->source = new \Twig\Source($source, $name); + $this->source = new Source($source, $name); } else { $this->source = $name; } @@ -37,11 +48,11 @@ class Twig_Node_Module extends \Twig\Node\Node 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits, - 'display_start' => new \Twig\Node\Node(), - 'display_end' => new \Twig\Node\Node(), - 'constructor_start' => new \Twig\Node\Node(), - 'constructor_end' => new \Twig\Node\Node(), - 'class_end' => new \Twig\Node\Node(), + 'display_start' => new Node(), + 'display_end' => new Node(), + 'constructor_start' => new Node(), + 'constructor_end' => new Node(), + 'class_end' => new Node(), ]; if (null !== $parent) { $nodes['parent'] = $parent; @@ -66,7 +77,7 @@ class Twig_Node_Module extends \Twig\Node\Node $this->setAttribute('index', $index); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $this->compileTemplate($compiler); @@ -75,7 +86,7 @@ class Twig_Node_Module extends \Twig\Node\Node } } - protected function compileTemplate(\Twig\Compiler $compiler) + protected function compileTemplate(Compiler $compiler) { if (!$this->getAttribute('index')) { $compiler->write('getNode('blocks')) || \count($this->getNode('traits')) || !$this->hasNode('parent') - || $this->getNode('parent') instanceof \Twig\Node\Expression\ConstantExpression + || $this->getNode('parent') instanceof ConstantExpression || \count($this->getNode('constructor_start')) || \count($this->getNode('constructor_end')) ) { @@ -115,7 +126,7 @@ class Twig_Node_Module extends \Twig\Node\Node $this->compileClassFooter($compiler); } - protected function compileGetParent(\Twig\Compiler $compiler) + protected function compileGetParent(Compiler $compiler) { if (!$this->hasNode('parent')) { return; @@ -129,7 +140,7 @@ class Twig_Node_Module extends \Twig\Node\Node ->write('return ') ; - if ($parent instanceof \Twig\Node\Expression\ConstantExpression) { + if ($parent instanceof ConstantExpression) { $compiler->subcompile($parent); } else { $compiler @@ -150,7 +161,7 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileClassHeader(\Twig\Compiler $compiler) + protected function compileClassHeader(Compiler $compiler) { $compiler ->write("\n\n") @@ -179,10 +190,10 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileConstructor(\Twig\Compiler $compiler) + protected function compileConstructor(Compiler $compiler) { $compiler - ->write("public function __construct(\Twig\Environment \$env)\n", "{\n") + ->write("public function __construct(Environment \$env)\n", "{\n") ->indent() ->subcompile($this->getNode('constructor_start')) ->write("parent::__construct(\$env);\n\n") @@ -191,7 +202,7 @@ class Twig_Node_Module extends \Twig\Node\Node // parent if (!$this->hasNode('parent')) { $compiler->write("\$this->parent = false;\n\n"); - } elseif (($parent = $this->getNode('parent')) && $parent instanceof \Twig\Node\Expression\ConstantExpression) { + } elseif (($parent = $this->getNode('parent')) && $parent instanceof ConstantExpression) { $compiler ->addDebugInfo($parent) ->write('$this->parent = $this->loadTemplate(') @@ -214,7 +225,7 @@ class Twig_Node_Module extends \Twig\Node\Node ->addDebugInfo($trait->getNode('template')) ->write(sprintf("if (!\$_trait_%s->isTraitable()) {\n", $i)) ->indent() - ->write("throw new \Twig\Error\RuntimeError('Template \"'.") + ->write("throw new RuntimeError('Template \"'.") ->subcompile($trait->getNode('template')) ->raw(".'\" cannot be used as a trait.');\n") ->outdent() @@ -228,7 +239,7 @@ class Twig_Node_Module extends \Twig\Node\Node ->string($key) ->raw("])) {\n") ->indent() - ->write("throw new \Twig\Error\RuntimeError(sprintf('Block ") + ->write("throw new RuntimeError(sprintf('Block ") ->string($key) ->raw(' is not defined in trait ') ->subcompile($trait->getNode('template')) @@ -313,7 +324,7 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileDisplay(\Twig\Compiler $compiler) + protected function compileDisplay(Compiler $compiler) { $compiler ->write("protected function doDisplay(array \$context, array \$blocks = [])\n", "{\n") @@ -325,7 +336,7 @@ class Twig_Node_Module extends \Twig\Node\Node if ($this->hasNode('parent')) { $parent = $this->getNode('parent'); $compiler->addDebugInfo($parent); - if ($parent instanceof \Twig\Node\Expression\ConstantExpression) { + if ($parent instanceof ConstantExpression) { $compiler->write('$this->parent'); } else { $compiler->write('$this->getParent($context)'); @@ -340,7 +351,7 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileClassFooter(\Twig\Compiler $compiler) + protected function compileClassFooter(Compiler $compiler) { $compiler ->subcompile($this->getNode('class_end')) @@ -349,12 +360,12 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileMacros(\Twig\Compiler $compiler) + protected function compileMacros(Compiler $compiler) { $compiler->subcompile($this->getNode('macros')); } - protected function compileGetTemplateName(\Twig\Compiler $compiler) + protected function compileGetTemplateName(Compiler $compiler) { $compiler ->write("public function getTemplateName()\n", "{\n") @@ -367,7 +378,7 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileIsTraitable(\Twig\Compiler $compiler) + protected function compileIsTraitable(Compiler $compiler) { // A template can be used as a trait if: // * it has no parent @@ -378,14 +389,14 @@ class Twig_Node_Module extends \Twig\Node\Node // only contains blocks and use statements. $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros')); if ($traitable) { - if ($this->getNode('body') instanceof \Twig\Node\BodyNode) { + if ($this->getNode('body') instanceof BodyNode) { $nodes = $this->getNode('body')->getNode(0); } else { $nodes = $this->getNode('body'); } if (!\count($nodes)) { - $nodes = new \Twig\Node\Node([$nodes]); + $nodes = new Node([$nodes]); } foreach ($nodes as $node) { @@ -393,11 +404,11 @@ class Twig_Node_Module extends \Twig\Node\Node continue; } - if ($node instanceof \Twig\Node\TextNode && ctype_space($node->getAttribute('data'))) { + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { continue; } - if ($node instanceof \Twig\Node\BlockReferenceNode) { + if ($node instanceof BlockReferenceNode) { continue; } @@ -419,7 +430,7 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileDebugInfo(\Twig\Compiler $compiler) + protected function compileDebugInfo(Compiler $compiler) { $compiler ->write("public function getDebugInfo()\n", "{\n") @@ -430,7 +441,7 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileGetSource(\Twig\Compiler $compiler) + protected function compileGetSource(Compiler $compiler) { $compiler ->write("/** @deprecated since 1.27 (to be removed in 2.0). Use getSourceContext() instead */\n") @@ -444,12 +455,12 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileGetSourceContext(\Twig\Compiler $compiler) + protected function compileGetSourceContext(Compiler $compiler) { $compiler ->write("public function getSourceContext()\n", "{\n") ->indent() - ->write('return new \Twig\Source(') + ->write('return new Source(') ->string($compiler->getEnvironment()->isDebug() ? $this->source->getCode() : '') ->raw(', ') ->string($this->source->getName()) @@ -461,9 +472,9 @@ class Twig_Node_Module extends \Twig\Node\Node ; } - protected function compileLoadTemplate(\Twig\Compiler $compiler, $node, $var) + protected function compileLoadTemplate(Compiler $compiler, $node, $var) { - if ($node instanceof \Twig\Node\Expression\ConstantExpression) { + if ($node instanceof ConstantExpression) { $compiler ->write(sprintf('%s = $this->loadTemplate(', $var)) ->subcompile($node) diff --git a/lib/Twig/Node/Print.php b/lib/Twig/Node/Print.php index 4ad9bb33b..7c326603f 100644 --- a/lib/Twig/Node/Print.php +++ b/lib/Twig/Node/Print.php @@ -10,19 +10,24 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\NodeOutputInterface; +use Twig\Node\Expression\AbstractExpression; +use Twig\Compiler; + /** * Represents a node that outputs an expression. * * @author Fabien Potencier */ -class Twig_Node_Print extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface +class Twig_Node_Print extends Node implements NodeOutputInterface { - public function __construct(\Twig\Node\Expression\AbstractExpression $expr, $lineno, $tag = null) + public function __construct(AbstractExpression $expr, $lineno, $tag = null) { parent::__construct(['expr' => $expr], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Sandbox.php b/lib/Twig/Node/Sandbox.php index a5253889e..99c03bec4 100644 --- a/lib/Twig/Node/Sandbox.php +++ b/lib/Twig/Node/Sandbox.php @@ -9,19 +9,22 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a sandbox node. * * @author Fabien Potencier */ -class Twig_Node_Sandbox extends \Twig\Node\Node +class Twig_Node_Sandbox extends Node { public function __construct(Twig_NodeInterface $body, $lineno, $tag = null) { parent::__construct(['body' => $body], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/SandboxedPrint.php b/lib/Twig/Node/SandboxedPrint.php index 05abce6cc..0fdfd3eb1 100644 --- a/lib/Twig/Node/SandboxedPrint.php +++ b/lib/Twig/Node/SandboxedPrint.php @@ -9,6 +9,11 @@ * file that was distributed with this source code. */ +use Twig\Node\PrintNode; +use Twig\Node\Node; +use Twig\Node\Expression\FilterExpression; +use Twig\Compiler; + /** * Twig_Node_SandboxedPrint adds a check for the __toString() method * when the variable is an object and the sandbox is activated. @@ -19,9 +24,9 @@ * * @author Fabien Potencier */ -class Twig_Node_SandboxedPrint extends \Twig\Node\PrintNode +class Twig_Node_SandboxedPrint extends PrintNode { - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) @@ -36,11 +41,11 @@ class Twig_Node_SandboxedPrint extends \Twig\Node\PrintNode * * This is mostly needed when another visitor adds filters (like the escaper one). * - * @return \Twig\Node\Node + * @return Node */ - protected function removeNodeFilter(\Twig\Node\Node $node) + protected function removeNodeFilter(Node $node) { - if ($node instanceof \Twig\Node\Expression\FilterExpression) { + if ($node instanceof FilterExpression) { return $this->removeNodeFilter($node->getNode('node')); } diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index 81f412e0b..5f7fb8d96 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -9,12 +9,19 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\NodeCaptureInterface; +use Twig\Node\TextNode; +use Twig\Node\Expression\ConstantExpression; +use Twig\Markup; +use Twig\Compiler; + /** * Represents a set node. * * @author Fabien Potencier */ -class Twig_Node_Set extends \Twig\Node\Node implements \Twig\Node\NodeCaptureInterface +class Twig_Node_Set extends Node implements NodeCaptureInterface { public function __construct($capture, Twig_NodeInterface $names, Twig_NodeInterface $values, $lineno, $tag = null) { @@ -29,14 +36,14 @@ class Twig_Node_Set extends \Twig\Node\Node implements \Twig\Node\NodeCaptureInt $this->setAttribute('safe', true); $values = $this->getNode('values'); - if ($values instanceof \Twig\Node\TextNode) { - $this->setNode('values', new \Twig\Node\Expression\ConstantExpression($values->getAttribute('data'), $values->getTemplateLine())); + if ($values instanceof TextNode) { + $this->setNode('values', new ConstantExpression($values->getAttribute('data'), $values->getTemplateLine())); $this->setAttribute('capture', false); } } } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); @@ -61,7 +68,7 @@ class Twig_Node_Set extends \Twig\Node\Node implements \Twig\Node\NodeCaptureInt $compiler->subcompile($this->getNode('names'), false); if ($this->getAttribute('capture')) { - $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset())"); + $compiler->raw(" = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset())"); } } @@ -83,7 +90,7 @@ class Twig_Node_Set extends \Twig\Node\Node implements \Twig\Node\NodeCaptureInt $compiler ->raw("('' === \$tmp = ") ->subcompile($this->getNode('values')) - ->raw(") ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset())") + ->raw(") ? '' : new Markup(\$tmp, \$this->env->getCharset())") ; } else { $compiler->subcompile($this->getNode('values')); diff --git a/lib/Twig/Node/SetTemp.php b/lib/Twig/Node/SetTemp.php index abea358ec..8ce128b72 100644 --- a/lib/Twig/Node/SetTemp.php +++ b/lib/Twig/Node/SetTemp.php @@ -9,17 +9,20 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * @internal */ -class Twig_Node_SetTemp extends \Twig\Node\Node +class Twig_Node_SetTemp extends Node { public function __construct($name, $lineno) { parent::__construct([], ['name' => $name], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $name = $this->getAttribute('name'); $compiler diff --git a/lib/Twig/Node/Spaceless.php b/lib/Twig/Node/Spaceless.php index 82bbae9ff..e7e3711ba 100644 --- a/lib/Twig/Node/Spaceless.php +++ b/lib/Twig/Node/Spaceless.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a spaceless node. * @@ -16,14 +19,14 @@ * * @author Fabien Potencier */ -class Twig_Node_Spaceless extends \Twig\Node\Node +class Twig_Node_Spaceless extends Node { public function __construct(Twig_NodeInterface $body, $lineno, $tag = 'spaceless') { parent::__construct(['body' => $body], [], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/Text.php b/lib/Twig/Node/Text.php index c503bfa77..81ca31d02 100644 --- a/lib/Twig/Node/Text.php +++ b/lib/Twig/Node/Text.php @@ -10,19 +10,23 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Node\NodeOutputInterface; +use Twig\Compiler; + /** * Represents a text node. * * @author Fabien Potencier */ -class Twig_Node_Text extends \Twig\Node\Node implements \Twig\Node\NodeOutputInterface +class Twig_Node_Text extends Node implements NodeOutputInterface { public function __construct($data, $lineno) { parent::__construct([], ['data' => $data], $lineno); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->addDebugInfo($this) diff --git a/lib/Twig/Node/With.php b/lib/Twig/Node/With.php index 9a4f9403a..fde8eb66e 100644 --- a/lib/Twig/Node/With.php +++ b/lib/Twig/Node/With.php @@ -9,14 +9,18 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Error\RuntimeError; +use Twig\Compiler; + /** * Represents a nested "with" scope. * * @author Fabien Potencier */ -class Twig_Node_With extends \Twig\Node\Node +class Twig_Node_With extends Node { - public function __construct(\Twig\Node\Node $body, \Twig\Node\Node $variables = null, $only = false, $lineno, $tag = null) + public function __construct(Node $body, Node $variables = null, $only = false, $lineno, $tag = null) { $nodes = ['body' => $body]; if (null !== $variables) { @@ -26,7 +30,7 @@ class Twig_Node_With extends \Twig\Node\Node parent::__construct($nodes, ['only' => (bool) $only], $lineno, $tag); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler->addDebugInfo($this); @@ -38,7 +42,7 @@ class Twig_Node_With extends \Twig\Node\Node ->raw(";\n") ->write(sprintf("if (!is_array(\$%s)) {\n", $varsName)) ->indent() - ->write("throw new \Twig\Error\RuntimeError('Variables passed to the \"with\" tag must be a hash.');\n") + ->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.');\n") ->outdent() ->write("}\n") ; diff --git a/lib/Twig/NodeInterface.php b/lib/Twig/NodeInterface.php index b2af00549..b2b9d3295 100644 --- a/lib/Twig/NodeInterface.php +++ b/lib/Twig/NodeInterface.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Compiler; + /** * Represents a node in the AST. * @@ -21,7 +23,7 @@ interface Twig_NodeInterface extends \Countable, \IteratorAggregate /** * Compiles the node to PHP. */ - public function compile(\Twig\Compiler $compiler); + public function compile(Compiler $compiler); /** * @deprecated since 1.27 (to be removed in 2.0) diff --git a/lib/Twig/NodeTraverser.php b/lib/Twig/NodeTraverser.php index ee6cd9bc3..f7edca44a 100644 --- a/lib/Twig/NodeTraverser.php +++ b/lib/Twig/NodeTraverser.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Environment; + /** * Twig_NodeTraverser is a node traverser. * @@ -24,9 +27,9 @@ class Twig_NodeTraverser protected $visitors = []; /** - * @param \Twig\NodeVisitor\NodeVisitorInterface[] $visitors + * @param NodeVisitorInterface[] $visitors */ - public function __construct(\Twig\Environment $env, array $visitors = []) + public function __construct(Environment $env, array $visitors = []) { $this->env = $env; foreach ($visitors as $visitor) { @@ -34,7 +37,7 @@ class Twig_NodeTraverser } } - public function addVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) + public function addVisitor(NodeVisitorInterface $visitor) { if (!isset($this->visitors[$visitor->getPriority()])) { $this->visitors[$visitor->getPriority()] = []; @@ -60,7 +63,7 @@ class Twig_NodeTraverser return $node; } - protected function traverseForVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) + protected function traverseForVisitor(NodeVisitorInterface $visitor, Twig_NodeInterface $node = null) { if (null === $node) { return; diff --git a/lib/Twig/NodeVisitor/Escaper.php b/lib/Twig/NodeVisitor/Escaper.php index a57e73342..7a05d039e 100644 --- a/lib/Twig/NodeVisitor/Escaper.php +++ b/lib/Twig/NodeVisitor/Escaper.php @@ -9,6 +9,20 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\NodeVisitor\SafeAnalysisNodeVisitor; +use Twig\Node\ModuleNode; +use Twig\Node\AutoEscapeNode; +use Twig\Node\BlockNode; +use Twig\Node\ImportNode; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\PrintNode; +use Twig\Node\BlockReferenceNode; +use Twig\NodeTraverser; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\Environment; + /** * Twig_NodeVisitor_Escaper implements output escaping. * @@ -16,7 +30,7 @@ * * @author Fabien Potencier */ -class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor +class Twig_NodeVisitor_Escaper extends AbstractNodeVisitor { protected $statusStack = []; protected $blocks = []; @@ -27,50 +41,50 @@ class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor public function __construct() { - $this->safeAnalysis = new \Twig\NodeVisitor\SafeAnalysisNodeVisitor(); + $this->safeAnalysis = new SafeAnalysisNodeVisitor(); } - protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doEnterNode(Node $node, Environment $env) { - if ($node instanceof \Twig\Node\ModuleNode) { + if ($node instanceof ModuleNode) { if ($env->hasExtension('\Twig\Extension\EscaperExtension') && $defaultStrategy = $env->getExtension('\Twig\Extension\EscaperExtension')->getDefaultStrategy($node->getTemplateName())) { $this->defaultStrategy = $defaultStrategy; } $this->safeVars = []; $this->blocks = []; - } elseif ($node instanceof \Twig\Node\AutoEscapeNode) { + } elseif ($node instanceof AutoEscapeNode) { $this->statusStack[] = $node->getAttribute('value'); - } elseif ($node instanceof \Twig\Node\BlockNode) { + } elseif ($node instanceof BlockNode) { $this->statusStack[] = isset($this->blocks[$node->getAttribute('name')]) ? $this->blocks[$node->getAttribute('name')] : $this->needEscaping($env); - } elseif ($node instanceof \Twig\Node\ImportNode) { + } elseif ($node instanceof ImportNode) { $this->safeVars[] = $node->getNode('var')->getAttribute('name'); } return $node; } - protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { - if ($node instanceof \Twig\Node\ModuleNode) { + if ($node instanceof ModuleNode) { $this->defaultStrategy = false; $this->safeVars = []; $this->blocks = []; - } elseif ($node instanceof \Twig\Node\Expression\FilterExpression) { + } elseif ($node instanceof FilterExpression) { return $this->preEscapeFilterNode($node, $env); - } elseif ($node instanceof \Twig\Node\PrintNode) { + } elseif ($node instanceof PrintNode) { return $this->escapePrintNode($node, $env, $this->needEscaping($env)); } - if ($node instanceof \Twig\Node\AutoEscapeNode || $node instanceof \Twig\Node\BlockNode) { + if ($node instanceof AutoEscapeNode || $node instanceof BlockNode) { array_pop($this->statusStack); - } elseif ($node instanceof \Twig\Node\BlockReferenceNode) { + } elseif ($node instanceof BlockReferenceNode) { $this->blocks[$node->getAttribute('name')] = $this->needEscaping($env); } return $node; } - protected function escapePrintNode(\Twig\Node\PrintNode $node, \Twig\Environment $env, $type) + protected function escapePrintNode(PrintNode $node, Environment $env, $type) { if (false === $type) { return $node; @@ -90,7 +104,7 @@ class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor ); } - protected function preEscapeFilterNode(\Twig\Node\Expression\FilterExpression $filter, \Twig\Environment $env) + protected function preEscapeFilterNode(FilterExpression $filter, Environment $env) { $name = $filter->getNode('filter')->getAttribute('value'); @@ -115,7 +129,7 @@ class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor if (null === $safe) { if (null === $this->traverser) { - $this->traverser = new \Twig\NodeTraverser($env, [$this->safeAnalysis]); + $this->traverser = new NodeTraverser($env, [$this->safeAnalysis]); } $this->safeAnalysis->setSafeVars($this->safeVars); @@ -127,7 +141,7 @@ class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor return \in_array($type, $safe) || \in_array('all', $safe); } - protected function needEscaping(\Twig\Environment $env) + protected function needEscaping(Environment $env) { if (\count($this->statusStack)) { return $this->statusStack[\count($this->statusStack) - 1]; @@ -139,10 +153,10 @@ class Twig_NodeVisitor_Escaper extends \Twig\NodeVisitor\AbstractNodeVisitor protected function getEscaperFilter($type, Twig_NodeInterface $node) { $line = $node->getTemplateLine(); - $name = new \Twig\Node\Expression\ConstantExpression('escape', $line); - $args = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression((string) $type, $line), new \Twig\Node\Expression\ConstantExpression(null, $line), new \Twig\Node\Expression\ConstantExpression(true, $line)]); + $name = new ConstantExpression('escape', $line); + $args = new Node([new ConstantExpression((string) $type, $line), new ConstantExpression(null, $line), new ConstantExpression(true, $line)]); - return new \Twig\Node\Expression\FilterExpression($node, $name, $args, $line); + return new FilterExpression($node, $name, $args, $line); } public function getPriority() diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index a25ef9025..77f2a2cf7 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -9,6 +9,25 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\BodyNode; +use Twig\Node\SetTempNode; +use Twig\Node\Node; +use Twig\Node\Expression\TempNameExpression; +use Twig\Node\PrintNode; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\ParentExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\ForNode; +use Twig\Node\Expression\NameExpression; +use Twig\Node\BlockReferenceNode; +use Twig\Node\IncludeNode; +use Twig\Node\Expression\FunctionExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Environment; + /** * Twig_NodeVisitor_Optimizer tries to optimizes the AST. * @@ -21,7 +40,7 @@ * * @author Fabien Potencier */ -class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor +class Twig_NodeVisitor_Optimizer extends AbstractNodeVisitor { const OPTIMIZE_ALL = -1; const OPTIMIZE_NONE = 0; @@ -47,7 +66,7 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor $this->optimizers = $optimizers; } - protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doEnterNode(Node $node, Environment $env) { if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { $this->enterOptimizeFor($node, $env); @@ -55,14 +74,14 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) { if ($this->inABody) { - if (!$node instanceof \Twig\Node\Expression\AbstractExpression) { + if (!$node instanceof AbstractExpression) { if ('Twig_Node' !== \get_class($node)) { array_unshift($this->prependedNodes, []); } } else { $node = $this->optimizeVariables($node, $env); } - } elseif ($node instanceof \Twig\Node\BodyNode) { + } elseif ($node instanceof BodyNode) { $this->inABody = true; } } @@ -70,9 +89,9 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor return $node; } - protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { - $expression = $node instanceof \Twig\Node\Expression\AbstractExpression; + $expression = $node instanceof AbstractExpression; if (self::OPTIMIZE_FOR === (self::OPTIMIZE_FOR & $this->optimizers)) { $this->leaveOptimizeFor($node, $env); @@ -85,17 +104,17 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor $node = $this->optimizePrintNode($node, $env); if (self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('\Twig\Extension\SandboxExtension')) { - if ($node instanceof \Twig\Node\BodyNode) { + if ($node instanceof BodyNode) { $this->inABody = false; } elseif ($this->inABody) { if (!$expression && 'Twig_Node' !== \get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) { $nodes = []; foreach (array_unique($prependedNodes) as $name) { - $nodes[] = new \Twig\Node\SetTempNode($name, $node->getTemplateLine()); + $nodes[] = new SetTempNode($name, $node->getTemplateLine()); } $nodes[] = $node; - $node = new \Twig\Node\Node($nodes); + $node = new Node($nodes); } } } @@ -103,12 +122,12 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor return $node; } - protected function optimizeVariables(Twig_NodeInterface $node, \Twig\Environment $env) + protected function optimizeVariables(Twig_NodeInterface $node, Environment $env) { if ('Twig_Node_Expression_Name' === \get_class($node) && $node->isSimple()) { $this->prependedNodes[0][] = $node->getAttribute('name'); - return new \Twig\Node\Expression\TempNameExpression($node->getAttribute('name'), $node->getTemplateLine()); + return new TempNameExpression($node->getAttribute('name'), $node->getTemplateLine()); } return $node; @@ -123,16 +142,16 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor * * @return Twig_NodeInterface */ - protected function optimizePrintNode(Twig_NodeInterface $node, \Twig\Environment $env) + protected function optimizePrintNode(Twig_NodeInterface $node, Environment $env) { - if (!$node instanceof \Twig\Node\PrintNode) { + if (!$node instanceof PrintNode) { return $node; } $exprNode = $node->getNode('expr'); if ( - $exprNode instanceof \Twig\Node\Expression\BlockReferenceExpression || - $exprNode instanceof \Twig\Node\Expression\ParentExpression + $exprNode instanceof BlockReferenceExpression || + $exprNode instanceof ParentExpression ) { $exprNode->setAttribute('output', true); @@ -147,9 +166,9 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor * * @return Twig_NodeInterface */ - protected function optimizeRawFilter(Twig_NodeInterface $node, \Twig\Environment $env) + protected function optimizeRawFilter(Twig_NodeInterface $node, Environment $env) { - if ($node instanceof \Twig\Node\Expression\FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { + if ($node instanceof FilterExpression && 'raw' == $node->getNode('filter')->getAttribute('value')) { return $node->getNode('node'); } @@ -159,9 +178,9 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor /** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. */ - protected function enterOptimizeFor(Twig_NodeInterface $node, \Twig\Environment $env) + protected function enterOptimizeFor(Twig_NodeInterface $node, Environment $env) { - if ($node instanceof \Twig\Node\ForNode) { + if ($node instanceof ForNode) { // disable the loop variable by default $node->setAttribute('with_loop', false); array_unshift($this->loops, $node); @@ -175,28 +194,28 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor // when do we need to add the loop variable back? // the loop variable is referenced for the current loop - elseif ($node instanceof \Twig\Node\Expression\NameExpression && 'loop' === $node->getAttribute('name')) { + elseif ($node instanceof NameExpression && 'loop' === $node->getAttribute('name')) { $node->setAttribute('always_defined', true); $this->addLoopToCurrent(); } // optimize access to loop targets - elseif ($node instanceof \Twig\Node\Expression\NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) { + elseif ($node instanceof NameExpression && \in_array($node->getAttribute('name'), $this->loopsTargets)) { $node->setAttribute('always_defined', true); } // block reference - elseif ($node instanceof \Twig\Node\BlockReferenceNode || $node instanceof \Twig\Node\Expression\BlockReferenceExpression) { + elseif ($node instanceof BlockReferenceNode || $node instanceof BlockReferenceExpression) { $this->addLoopToCurrent(); } // include without the only attribute - elseif ($node instanceof \Twig\Node\IncludeNode && !$node->getAttribute('only')) { + elseif ($node instanceof IncludeNode && !$node->getAttribute('only')) { $this->addLoopToAll(); } // include function without the with_context=false parameter - elseif ($node instanceof \Twig\Node\Expression\FunctionExpression + elseif ($node instanceof FunctionExpression && 'include' === $node->getAttribute('name') && (!$node->getNode('arguments')->hasNode('with_context') || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') @@ -206,12 +225,12 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor } // the loop variable is referenced via an attribute - elseif ($node instanceof \Twig\Node\Expression\GetAttrExpression - && (!$node->getNode('attribute') instanceof \Twig\Node\Expression\ConstantExpression + elseif ($node instanceof GetAttrExpression + && (!$node->getNode('attribute') instanceof ConstantExpression || 'parent' === $node->getNode('attribute')->getAttribute('value') ) && (true === $this->loops[0]->getAttribute('with_loop') - || ($node->getNode('node') instanceof \Twig\Node\Expression\NameExpression + || ($node->getNode('node') instanceof NameExpression && 'loop' === $node->getNode('node')->getAttribute('name') ) ) @@ -223,9 +242,9 @@ class Twig_NodeVisitor_Optimizer extends \Twig\NodeVisitor\AbstractNodeVisitor /** * Optimizes "for" tag by removing the "loop" variable creation whenever possible. */ - protected function leaveOptimizeFor(Twig_NodeInterface $node, \Twig\Environment $env) + protected function leaveOptimizeFor(Twig_NodeInterface $node, Environment $env) { - if ($node instanceof \Twig\Node\ForNode) { + if ($node instanceof ForNode) { array_shift($this->loops); array_shift($this->loopsTargets); array_shift($this->loopsTargets); diff --git a/lib/Twig/NodeVisitor/SafeAnalysis.php b/lib/Twig/NodeVisitor/SafeAnalysis.php index 442c16f87..e0ce7c75b 100644 --- a/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -9,10 +9,23 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\ParentExpression; +use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\FunctionExpression; +use Twig\Node\Expression\MethodCallExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; +use Twig\Environment; + /** * @final */ -class Twig_NodeVisitor_SafeAnalysis extends \Twig\NodeVisitor\AbstractNodeVisitor +class Twig_NodeVisitor_SafeAnalysis extends AbstractNodeVisitor { protected $data = []; protected $safeVars = []; @@ -60,27 +73,27 @@ class Twig_NodeVisitor_SafeAnalysis extends \Twig\NodeVisitor\AbstractNodeVisito ]; } - protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doEnterNode(Node $node, Environment $env) { return $node; } - protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { - if ($node instanceof \Twig\Node\Expression\ConstantExpression) { + if ($node instanceof ConstantExpression) { // constants are marked safe for all $this->setSafe($node, ['all']); - } elseif ($node instanceof \Twig\Node\Expression\BlockReferenceExpression) { + } elseif ($node instanceof BlockReferenceExpression) { // blocks are safe by definition $this->setSafe($node, ['all']); - } elseif ($node instanceof \Twig\Node\Expression\ParentExpression) { + } elseif ($node instanceof ParentExpression) { // parent block is safe by definition $this->setSafe($node, ['all']); - } elseif ($node instanceof \Twig\Node\Expression\ConditionalExpression) { + } elseif ($node instanceof ConditionalExpression) { // intersect safeness of both operands $safe = $this->intersectSafe($this->getSafe($node->getNode('expr2')), $this->getSafe($node->getNode('expr3'))); $this->setSafe($node, $safe); - } elseif ($node instanceof \Twig\Node\Expression\FilterExpression) { + } elseif ($node instanceof FilterExpression) { // filter expression is safe when the filter is safe $name = $node->getNode('filter')->getAttribute('value'); $args = $node->getNode('arguments'); @@ -93,7 +106,7 @@ class Twig_NodeVisitor_SafeAnalysis extends \Twig\NodeVisitor\AbstractNodeVisito } else { $this->setSafe($node, []); } - } elseif ($node instanceof \Twig\Node\Expression\FunctionExpression) { + } elseif ($node instanceof FunctionExpression) { // function expression is safe when the function is safe $name = $node->getAttribute('name'); $args = $node->getNode('arguments'); @@ -103,13 +116,13 @@ class Twig_NodeVisitor_SafeAnalysis extends \Twig\NodeVisitor\AbstractNodeVisito } else { $this->setSafe($node, []); } - } elseif ($node instanceof \Twig\Node\Expression\MethodCallExpression) { + } elseif ($node instanceof MethodCallExpression) { if ($node->getAttribute('safe')) { $this->setSafe($node, ['all']); } else { $this->setSafe($node, []); } - } elseif ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression) { + } elseif ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression) { $name = $node->getNode('node')->getAttribute('name'); // attributes on template instances are safe if ('_self' == $name || \in_array($name, $this->safeVars)) { diff --git a/lib/Twig/NodeVisitor/Sandbox.php b/lib/Twig/NodeVisitor/Sandbox.php index 193f73564..ece1cbad9 100644 --- a/lib/Twig/NodeVisitor/Sandbox.php +++ b/lib/Twig/NodeVisitor/Sandbox.php @@ -9,6 +9,17 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\Node\ModuleNode; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Expression\FunctionExpression; +use Twig\Node\Expression\Binary\RangeBinary; +use Twig\Node\PrintNode; +use Twig\Node\SandboxedPrintNode; +use Twig\Node\Node; +use Twig\Node\CheckSecurityNode; +use Twig\Environment; + /** * Twig_NodeVisitor_Sandbox implements sandboxing. * @@ -16,16 +27,16 @@ * * @author Fabien Potencier */ -class Twig_NodeVisitor_Sandbox extends \Twig\NodeVisitor\AbstractNodeVisitor +class Twig_NodeVisitor_Sandbox extends AbstractNodeVisitor { protected $inAModule = false; protected $tags; protected $filters; protected $functions; - protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doEnterNode(Node $node, Environment $env) { - if ($node instanceof \Twig\Node\ModuleNode) { + if ($node instanceof ModuleNode) { $this->inAModule = true; $this->tags = []; $this->filters = []; @@ -39,35 +50,35 @@ class Twig_NodeVisitor_Sandbox extends \Twig\NodeVisitor\AbstractNodeVisitor } // look for filters - if ($node instanceof \Twig\Node\Expression\FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { + if ($node instanceof FilterExpression && !isset($this->filters[$node->getNode('filter')->getAttribute('value')])) { $this->filters[$node->getNode('filter')->getAttribute('value')] = $node; } // look for functions - if ($node instanceof \Twig\Node\Expression\FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { + if ($node instanceof FunctionExpression && !isset($this->functions[$node->getAttribute('name')])) { $this->functions[$node->getAttribute('name')] = $node; } // the .. operator is equivalent to the range() function - if ($node instanceof \Twig\Node\Expression\Binary\RangeBinary && !isset($this->functions['range'])) { + if ($node instanceof RangeBinary && !isset($this->functions['range'])) { $this->functions['range'] = $node; } // wrap print to check __toString() calls - if ($node instanceof \Twig\Node\PrintNode) { - return new \Twig\Node\SandboxedPrintNode($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag()); + if ($node instanceof PrintNode) { + return new SandboxedPrintNode($node->getNode('expr'), $node->getTemplateLine(), $node->getNodeTag()); } } return $node; } - protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { - if ($node instanceof \Twig\Node\ModuleNode) { + if ($node instanceof ModuleNode) { $this->inAModule = false; - $node->setNode('display_start', new \Twig\Node\Node([new \Twig\Node\CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); + $node->setNode('display_start', new Node([new CheckSecurityNode($this->filters, $this->tags, $this->functions), $node->getNode('display_start')])); } return $node; diff --git a/lib/Twig/NodeVisitorInterface.php b/lib/Twig/NodeVisitorInterface.php index 00f8afaf6..ebb2f37c8 100644 --- a/lib/Twig/NodeVisitorInterface.php +++ b/lib/Twig/NodeVisitorInterface.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Environment; + /** * Twig_NodeVisitorInterface is the interface the all node visitor classes must implement. * @@ -21,14 +23,14 @@ interface Twig_NodeVisitorInterface * * @return Twig_NodeInterface The modified node */ - public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env); + public function enterNode(Twig_NodeInterface $node, Environment $env); /** * Called after child nodes are visited. * * @return Twig_NodeInterface|false The modified node or false if the node must be removed */ - public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env); + public function leaveNode(Twig_NodeInterface $node, Environment $env); /** * Returns the priority for this visitor. diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 1eaf49fce..abe443d3b 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -10,6 +10,26 @@ * file that was distributed with this source code. */ +use Twig\ExpressionParser; +use Twig\Node\Node; +use Twig\Node\ModuleNode; +use Twig\Node\BodyNode; +use Twig\NodeTraverser; +use Twig\Node\TextNode; +use Twig\Node\PrintNode; +use Twig\Error\SyntaxError; +use Twig\TokenParser\TokenParserInterface; +use Twig\TokenStream; +use Twig\Token; +use Twig\Node\BlockReferenceNode; +use Twig\Node\NodeOutputInterface; +use Twig\Node\NodeCaptureInterface; +use Twig\Environment; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Node\BlockNode; +use Twig\Node\MacroNode; +use Twig\Node\Expression\AbstractExpression; + /** * Default parser implementation. * @@ -33,7 +53,7 @@ class Twig_Parser implements Twig_ParserInterface protected $embeddedTemplates = []; private $varNameSalt = 0; - public function __construct(\Twig\Environment $env) + public function __construct(Environment $env) { $this->env = $env; } @@ -63,7 +83,7 @@ class Twig_Parser implements Twig_ParserInterface return $this->stream->getSourceContext()->getName(); } - public function parse(\Twig\TokenStream $stream, $test = null, $dropNeedle = false) + public function parse(TokenStream $stream, $test = null, $dropNeedle = false) { // push all variables into the stack to keep the current state of the parser // using get_object_vars() instead of foreach would lead to https://bugs.php.net/71336 @@ -88,7 +108,7 @@ class Twig_Parser implements Twig_ParserInterface } if (null === $this->expressionParser) { - $this->expressionParser = new \Twig\ExpressionParser($this, $this->env); + $this->expressionParser = new ExpressionParser($this, $this->env); } $this->stream = $stream; @@ -105,9 +125,9 @@ class Twig_Parser implements Twig_ParserInterface $body = $this->subparse($test, $dropNeedle); if (null !== $this->parent && null === $body = $this->filterBodyNodes($body)) { - $body = new \Twig\Node\Node(); + $body = new Node(); } - } catch (\Twig\Error\SyntaxError $e) { + } catch (SyntaxError $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->stream->getSourceContext()); } @@ -119,9 +139,9 @@ class Twig_Parser implements Twig_ParserInterface throw $e; } - $node = new \Twig\Node\ModuleNode(new \Twig\Node\BodyNode([$body]), $this->parent, new \Twig\Node\Node($this->blocks), new \Twig\Node\Node($this->macros), new \Twig\Node\Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); + $node = new ModuleNode(new BodyNode([$body]), $this->parent, new Node($this->blocks), new Node($this->macros), new Node($this->traits), $this->embeddedTemplates, $stream->getSourceContext()); - $traverser = new \Twig\NodeTraverser($this->env, $this->visitors); + $traverser = new NodeTraverser($this->env, $this->visitors); $node = $traverser->traverse($node); @@ -139,24 +159,24 @@ class Twig_Parser implements Twig_ParserInterface $rv = []; while (!$this->stream->isEOF()) { switch ($this->getCurrentToken()->getType()) { - case \Twig\Token::TEXT_TYPE: + case Token::TEXT_TYPE: $token = $this->stream->next(); - $rv[] = new \Twig\Node\TextNode($token->getValue(), $token->getLine()); + $rv[] = new TextNode($token->getValue(), $token->getLine()); break; - case \Twig\Token::VAR_START_TYPE: + case Token::VAR_START_TYPE: $token = $this->stream->next(); $expr = $this->expressionParser->parseExpression(); - $this->stream->expect(\Twig\Token::VAR_END_TYPE); - $rv[] = new \Twig\Node\PrintNode($expr, $token->getLine()); + $this->stream->expect(Token::VAR_END_TYPE); + $rv[] = new PrintNode($expr, $token->getLine()); break; - case \Twig\Token::BLOCK_START_TYPE: + case Token::BLOCK_START_TYPE: $this->stream->next(); $token = $this->getCurrentToken(); - if (\Twig\Token::NAME_TYPE !== $token->getType()) { - throw new \Twig\Error\SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); + if (Token::NAME_TYPE !== $token->getType()) { + throw new SyntaxError('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); } if (null !== $test && \call_user_func($test, $token)) { @@ -168,19 +188,19 @@ class Twig_Parser implements Twig_ParserInterface return $rv[0]; } - return new \Twig\Node\Node($rv, [], $lineno); + return new Node($rv, [], $lineno); } $subparser = $this->handlers->getTokenParser($token->getValue()); if (null === $subparser) { if (null !== $test) { - $e = new \Twig\Error\SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e = new SyntaxError(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - if (\is_array($test) && isset($test[0]) && $test[0] instanceof \Twig\TokenParser\TokenParserInterface) { + if (\is_array($test) && isset($test[0]) && $test[0] instanceof TokenParserInterface) { $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); } } else { - $e = new \Twig\Error\SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); + $e = new SyntaxError(sprintf('Unknown "%s" tag.', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); $e->addSuggestions($token->getValue(), array_keys($this->env->getTags())); } @@ -196,7 +216,7 @@ class Twig_Parser implements Twig_ParserInterface break; default: - throw new \Twig\Error\SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); + throw new SyntaxError('Lexer or parser ended up in unsupported state.', $this->getCurrentToken()->getLine(), $this->stream->getSourceContext()); } } @@ -204,7 +224,7 @@ class Twig_Parser implements Twig_ParserInterface return $rv[0]; } - return new \Twig\Node\Node($rv, [], $lineno); + return new Node($rv, [], $lineno); } /** @@ -220,7 +240,7 @@ class Twig_Parser implements Twig_ParserInterface /** * @deprecated since 1.27 (to be removed in 2.0) */ - public function addNodeVisitor(\Twig\NodeVisitor\NodeVisitorInterface $visitor) + public function addNodeVisitor(NodeVisitorInterface $visitor) { @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); @@ -257,9 +277,9 @@ class Twig_Parser implements Twig_ParserInterface return $this->blocks[$name]; } - public function setBlock($name, \Twig\Node\BlockNode $value) + public function setBlock($name, BlockNode $value) { - $this->blocks[$name] = new \Twig\Node\BodyNode([$value], [], $value->getTemplateLine()); + $this->blocks[$name] = new BodyNode([$value], [], $value->getTemplateLine()); } public function hasMacro($name) @@ -267,10 +287,10 @@ class Twig_Parser implements Twig_ParserInterface return isset($this->macros[$name]); } - public function setMacro($name, \Twig\Node\MacroNode $node) + public function setMacro($name, MacroNode $node) { if ($this->isReservedMacroName($name)) { - throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()); + throw new SyntaxError(sprintf('"%s" cannot be used as a macro name as it is a reserved keyword.', $name), $node->getTemplateLine(), $this->stream->getSourceContext()); } $this->macros[$name] = $node; @@ -303,14 +323,14 @@ class Twig_Parser implements Twig_ParserInterface return \count($this->traits) > 0; } - public function embedTemplate(\Twig\Node\ModuleNode $template) + public function embedTemplate(ModuleNode $template) { $template->setIndex(mt_rand()); $this->embeddedTemplates[] = $template; } - public function addImportedSymbol($type, $alias, $name = null, \Twig\Node\Expression\AbstractExpression $node = null) + public function addImportedSymbol($type, $alias, $name = null, AbstractExpression $node = null) { $this->importedSymbols[0][$type][$alias] = ['name' => $name, 'node' => $node]; } @@ -340,7 +360,7 @@ class Twig_Parser implements Twig_ParserInterface } /** - * @return \Twig\ExpressionParser + * @return ExpressionParser */ public function getExpressionParser() { @@ -358,7 +378,7 @@ class Twig_Parser implements Twig_ParserInterface } /** - * @return \Twig\TokenStream + * @return TokenStream */ public function getStream() { @@ -366,7 +386,7 @@ class Twig_Parser implements Twig_ParserInterface } /** - * @return \Twig\Token + * @return Token */ public function getCurrentToken() { @@ -377,9 +397,9 @@ class Twig_Parser implements Twig_ParserInterface { // check that the body does not contain non-empty output nodes if ( - ($node instanceof \Twig\Node\TextNode && !ctype_space($node->getAttribute('data'))) + ($node instanceof TextNode && !ctype_space($node->getAttribute('data'))) || - (!$node instanceof \Twig\Node\TextNode && !$node instanceof \Twig\Node\BlockReferenceNode && $node instanceof \Twig\Node\NodeOutputInterface) + (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface) ) { if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { $t = substr($node->getAttribute('data'), 3); @@ -389,15 +409,15 @@ class Twig_Parser implements Twig_ParserInterface } } - throw new \Twig\Error\SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); + throw new SyntaxError('A template that extends another one cannot include content outside Twig blocks. Did you forget to put the content inside a {% block %} tag?', $node->getTemplateLine(), $this->stream->getSourceContext()); } // bypass nodes that will "capture" the output - if ($node instanceof \Twig\Node\NodeCaptureInterface) { + if ($node instanceof NodeCaptureInterface) { return $node; } - if ($node instanceof \Twig\Node\NodeOutputInterface) { + if ($node instanceof NodeOutputInterface) { return; } diff --git a/lib/Twig/ParserInterface.php b/lib/Twig/ParserInterface.php index d628d6521..438db65d4 100644 --- a/lib/Twig/ParserInterface.php +++ b/lib/Twig/ParserInterface.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Node\ModuleNode; +use Twig\Error\SyntaxError; +use Twig\TokenStream; + /** * Interface implemented by parser classes. * @@ -21,9 +25,9 @@ interface Twig_ParserInterface /** * Converts a token stream to a node tree. * - * @return \Twig\Node\ModuleNode + * @return ModuleNode * - * @throws \Twig\Error\SyntaxError When the token stream is syntactically or semantically wrong + * @throws SyntaxError When the token stream is syntactically or semantically wrong */ - public function parse(\Twig\TokenStream $stream); + public function parse(TokenStream $stream); } diff --git a/lib/Twig/Profiler/Dumper/Base.php b/lib/Twig/Profiler/Dumper/Base.php index 9ce124323..4272c5390 100644 --- a/lib/Twig/Profiler/Dumper/Base.php +++ b/lib/Twig/Profiler/Dumper/Base.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Profile; + /** * @author Fabien Potencier */ @@ -16,18 +18,18 @@ abstract class Twig_Profiler_Dumper_Base { private $root; - public function dump(\Twig\Profiler\Profile $profile) + public function dump(Profile $profile) { return $this->dumpProfile($profile); } - abstract protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix); + abstract protected function formatTemplate(Profile $profile, $prefix); - abstract protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix); + abstract protected function formatNonTemplate(Profile $profile, $prefix); - abstract protected function formatTime(\Twig\Profiler\Profile $profile, $percent); + abstract protected function formatTime(Profile $profile, $percent); - private function dumpProfile(\Twig\Profiler\Profile $profile, $prefix = '', $sibling = false) + private function dumpProfile(Profile $profile, $prefix = '', $sibling = false) { if ($profile->isRoot()) { $this->root = $profile->getDuration(); diff --git a/lib/Twig/Profiler/Dumper/Blackfire.php b/lib/Twig/Profiler/Dumper/Blackfire.php index 827a20b6d..439513852 100644 --- a/lib/Twig/Profiler/Dumper/Blackfire.php +++ b/lib/Twig/Profiler/Dumper/Blackfire.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Profile; + /** * @author Fabien Potencier * @@ -16,7 +18,7 @@ */ class Twig_Profiler_Dumper_Blackfire { - public function dump(\Twig\Profiler\Profile $profile) + public function dump(Profile $profile) { $data = []; $this->dumpProfile('main()', $profile, $data); @@ -38,7 +40,7 @@ EOF; return $str; } - private function dumpChildren($parent, \Twig\Profiler\Profile $profile, &$data) + private function dumpChildren($parent, Profile $profile, &$data) { foreach ($profile as $p) { if ($p->isTemplate()) { @@ -51,7 +53,7 @@ EOF; } } - private function dumpProfile($edge, \Twig\Profiler\Profile $profile, &$data) + private function dumpProfile($edge, Profile $profile, &$data) { if (isset($data[$edge])) { ++$data[$edge]['ct']; diff --git a/lib/Twig/Profiler/Dumper/Html.php b/lib/Twig/Profiler/Dumper/Html.php index b9ddd586b..80eee16bd 100644 --- a/lib/Twig/Profiler/Dumper/Html.php +++ b/lib/Twig/Profiler/Dumper/Html.php @@ -9,12 +9,15 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Dumper\BaseDumper; +use Twig\Profiler\Profile; + /** * @author Fabien Potencier * * @final */ -class Twig_Profiler_Dumper_Html extends \Twig\Profiler\Dumper\BaseDumper +class Twig_Profiler_Dumper_Html extends BaseDumper { private static $colors = [ 'block' => '#dfd', @@ -23,22 +26,22 @@ class Twig_Profiler_Dumper_Html extends \Twig\Profiler\Dumper\BaseDumper 'big' => '#d44', ]; - public function dump(\Twig\Profiler\Profile $profile) + public function dump(Profile $profile) { return '
'.parent::dump($profile).'
'; } - protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix) + protected function formatTemplate(Profile $profile, $prefix) { return sprintf('%s└ %s', $prefix, self::$colors['template'], $profile->getTemplate()); } - protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix) + protected function formatNonTemplate(Profile $profile, $prefix) { return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), isset(self::$colors[$profile->getType()]) ? self::$colors[$profile->getType()] : 'auto', $profile->getName()); } - protected function formatTime(\Twig\Profiler\Profile $profile, $percent) + protected function formatTime(Profile $profile, $percent) { return sprintf('%.2fms/%.0f%%', $percent > 20 ? self::$colors['big'] : 'auto', $profile->getDuration() * 1000, $percent); } diff --git a/lib/Twig/Profiler/Dumper/Text.php b/lib/Twig/Profiler/Dumper/Text.php index abc961b78..b3b1ec5db 100644 --- a/lib/Twig/Profiler/Dumper/Text.php +++ b/lib/Twig/Profiler/Dumper/Text.php @@ -9,24 +9,27 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Dumper\BaseDumper; +use Twig\Profiler\Profile; + /** * @author Fabien Potencier * * @final */ -class Twig_Profiler_Dumper_Text extends \Twig\Profiler\Dumper\BaseDumper +class Twig_Profiler_Dumper_Text extends BaseDumper { - protected function formatTemplate(\Twig\Profiler\Profile $profile, $prefix) + protected function formatTemplate(Profile $profile, $prefix) { return sprintf('%s└ %s', $prefix, $profile->getTemplate()); } - protected function formatNonTemplate(\Twig\Profiler\Profile $profile, $prefix) + protected function formatNonTemplate(Profile $profile, $prefix) { return sprintf('%s└ %s::%s(%s)', $prefix, $profile->getTemplate(), $profile->getType(), $profile->getName()); } - protected function formatTime(\Twig\Profiler\Profile $profile, $percent) + protected function formatTime(Profile $profile, $percent) { return sprintf('%.2fms/%.0f%%', $profile->getDuration() * 1000, $percent); } diff --git a/lib/Twig/Profiler/Node/EnterProfile.php b/lib/Twig/Profiler/Node/EnterProfile.php index 3144c03c7..c1451c211 100644 --- a/lib/Twig/Profiler/Node/EnterProfile.php +++ b/lib/Twig/Profiler/Node/EnterProfile.php @@ -9,25 +9,29 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Profiler\Profile; +use Twig\Compiler; + /** * Represents a profile enter node. * * @author Fabien Potencier */ -class Twig_Profiler_Node_EnterProfile extends \Twig\Node\Node +class Twig_Profiler_Node_EnterProfile extends Node { public function __construct($extensionName, $type, $name, $varName) { parent::__construct([], ['extension_name' => $extensionName, 'name' => $name, 'type' => $type, 'var_name' => $varName]); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->write(sprintf('$%s = $this->env->getExtension(', $this->getAttribute('var_name'))) ->repr($this->getAttribute('extension_name')) ->raw(");\n") - ->write(sprintf('$%s->enter($%s = new \Twig\Profiler\Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) + ->write(sprintf('$%s->enter($%s = new Profile($this->getTemplateName(), ', $this->getAttribute('var_name'), $this->getAttribute('var_name').'_prof')) ->repr($this->getAttribute('type')) ->raw(', ') ->repr($this->getAttribute('name')) diff --git a/lib/Twig/Profiler/Node/LeaveProfile.php b/lib/Twig/Profiler/Node/LeaveProfile.php index cfc0d2597..abe668fd9 100644 --- a/lib/Twig/Profiler/Node/LeaveProfile.php +++ b/lib/Twig/Profiler/Node/LeaveProfile.php @@ -9,19 +9,22 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; +use Twig\Compiler; + /** * Represents a profile leave node. * * @author Fabien Potencier */ -class Twig_Profiler_Node_LeaveProfile extends \Twig\Node\Node +class Twig_Profiler_Node_LeaveProfile extends Node { public function __construct($varName) { parent::__construct([], ['var_name' => $varName]); } - public function compile(\Twig\Compiler $compiler) + public function compile(Compiler $compiler) { $compiler ->write("\n") diff --git a/lib/Twig/Profiler/NodeVisitor/Profiler.php b/lib/Twig/Profiler/NodeVisitor/Profiler.php index 40d46532d..fe7ac5c23 100644 --- a/lib/Twig/Profiler/NodeVisitor/Profiler.php +++ b/lib/Twig/Profiler/NodeVisitor/Profiler.php @@ -9,12 +9,23 @@ * file that was distributed with this source code. */ +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\Node\ModuleNode; +use Twig\Node\Node; +use Twig\Profiler\Node\EnterProfileNode; +use Twig\Profiler\Node\LeaveProfileNode; +use Twig\Node\BlockNode; +use Twig\Node\BodyNode; +use Twig\Node\MacroNode; +use Twig\Profiler\Profile; +use Twig\Environment; + /** * @author Fabien Potencier * * @final */ -class Twig_Profiler_NodeVisitor_Profiler extends \Twig\NodeVisitor\AbstractNodeVisitor +class Twig_Profiler_NodeVisitor_Profiler extends AbstractNodeVisitor { private $extensionName; @@ -23,30 +34,30 @@ class Twig_Profiler_NodeVisitor_Profiler extends \Twig\NodeVisitor\AbstractNodeV $this->extensionName = $extensionName; } - protected function doEnterNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doEnterNode(Node $node, Environment $env) { return $node; } - protected function doLeaveNode(\Twig\Node\Node $node, \Twig\Environment $env) + protected function doLeaveNode(Node $node, Environment $env) { - if ($node instanceof \Twig\Node\ModuleNode) { + if ($node instanceof ModuleNode) { $varName = $this->getVarName(); - $node->setNode('display_start', new \Twig\Node\Node([new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); - $node->setNode('display_end', new \Twig\Node\Node([new \Twig\Profiler\Node\LeaveProfileNode($varName), $node->getNode('display_end')])); - } elseif ($node instanceof \Twig\Node\BlockNode) { + $node->setNode('display_start', new Node([new EnterProfileNode($this->extensionName, Profile::TEMPLATE, $node->getTemplateName(), $varName), $node->getNode('display_start')])); + $node->setNode('display_end', new Node([new LeaveProfileNode($varName), $node->getNode('display_end')])); + } elseif ($node instanceof BlockNode) { $varName = $this->getVarName(); - $node->setNode('body', new \Twig\Node\BodyNode([ - new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::BLOCK, $node->getAttribute('name'), $varName), + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::BLOCK, $node->getAttribute('name'), $varName), $node->getNode('body'), - new \Twig\Profiler\Node\LeaveProfileNode($varName), + new LeaveProfileNode($varName), ])); - } elseif ($node instanceof \Twig\Node\MacroNode) { + } elseif ($node instanceof MacroNode) { $varName = $this->getVarName(); - $node->setNode('body', new \Twig\Node\BodyNode([ - new \Twig\Profiler\Node\EnterProfileNode($this->extensionName, \Twig\Profiler\Profile::MACRO, $node->getAttribute('name'), $varName), + $node->setNode('body', new BodyNode([ + new EnterProfileNode($this->extensionName, Profile::MACRO, $node->getAttribute('name'), $varName), $node->getNode('body'), - new \Twig\Profiler\Node\LeaveProfileNode($varName), + new LeaveProfileNode($varName), ])); } diff --git a/lib/Twig/Sandbox/SecurityError.php b/lib/Twig/Sandbox/SecurityError.php index bb18c8f03..91878f8c0 100644 --- a/lib/Twig/Sandbox/SecurityError.php +++ b/lib/Twig/Sandbox/SecurityError.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Error\Error; + /** * Exception thrown when a security error occurs at runtime. * * @author Fabien Potencier */ -class Twig_Sandbox_SecurityError extends \Twig\Error\Error +class Twig_Sandbox_SecurityError extends Error { } diff --git a/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php b/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php index 4d254d36a..22a20abb5 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedFilterError.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Sandbox\SecurityError; + /** * Exception thrown when a not allowed filter is used in a template. * * @author Martin Hasoň */ -class Twig_Sandbox_SecurityNotAllowedFilterError extends \Twig\Sandbox\SecurityError +class Twig_Sandbox_SecurityNotAllowedFilterError extends SecurityError { private $filterName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php b/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php index 8624cca53..7c2c3be87 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedFunctionError.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Sandbox\SecurityError; + /** * Exception thrown when a not allowed function is used in a template. * * @author Martin Hasoň */ -class Twig_Sandbox_SecurityNotAllowedFunctionError extends \Twig\Sandbox\SecurityError +class Twig_Sandbox_SecurityNotAllowedFunctionError extends SecurityError { private $functionName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php b/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php index 3d49be38a..7f18a8acf 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedMethodError.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Sandbox\SecurityError; + /** * Exception thrown when a not allowed class method is used in a template. * * @author Kit Burton-Senior */ -class Twig_Sandbox_SecurityNotAllowedMethodError extends \Twig\Sandbox\SecurityError +class Twig_Sandbox_SecurityNotAllowedMethodError extends SecurityError { private $className; private $methodName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php b/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php index ae304833b..81cd20c18 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedPropertyError.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Sandbox\SecurityError; + /** * Exception thrown when a not allowed class property is used in a template. * * @author Kit Burton-Senior */ -class Twig_Sandbox_SecurityNotAllowedPropertyError extends \Twig\Sandbox\SecurityError +class Twig_Sandbox_SecurityNotAllowedPropertyError extends SecurityError { private $className; private $propertyName; diff --git a/lib/Twig/Sandbox/SecurityNotAllowedTagError.php b/lib/Twig/Sandbox/SecurityNotAllowedTagError.php index c5bc54da3..96ecc7ff2 100644 --- a/lib/Twig/Sandbox/SecurityNotAllowedTagError.php +++ b/lib/Twig/Sandbox/SecurityNotAllowedTagError.php @@ -9,12 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Sandbox\SecurityError; + /** * Exception thrown when a not allowed tag is used in a template. * * @author Martin Hasoň */ -class Twig_Sandbox_SecurityNotAllowedTagError extends \Twig\Sandbox\SecurityError +class Twig_Sandbox_SecurityNotAllowedTagError extends SecurityError { private $tagName; diff --git a/lib/Twig/Sandbox/SecurityPolicy.php b/lib/Twig/Sandbox/SecurityPolicy.php index 8b9465bb5..ae42f6698 100644 --- a/lib/Twig/Sandbox/SecurityPolicy.php +++ b/lib/Twig/Sandbox/SecurityPolicy.php @@ -9,6 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Sandbox\SecurityPolicyInterface; +use Twig\Sandbox\SecurityNotAllowedTagError; +use Twig\Sandbox\SecurityNotAllowedFilterError; +use Twig\Sandbox\SecurityNotAllowedFunctionError; +use Twig\Markup; +use Twig\Sandbox\SecurityNotAllowedMethodError; +use Twig\Sandbox\SecurityNotAllowedPropertyError; + /** * Represents a security policy which need to be enforced when sandbox mode is enabled. * @@ -16,7 +24,7 @@ * * @author Fabien Potencier */ -class Twig_Sandbox_SecurityPolicy implements \Twig\Sandbox\SecurityPolicyInterface +class Twig_Sandbox_SecurityPolicy implements SecurityPolicyInterface { protected $allowedTags; protected $allowedFilters; @@ -65,26 +73,26 @@ class Twig_Sandbox_SecurityPolicy implements \Twig\Sandbox\SecurityPolicyInterfa { foreach ($tags as $tag) { if (!\in_array($tag, $this->allowedTags)) { - throw new \Twig\Sandbox\SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); + throw new SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); } } foreach ($filters as $filter) { if (!\in_array($filter, $this->allowedFilters)) { - throw new \Twig\Sandbox\SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); + throw new SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); } } foreach ($functions as $function) { if (!\in_array($function, $this->allowedFunctions)) { - throw new \Twig\Sandbox\SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); + throw new SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); } } } public function checkMethodAllowed($obj, $method) { - if ($obj instanceof Twig_TemplateInterface || $obj instanceof \Twig\Markup) { + if ($obj instanceof Twig_TemplateInterface || $obj instanceof Markup) { return true; } @@ -100,7 +108,7 @@ class Twig_Sandbox_SecurityPolicy implements \Twig\Sandbox\SecurityPolicyInterfa if (!$allowed) { $class = \get_class($obj); - throw new \Twig\Sandbox\SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); + throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); } } @@ -117,7 +125,7 @@ class Twig_Sandbox_SecurityPolicy implements \Twig\Sandbox\SecurityPolicyInterfa if (!$allowed) { $class = \get_class($obj); - throw new \Twig\Sandbox\SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); + throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); } } } diff --git a/lib/Twig/SimpleFilter.php b/lib/Twig/SimpleFilter.php index f94f9469e..fa8957549 100644 --- a/lib/Twig/SimpleFilter.php +++ b/lib/Twig/SimpleFilter.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + /** * Represents a template filter. * @@ -76,7 +78,7 @@ class Twig_SimpleFilter return $this->options['needs_context']; } - public function getSafe(\Twig\Node\Node $filterArgs) + public function getSafe(Node $filterArgs) { if (null !== $this->options['is_safe']) { return $this->options['is_safe']; diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php index 592002609..3d0b37c9d 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Node; + /** * Represents a template function. * @@ -74,7 +76,7 @@ class Twig_SimpleFunction return $this->options['needs_context']; } - public function getSafe(\Twig\Node\Node $functionArgs) + public function getSafe(Node $functionArgs) { if (null !== $this->options['is_safe']) { return $this->options['is_safe']; diff --git a/lib/Twig/SourceContextLoaderInterface.php b/lib/Twig/SourceContextLoaderInterface.php index c0b2b156e..ce0dce14f 100644 --- a/lib/Twig/SourceContextLoaderInterface.php +++ b/lib/Twig/SourceContextLoaderInterface.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Source; +use Twig\Error\LoaderError; + /** * Adds a getSourceContext() method for loaders. * @@ -23,9 +26,9 @@ interface Twig_SourceContextLoaderInterface * * @param string $name The template logical name * - * @return \Twig\Source + * @return Source * - * @throws \Twig\Error\LoaderError When $name is not found + * @throws LoaderError When $name is not found */ public function getSourceContext($name); } diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 810536a10..916b50334 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -10,6 +10,14 @@ * file that was distributed with this source code. */ +use Twig\Source; +use Twig\TemplateWrapper; +use Twig\Error\RuntimeError; +use Twig\Markup; +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Error\Error; + /** * Default base class for compiled templates. * @@ -34,7 +42,7 @@ abstract class Twig_Template implements Twig_TemplateInterface protected $blocks = []; protected $traits = []; - public function __construct(\Twig\Environment $env) + public function __construct(Environment $env) { $this->env = $env; } @@ -83,11 +91,11 @@ abstract class Twig_Template implements Twig_TemplateInterface /** * Returns information about the original template source code. * - * @return \Twig\Source + * @return Source */ public function getSourceContext() { - return new \Twig\Source('', $this->getTemplateName()); + return new Source('', $this->getTemplateName()); } /** @@ -108,7 +116,7 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @param array $context * - * @return Twig_TemplateInterface|\Twig\TemplateWrapper|false The parent template or false if there is no parent + * @return Twig_TemplateInterface|TemplateWrapper|false The parent template or false if there is no parent * * @internal */ @@ -125,14 +133,14 @@ abstract class Twig_Template implements Twig_TemplateInterface return false; } - if ($parent instanceof self || $parent instanceof \Twig\TemplateWrapper) { + if ($parent instanceof self || $parent instanceof TemplateWrapper) { return $this->parents[$parent->getSourceContext()->getName()] = $parent; } if (!isset($this->parents[$parent])) { $this->parents[$parent] = $this->loadTemplate($parent); } - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { $e->setSourceContext(null); $e->guess(); @@ -173,7 +181,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, $blocks, false); } else { - throw new \Twig\Error\RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); + throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext()); } } @@ -213,7 +221,7 @@ abstract class Twig_Template implements Twig_TemplateInterface if (null !== $template) { try { $template->$block($context, $blocks); - } catch (\Twig\Error\Error $e) { + } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($template->getSourceContext()); } @@ -227,7 +235,7 @@ abstract class Twig_Template implements Twig_TemplateInterface throw $e; } catch (\Exception $e) { - throw new \Twig\Error\RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); + throw new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getSourceContext(), $e); } } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); @@ -355,14 +363,14 @@ abstract class Twig_Template implements Twig_TemplateInterface return $this->env->resolveTemplate($template); } - if ($template instanceof self || $template instanceof \Twig\TemplateWrapper) { + if ($template instanceof self || $template instanceof TemplateWrapper) { return $template; } return $this->env->loadTemplate($template, $index); - } catch (\Twig\Error\Error $e) { + } catch (Error $e) { if (!$e->getSourceContext()) { - $e->setSourceContext($templateName ? new \Twig\Source('', $templateName) : $this->getSourceContext()); + $e->setSourceContext($templateName ? new Source('', $templateName) : $this->getSourceContext()); } if ($e->getTemplateLine()) { @@ -426,7 +434,7 @@ abstract class Twig_Template implements Twig_TemplateInterface { try { $this->doDisplay($context, $blocks); - } catch (\Twig\Error\Error $e) { + } catch (Error $e) { if (!$e->getSourceContext()) { $e->setSourceContext($this->getSourceContext()); } @@ -440,7 +448,7 @@ abstract class Twig_Template implements Twig_TemplateInterface throw $e; } catch (\Exception $e) { - throw new \Twig\Error\RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); + throw new RuntimeError(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $this->getSourceContext(), $e); } } @@ -469,7 +477,7 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @return mixed The content of the context variable * - * @throws \Twig\Error\RuntimeError if the variable does not exist and Twig is running in strict mode + * @throws RuntimeError if the variable does not exist and Twig is running in strict mode * * @internal */ @@ -480,7 +488,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return; } - throw new \Twig\Error\RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext()); + throw new RuntimeError(sprintf('Variable "%s" does not exist.', $item), -1, $this->getSourceContext()); } return $context[$item]; @@ -498,7 +506,7 @@ abstract class Twig_Template implements Twig_TemplateInterface * * @return mixed The attribute value, or a Boolean when $isDefinedTest is true, or null when the attribute is not set and $ignoreStrictCheck is true * - * @throws \Twig\Error\RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false + * @throws RuntimeError if the attribute does not exist and Twig is running in strict mode and $isDefinedTest is false * * @internal */ @@ -549,7 +557,7 @@ abstract class Twig_Template implements Twig_TemplateInterface $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } - throw new \Twig\Error\RuntimeError($message, -1, $this->getSourceContext()); + throw new RuntimeError($message, -1, $this->getSourceContext()); } } @@ -570,7 +578,7 @@ abstract class Twig_Template implements Twig_TemplateInterface $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } - throw new \Twig\Error\RuntimeError($message, -1, $this->getSourceContext()); + throw new RuntimeError($message, -1, $this->getSourceContext()); } // object property @@ -655,7 +663,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return; } - throw new \Twig\Error\RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext()); + throw new RuntimeError(sprintf('Neither the property "%1$s" nor one of the methods "%1$s()", "get%1$s()"/"is%1$s()" or "__call()" exist and have public access in class "%2$s".', $item, $class), -1, $this->getSourceContext()); } if ($isDefinedTest) { @@ -694,7 +702,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } @trigger_error($message, E_USER_DEPRECATED); - return '' === $ret ? '' : new \Twig\Markup($ret, $this->env->getCharset()); + return '' === $ret ? '' : new Markup($ret, $this->env->getCharset()); } return $ret; diff --git a/lib/Twig/TemplateInterface.php b/lib/Twig/TemplateInterface.php index 3cbfe226f..0f767b8fc 100644 --- a/lib/Twig/TemplateInterface.php +++ b/lib/Twig/TemplateInterface.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Environment; + /** * Interface implemented by all compiled templates. * @@ -42,7 +44,7 @@ interface Twig_TemplateInterface /** * Returns the bound environment for this template. * - * @return \Twig\Environment + * @return Environment */ public function getEnvironment(); } diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php index 59aabf799..f696ce580 100644 --- a/lib/Twig/TemplateWrapper.php +++ b/lib/Twig/TemplateWrapper.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Source; +use Twig\Environment; +use Twig\Template; + /** * Exposes a template to userland. * @@ -25,7 +29,7 @@ final class Twig_TemplateWrapper * * @internal */ - public function __construct(\Twig\Environment $env, \Twig\Template $template) + public function __construct(Environment $env, Template $template) { $this->env = $env; $this->template = $template; @@ -126,7 +130,7 @@ final class Twig_TemplateWrapper } /** - * @return \Twig\Source + * @return Source */ public function getSourceContext() { diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index 3a083734b..574f583fb 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -9,6 +9,17 @@ * file that was distributed with this source code. */ +use Twig\RuntimeLoader\RuntimeLoaderInterface; +use Twig\Extension\ExtensionInterface; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; +use Twig\Loader\ArrayLoader; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Source; + use PHPUnit\Framework\TestCase; /** @@ -25,7 +36,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase abstract protected function getFixturesDir(); /** - * @return \Twig\RuntimeLoader\RuntimeLoaderInterface[] + * @return RuntimeLoaderInterface[] */ protected function getRuntimeLoaders() { @@ -33,7 +44,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase } /** - * @return \Twig\Extension\ExtensionInterface[] + * @return ExtensionInterface[] */ protected function getExtensions() { @@ -41,7 +52,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase } /** - * @return \Twig\TwigFilter[] + * @return TwigFilter[] */ protected function getTwigFilters() { @@ -49,7 +60,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase } /** - * @return \Twig\TwigFunction[] + * @return TwigFunction[] */ protected function getTwigFunctions() { @@ -57,7 +68,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase } /** - * @return \Twig\TwigTest[] + * @return TwigTest[] */ protected function getTwigTests() { @@ -142,14 +153,14 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase } } - $loader = new \Twig\Loader\ArrayLoader($templates); + $loader = new ArrayLoader($templates); foreach ($outputs as $i => $match) { $config = array_merge([ 'cache' => false, 'strict_variables' => true, ], $match[2] ? eval($match[2].';') : []); - $twig = new \Twig\Environment($loader, $config); + $twig = new Environment($loader, $config); $twig->addGlobal('global', 'global'); foreach ($this->getRuntimeLoaders() as $runtimeLoader) { $twig->addRuntimeLoader($runtimeLoader); @@ -187,7 +198,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase return; } - throw new \Twig\Error\Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); + throw new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); } try { @@ -199,7 +210,7 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase return; } - $e = new \Twig\Error\Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); + $e = new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); } @@ -218,8 +229,8 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase foreach (array_keys($templates) as $name) { echo "Template: $name\n"; $loader = $twig->getLoader(); - if (!$loader instanceof \Twig\Loader\SourceContextLoaderInterface) { - $source = new \Twig\Source($loader->getSource($name), $name); + if (!$loader instanceof SourceContextLoaderInterface) { + $source = new Source($loader->getSource($name), $name); } else { $source = $loader->getSourceContext($name); } diff --git a/lib/Twig/Test/Method.php b/lib/Twig/Test/Method.php index e4124f223..7a892ae85 100644 --- a/lib/Twig/Test/Method.php +++ b/lib/Twig/Test/Method.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Extension\ExtensionInterface; + @trigger_error('The Twig_Test_Method class is deprecated since version 1.12 and will be removed in 2.0. Use Twig_SimpleTest instead.', E_USER_DEPRECATED); /** @@ -23,7 +25,7 @@ class Twig_Test_Method extends Twig_Test protected $extension; protected $method; - public function __construct(\Twig\Extension\ExtensionInterface $extension, $method, array $options = []) + public function __construct(ExtensionInterface $extension, $method, array $options = []) { $options['callable'] = [$extension, $method]; diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php index ea0f8bb3f..43ee43872 100644 --- a/lib/Twig/Test/NodeTestCase.php +++ b/lib/Twig/Test/NodeTestCase.php @@ -9,6 +9,11 @@ * file that was distributed with this source code. */ +use Twig\Compiler; +use Twig\Environment; +use Twig\Loader\ArrayLoader; +use Twig\Node\Node; + use PHPUnit\Framework\TestCase; abstract class Twig_Test_NodeTestCase extends TestCase @@ -23,7 +28,7 @@ abstract class Twig_Test_NodeTestCase extends TestCase $this->assertNodeCompilation($source, $node, $environment, $isPattern); } - public function assertNodeCompilation($source, \Twig\Node\Node $node, \Twig\Environment $environment = null, $isPattern = false) + public function assertNodeCompilation($source, Node $node, Environment $environment = null, $isPattern = false) { $compiler = $this->getCompiler($environment); $compiler->compile($node); @@ -35,14 +40,14 @@ abstract class Twig_Test_NodeTestCase extends TestCase } } - protected function getCompiler(\Twig\Environment $environment = null) + protected function getCompiler(Environment $environment = null) { - return new \Twig\Compiler(null === $environment ? $this->getEnvironment() : $environment); + return new Compiler(null === $environment ? $this->getEnvironment() : $environment); } protected function getEnvironment() { - return new \Twig\Environment(new \Twig\Loader\ArrayLoader([])); + return new Environment(new ArrayLoader([])); } protected function getVariableGetter($name, $line = false) diff --git a/lib/Twig/TokenParser.php b/lib/Twig/TokenParser.php index e8fa01a25..3634e1b75 100644 --- a/lib/Twig/TokenParser.php +++ b/lib/Twig/TokenParser.php @@ -9,12 +9,15 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\TokenParserInterface; +use Twig\Parser; + /** * Base class for all token parsers. * * @author Fabien Potencier */ -abstract class Twig_TokenParser implements \Twig\TokenParser\TokenParserInterface +abstract class Twig_TokenParser implements TokenParserInterface { /** * @var Twig_Parser @@ -24,7 +27,7 @@ abstract class Twig_TokenParser implements \Twig\TokenParser\TokenParserInterfac /** * Sets the parser associated with this token parser. */ - public function setParser(\Twig\Parser $parser) + public function setParser(Parser $parser) { $this->parser = $parser; } diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index 42f62d981..8b7f72185 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\Expression\ConstantExpression; +use Twig\Error\SyntaxError; +use Twig\Node\AutoEscapeNode; +use Twig\Token; + /** * Marks a section of a template to be escaped or not. * @@ -27,19 +33,19 @@ * * @final */ -class Twig_TokenParser_AutoEscape extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_AutoEscape extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - if ($stream->test(\Twig\Token::BLOCK_END_TYPE)) { + if ($stream->test(Token::BLOCK_END_TYPE)) { $value = 'html'; } else { $expr = $this->parser->getExpressionParser()->parseExpression(); - if (!$expr instanceof \Twig\Node\Expression\ConstantExpression) { - throw new \Twig\Error\SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + if (!$expr instanceof ConstantExpression) { + throw new SyntaxError('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $value = $expr->getAttribute('value'); @@ -49,25 +55,25 @@ class Twig_TokenParser_AutoEscape extends \Twig\TokenParser\AbstractTokenParser $value = 'html'; } - if ($compat && $stream->test(\Twig\Token::NAME_TYPE)) { + if ($compat && $stream->test(Token::NAME_TYPE)) { @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED); if (false === $value) { - throw new \Twig\Error\SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $value = $stream->next()->getValue(); } } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\AutoEscapeNode($value, $body, $lineno, $this->getTag()); + return new AutoEscapeNode($value, $body, $lineno, $this->getTag()); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endautoescape'); } diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index c45289c5b..9a0b57836 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -10,6 +10,14 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Error\SyntaxError; +use Twig\Node\BlockNode; +use Twig\Node\Node; +use Twig\Node\PrintNode; +use Twig\Node\BlockReferenceNode; +use Twig\Token; + /** * Marks a section of a template as being reusable. * @@ -20,44 +28,44 @@ * * @final */ -class Twig_TokenParser_Block extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Block extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); if ($this->parser->hasBlock($name)) { - throw new \Twig\Error\SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf("The block '%s' has already been defined line %d.", $name, $this->parser->getBlock($name)->getTemplateLine()), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } - $this->parser->setBlock($name, $block = new \Twig\Node\BlockNode($name, new \Twig\Node\Node([]), $lineno)); + $this->parser->setBlock($name, $block = new BlockNode($name, new Node([]), $lineno)); $this->parser->pushLocalScope(); $this->parser->pushBlockStack($name); - if ($stream->nextIf(\Twig\Token::BLOCK_END_TYPE)) { + if ($stream->nextIf(Token::BLOCK_END_TYPE)) { $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) { + if ($token = $stream->nextIf(Token::NAME_TYPE)) { $value = $token->getValue(); if ($value != $name) { - throw new \Twig\Error\SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('Expected endblock for block "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } } else { - $body = new \Twig\Node\Node([ - new \Twig\Node\PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno), + $body = new Node([ + new PrintNode($this->parser->getExpressionParser()->parseExpression(), $lineno), ]); } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $block->setNode('body', $body); $this->parser->popBlockStack(); $this->parser->popLocalScope(); - return new \Twig\Node\BlockReferenceNode($name, $lineno, $this->getTag()); + return new BlockReferenceNode($name, $lineno, $this->getTag()); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endblock'); } diff --git a/lib/Twig/TokenParser/Deprecated.php b/lib/Twig/TokenParser/Deprecated.php index 05ea04251..dca8a0efd 100644 --- a/lib/Twig/TokenParser/Deprecated.php +++ b/lib/Twig/TokenParser/Deprecated.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\DeprecatedNode; +use Twig\Token; + /** * Deprecates a section of a template. * @@ -19,15 +23,15 @@ * * @final */ -class Twig_TokenParser_Deprecated extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Deprecated extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\DeprecatedNode($expr, $token->getLine(), $this->getTag()); + return new DeprecatedNode($expr, $token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/Do.php b/lib/Twig/TokenParser/Do.php index 7d788668a..4aa963a95 100644 --- a/lib/Twig/TokenParser/Do.php +++ b/lib/Twig/TokenParser/Do.php @@ -9,20 +9,24 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\DoNode; +use Twig\Token; + /** * Evaluates an expression, discarding the returned value. * * @final */ -class Twig_TokenParser_Do extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Do extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\DoNode($expr, $token->getLine(), $this->getTag()); + return new DoNode($expr, $token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/Embed.php b/lib/Twig/TokenParser/Embed.php index 7003f180e..e1a98e655 100644 --- a/lib/Twig/TokenParser/Embed.php +++ b/lib/Twig/TokenParser/Embed.php @@ -9,14 +9,20 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\IncludeTokenParser; +use Twig\Token; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\EmbedNode; + /** * Embeds a template. * * @final */ -class Twig_TokenParser_Embed extends \Twig\TokenParser\IncludeTokenParser +class Twig_TokenParser_Embed extends IncludeTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $stream = $this->parser->getStream(); @@ -24,19 +30,19 @@ class Twig_TokenParser_Embed extends \Twig\TokenParser\IncludeTokenParser list($variables, $only, $ignoreMissing) = $this->parseArguments(); - $parentToken = $fakeParentToken = new \Twig\Token(\Twig\Token::STRING_TYPE, '__parent__', $token->getLine()); - if ($parent instanceof \Twig\Node\Expression\ConstantExpression) { - $parentToken = new \Twig\Token(\Twig\Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine()); - } elseif ($parent instanceof \Twig\Node\Expression\NameExpression) { - $parentToken = new \Twig\Token(\Twig\Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine()); + $parentToken = $fakeParentToken = new Token(Token::STRING_TYPE, '__parent__', $token->getLine()); + if ($parent instanceof ConstantExpression) { + $parentToken = new Token(Token::STRING_TYPE, $parent->getAttribute('value'), $token->getLine()); + } elseif ($parent instanceof NameExpression) { + $parentToken = new Token(Token::NAME_TYPE, $parent->getAttribute('name'), $token->getLine()); } // inject a fake parent to make the parent() function work $stream->injectTokens([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', $token->getLine()), - new \Twig\Token(\Twig\Token::NAME_TYPE, 'extends', $token->getLine()), + new Token(Token::BLOCK_START_TYPE, '', $token->getLine()), + new Token(Token::NAME_TYPE, 'extends', $token->getLine()), $parentToken, - new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', $token->getLine()), + new Token(Token::BLOCK_END_TYPE, '', $token->getLine()), ]); $module = $this->parser->parse($stream, [$this, 'decideBlockEnd'], true); @@ -48,12 +54,12 @@ class Twig_TokenParser_Embed extends \Twig\TokenParser\IncludeTokenParser $this->parser->embedTemplate($module); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + return new EmbedNode($module->getTemplateName(), $module->getAttribute('index'), $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endembed'); } diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php index cb1c5fda3..ced7c08b6 100644 --- a/lib/Twig/TokenParser/Extends.php +++ b/lib/Twig/TokenParser/Extends.php @@ -10,6 +10,10 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Error\SyntaxError; +use Twig\Token; + /** * Extends a template by another one. * @@ -17,22 +21,22 @@ * * @final */ -class Twig_TokenParser_Extends extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Extends extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $stream = $this->parser->getStream(); if (!$this->parser->isMainScope()) { - throw new \Twig\Error\SyntaxError('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError('Cannot extend from a block.', $token->getLine(), $stream->getSourceContext()); } if (null !== $this->parser->getParent()) { - throw new \Twig\Error\SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError('Multiple extends tags are forbidden.', $token->getLine(), $stream->getSourceContext()); } $this->parser->setParent($this->parser->getExpressionParser()->parseExpression()); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); } public function getTag() diff --git a/lib/Twig/TokenParser/Filter.php b/lib/Twig/TokenParser/Filter.php index ebb6cd99c..e25bdd21e 100644 --- a/lib/Twig/TokenParser/Filter.php +++ b/lib/Twig/TokenParser/Filter.php @@ -9,6 +9,13 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\BlockNode; +use Twig\Node\PrintNode; +use Twig\Token; + /** * Filters a section of a template by applying filters. * @@ -18,26 +25,26 @@ * * @final */ -class Twig_TokenParser_Filter extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Filter extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $name = $this->parser->getVarName(); - $ref = new \Twig\Node\Expression\BlockReferenceExpression(new \Twig\Node\Expression\ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag()); + $ref = new BlockReferenceExpression(new ConstantExpression($name, $token->getLine()), null, $token->getLine(), $this->getTag()); $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - $block = new \Twig\Node\BlockNode($name, $body, $token->getLine()); + $block = new BlockNode($name, $body, $token->getLine()); $this->parser->setBlock($name, $block); - return new \Twig\Node\PrintNode($filter, $token->getLine(), $this->getTag()); + return new PrintNode($filter, $token->getLine(), $this->getTag()); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endfilter'); } diff --git a/lib/Twig/TokenParser/Flush.php b/lib/Twig/TokenParser/Flush.php index 67db2d87a..c43142b59 100644 --- a/lib/Twig/TokenParser/Flush.php +++ b/lib/Twig/TokenParser/Flush.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\FlushNode; +use Twig\Token; + /** * Flushes the output to the client. * @@ -16,13 +20,13 @@ * * @final */ -class Twig_TokenParser_Flush extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Flush extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\FlushNode($token->getLine(), $this->getTag()); + return new FlushNode($token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 6518a2519..212b16f7c 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -10,6 +10,16 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\ForNode; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Error\SyntaxError; +use Twig\Node\Expression\ConstantExpression; +use Twig\Token; +use Twig\TokenStream; + /** * Loops over each item of a sequence. * @@ -21,40 +31,40 @@ * * @final */ -class Twig_TokenParser_For extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_For extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $targets = $this->parser->getExpressionParser()->parseAssignmentExpression(); - $stream->expect(\Twig\Token::OPERATOR_TYPE, 'in'); + $stream->expect(Token::OPERATOR_TYPE, 'in'); $seq = $this->parser->getExpressionParser()->parseExpression(); $ifexpr = null; - if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'if')) { + if ($stream->nextIf(Token::NAME_TYPE, 'if')) { $ifexpr = $this->parser->getExpressionParser()->parseExpression(); } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideForFork']); if ('else' == $stream->next()->getValue()) { - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $else = $this->parser->subparse([$this, 'decideForEnd'], true); } else { $else = null; } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); if (\count($targets) > 1) { $keyTarget = $targets->getNode(0); - $keyTarget = new \Twig\Node\Expression\AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); + $keyTarget = new AssignNameExpression($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); $valueTarget = $targets->getNode(1); - $valueTarget = new \Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); } else { - $keyTarget = new \Twig\Node\Expression\AssignNameExpression('_key', $lineno); + $keyTarget = new AssignNameExpression('_key', $lineno); $valueTarget = $targets->getNode(0); - $valueTarget = new \Twig\Node\Expression\AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); + $valueTarget = new AssignNameExpression($valueTarget->getAttribute('name'), $valueTarget->getTemplateLine()); } if ($ifexpr) { @@ -62,24 +72,24 @@ class Twig_TokenParser_For extends \Twig\TokenParser\AbstractTokenParser $this->checkLoopUsageBody($stream, $body); } - return new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); + return new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, $lineno, $this->getTag()); } - public function decideForFork(\Twig\Token $token) + public function decideForFork(Token $token) { return $token->test(['else', 'endfor']); } - public function decideForEnd(\Twig\Token $token) + public function decideForEnd(Token $token) { return $token->test('endfor'); } // the loop variable cannot be used in the condition - protected function checkLoopUsageCondition(\Twig\TokenStream $stream, Twig_NodeInterface $node) + protected function checkLoopUsageCondition(TokenStream $stream, Twig_NodeInterface $node) { - if ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { - throw new \Twig\Error\SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); + if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + throw new SyntaxError('The "loop" variable cannot be used in a looping condition.', $node->getTemplateLine(), $stream->getSourceContext()); } foreach ($node as $n) { @@ -93,17 +103,17 @@ class Twig_TokenParser_For extends \Twig\TokenParser\AbstractTokenParser // check usage of non-defined loop-items // it does not catch all problems (for instance when a for is included into another or when the variable is used in an include) - protected function checkLoopUsageBody(\Twig\TokenStream $stream, Twig_NodeInterface $node) + protected function checkLoopUsageBody(TokenStream $stream, Twig_NodeInterface $node) { - if ($node instanceof \Twig\Node\Expression\GetAttrExpression && $node->getNode('node') instanceof \Twig\Node\Expression\NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { + if ($node instanceof GetAttrExpression && $node->getNode('node') instanceof NameExpression && 'loop' == $node->getNode('node')->getAttribute('name')) { $attribute = $node->getNode('attribute'); - if ($attribute instanceof \Twig\Node\Expression\ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { - throw new \Twig\Error\SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); + if ($attribute instanceof ConstantExpression && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { + throw new SyntaxError(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); } } // should check for parent.loop.XXX usage - if ($node instanceof \Twig\Node\ForNode) { + if ($node instanceof ForNode) { return; } diff --git a/lib/Twig/TokenParser/From.php b/lib/Twig/TokenParser/From.php index 50f7b5d4c..bb453cb52 100644 --- a/lib/Twig/TokenParser/From.php +++ b/lib/Twig/TokenParser/From.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\ImportNode; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Error\SyntaxError; +use Twig\Token; + /** * Imports macros. * @@ -16,9 +22,9 @@ * * @final */ -class Twig_TokenParser_From extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_From extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $macro = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); @@ -26,27 +32,27 @@ class Twig_TokenParser_From extends \Twig\TokenParser\AbstractTokenParser $targets = []; do { - $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); $alias = $name; if ($stream->nextIf('as')) { - $alias = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $alias = $stream->expect(Token::NAME_TYPE)->getValue(); } $targets[$name] = $alias; - if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { break; } } while (true); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - $node = new \Twig\Node\ImportNode($macro, new \Twig\Node\Expression\AssignNameExpression($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); + $node = new ImportNode($macro, new AssignNameExpression($this->parser->getVarName(), $token->getLine()), $token->getLine(), $this->getTag()); foreach ($targets as $name => $alias) { if ($this->parser->isReservedMacroName($name)) { - throw new \Twig\Error\SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('"%s" cannot be an imported macro as it is a reserved keyword.', $name), $token->getLine(), $stream->getSourceContext()); } $this->parser->addImportedSymbol('function', $alias, 'get'.$name, $node->getNode('var')); diff --git a/lib/Twig/TokenParser/If.php b/lib/Twig/TokenParser/If.php index a26d0839e..be49393bd 100644 --- a/lib/Twig/TokenParser/If.php +++ b/lib/Twig/TokenParser/If.php @@ -10,6 +10,12 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Error\SyntaxError; +use Twig\Node\IfNode; +use Twig\Node\Node; +use Twig\Token; + /** * Tests a condition. * @@ -23,14 +29,14 @@ * * @final */ -class Twig_TokenParser_If extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_If extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $expr = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideIfFork']); $tests = [$expr, $body]; $else = null; @@ -39,13 +45,13 @@ class Twig_TokenParser_If extends \Twig\TokenParser\AbstractTokenParser while (!$end) { switch ($stream->next()->getValue()) { case 'else': - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $else = $this->parser->subparse([$this, 'decideIfEnd']); break; case 'elseif': $expr = $this->parser->getExpressionParser()->parseExpression(); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideIfFork']); $tests[] = $expr; $tests[] = $body; @@ -56,21 +62,21 @@ class Twig_TokenParser_If extends \Twig\TokenParser\AbstractTokenParser break; default: - throw new \Twig\Error\SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('Unexpected end of template. Twig was looking for the following tags "else", "elseif", or "endif" to close the "if" block started at line %d).', $lineno), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\IfNode(new \Twig\Node\Node($tests), $else, $lineno, $this->getTag()); + return new IfNode(new Node($tests), $else, $lineno, $this->getTag()); } - public function decideIfFork(\Twig\Token $token) + public function decideIfFork(Token $token) { return $token->test(['elseif', 'else', 'endif']); } - public function decideIfEnd(\Twig\Token $token) + public function decideIfEnd(Token $token) { return $token->test(['endif']); } diff --git a/lib/Twig/TokenParser/Import.php b/lib/Twig/TokenParser/Import.php index 3b5dd9ae4..f9dfbf13f 100644 --- a/lib/Twig/TokenParser/Import.php +++ b/lib/Twig/TokenParser/Import.php @@ -9,6 +9,11 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\ImportNode; +use Twig\Token; + /** * Imports macros. * @@ -16,18 +21,18 @@ * * @final */ -class Twig_TokenParser_Import extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Import extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $macro = $this->parser->getExpressionParser()->parseExpression(); $this->parser->getStream()->expect('as'); - $var = new \Twig\Node\Expression\AssignNameExpression($this->parser->getStream()->expect(\Twig\Token::NAME_TYPE)->getValue(), $token->getLine()); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $var = new AssignNameExpression($this->parser->getStream()->expect(Token::NAME_TYPE)->getValue(), $token->getLine()); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); $this->parser->addImportedSymbol('template', $var->getAttribute('name')); - return new \Twig\Node\ImportNode($macro, $var, $token->getLine(), $this->getTag()); + return new ImportNode($macro, $var, $token->getLine(), $this->getTag()); } public function getTag() diff --git a/lib/Twig/TokenParser/Include.php b/lib/Twig/TokenParser/Include.php index a673a0663..49d88e79e 100644 --- a/lib/Twig/TokenParser/Include.php +++ b/lib/Twig/TokenParser/Include.php @@ -10,6 +10,10 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\IncludeNode; +use Twig\Token; + /** * Includes a template. * @@ -17,15 +21,15 @@ * Body * {% include 'footer.html' %} */ -class Twig_TokenParser_Include extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Include extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); list($variables, $only, $ignoreMissing) = $this->parseArguments(); - return new \Twig\Node\IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); + return new IncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); } protected function parseArguments() @@ -33,23 +37,23 @@ class Twig_TokenParser_Include extends \Twig\TokenParser\AbstractTokenParser $stream = $this->parser->getStream(); $ignoreMissing = false; - if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'ignore')) { - $stream->expect(\Twig\Token::NAME_TYPE, 'missing'); + if ($stream->nextIf(Token::NAME_TYPE, 'ignore')) { + $stream->expect(Token::NAME_TYPE, 'missing'); $ignoreMissing = true; } $variables = null; - if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'with')) { + if ($stream->nextIf(Token::NAME_TYPE, 'with')) { $variables = $this->parser->getExpressionParser()->parseExpression(); } $only = false; - if ($stream->nextIf(\Twig\Token::NAME_TYPE, 'only')) { + if ($stream->nextIf(Token::NAME_TYPE, 'only')) { $only = true; } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); return [$variables, $only, $ignoreMissing]; } diff --git a/lib/Twig/TokenParser/Macro.php b/lib/Twig/TokenParser/Macro.php index e0462c76f..946e94543 100644 --- a/lib/Twig/TokenParser/Macro.php +++ b/lib/Twig/TokenParser/Macro.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Error\SyntaxError; +use Twig\Node\MacroNode; +use Twig\Node\BodyNode; +use Twig\Token; + /** * Defines a macro. * @@ -18,33 +24,33 @@ * * @final */ -class Twig_TokenParser_Macro extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Macro extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); - $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); $arguments = $this->parser->getExpressionParser()->parseArguments(true, true); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $this->parser->pushLocalScope(); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - if ($token = $stream->nextIf(\Twig\Token::NAME_TYPE)) { + if ($token = $stream->nextIf(Token::NAME_TYPE)) { $value = $token->getValue(); if ($value != $name) { - throw new \Twig\Error\SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('Expected endmacro for macro "%s" (but "%s" given).', $name, $value), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } $this->parser->popLocalScope(); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - $this->parser->setMacro($name, new \Twig\Node\MacroNode($name, new \Twig\Node\BodyNode([$body]), $arguments, $lineno, $this->getTag())); + $this->parser->setMacro($name, new MacroNode($name, new BodyNode([$body]), $arguments, $lineno, $this->getTag())); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endmacro'); } diff --git a/lib/Twig/TokenParser/Sandbox.php b/lib/Twig/TokenParser/Sandbox.php index 9adfb0938..06da84224 100644 --- a/lib/Twig/TokenParser/Sandbox.php +++ b/lib/Twig/TokenParser/Sandbox.php @@ -9,6 +9,13 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\IncludeNode; +use Twig\Node\TextNode; +use Twig\Error\SyntaxError; +use Twig\Node\SandboxNode; +use Twig\Token; + /** * Marks a section of a template as untrusted code that must be evaluated in the sandbox mode. * @@ -20,32 +27,32 @@ * * @final */ -class Twig_TokenParser_Sandbox extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Sandbox extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $stream = $this->parser->getStream(); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); // in a sandbox tag, only include tags are allowed - if (!$body instanceof \Twig\Node\IncludeNode) { + if (!$body instanceof IncludeNode) { foreach ($body as $node) { - if ($node instanceof \Twig\Node\TextNode && ctype_space($node->getAttribute('data'))) { + if ($node instanceof TextNode && ctype_space($node->getAttribute('data'))) { continue; } - if (!$node instanceof \Twig\Node\IncludeNode) { - throw new \Twig\Error\SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); + if (!$node instanceof IncludeNode) { + throw new SyntaxError('Only "include" tags are allowed within a "sandbox" section.', $node->getTemplateLine(), $stream->getSourceContext()); } } } - return new \Twig\Node\SandboxNode($body, $token->getLine(), $this->getTag()); + return new SandboxNode($body, $token->getLine(), $this->getTag()); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endsandbox'); } diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php index 55a45f83f..4006bd6f9 100644 --- a/lib/Twig/TokenParser/Set.php +++ b/lib/Twig/TokenParser/Set.php @@ -9,6 +9,11 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Error\SyntaxError; +use Twig\Node\SetNode; +use Twig\Token; + /** * Defines a variable. * @@ -21,40 +26,40 @@ * * @final */ -class Twig_TokenParser_Set extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Set extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); $stream = $this->parser->getStream(); $names = $this->parser->getExpressionParser()->parseAssignmentExpression(); $capture = false; - if ($stream->nextIf(\Twig\Token::OPERATOR_TYPE, '=')) { + if ($stream->nextIf(Token::OPERATOR_TYPE, '=')) { $values = $this->parser->getExpressionParser()->parseMultitargetExpression(); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); if (\count($names) !== \count($values)) { - throw new \Twig\Error\SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError('When using set, you must have the same number of variables and assignments.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } } else { $capture = true; if (\count($names) > 1) { - throw new \Twig\Error\SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + throw new SyntaxError('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $values = $this->parser->subparse([$this, 'decideBlockEnd'], true); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); } - return new \Twig\Node\SetNode($capture, $names, $values, $lineno, $this->getTag()); + return new SetNode($capture, $names, $values, $lineno, $this->getTag()); } - public function decideBlockEnd(\Twig\Token $token) + public function decideBlockEnd(Token $token) { return $token->test('endset'); } diff --git a/lib/Twig/TokenParser/Spaceless.php b/lib/Twig/TokenParser/Spaceless.php index 3b303ea5a..e6a2a0fec 100644 --- a/lib/Twig/TokenParser/Spaceless.php +++ b/lib/Twig/TokenParser/Spaceless.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\SpacelessNode; +use Twig\Token; + /** * Remove whitespaces between HTML tags. * @@ -21,20 +25,20 @@ * * @final */ -class Twig_TokenParser_Spaceless extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Spaceless extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $lineno = $token->getLine(); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideSpacelessEnd'], true); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\SpacelessNode($body, $lineno, $this->getTag()); + return new SpacelessNode($body, $lineno, $this->getTag()); } - public function decideSpacelessEnd(\Twig\Token $token) + public function decideSpacelessEnd(Token $token) { return $token->test('endspaceless'); } diff --git a/lib/Twig/TokenParser/Use.php b/lib/Twig/TokenParser/Use.php index 1a515e836..4e27f3783 100644 --- a/lib/Twig/TokenParser/Use.php +++ b/lib/Twig/TokenParser/Use.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\Expression\ConstantExpression; +use Twig\Error\SyntaxError; +use Twig\Node\Node; +use Twig\Token; + /** * Imports blocks defined in another template into the current template. * @@ -23,40 +29,40 @@ * * @final */ -class Twig_TokenParser_Use extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_Use extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $template = $this->parser->getExpressionParser()->parseExpression(); $stream = $this->parser->getStream(); - if (!$template instanceof \Twig\Node\Expression\ConstantExpression) { - throw new \Twig\Error\SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); + if (!$template instanceof ConstantExpression) { + throw new SyntaxError('The template references in a "use" statement must be a string.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $targets = []; if ($stream->nextIf('with')) { do { - $name = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $name = $stream->expect(Token::NAME_TYPE)->getValue(); $alias = $name; if ($stream->nextIf('as')) { - $alias = $stream->expect(\Twig\Token::NAME_TYPE)->getValue(); + $alias = $stream->expect(Token::NAME_TYPE)->getValue(); } - $targets[$name] = new \Twig\Node\Expression\ConstantExpression($alias, -1); + $targets[$name] = new ConstantExpression($alias, -1); - if (!$stream->nextIf(\Twig\Token::PUNCTUATION_TYPE, ',')) { + if (!$stream->nextIf(Token::PUNCTUATION_TYPE, ',')) { break; } } while (true); } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - $this->parser->addTrait(new \Twig\Node\Node(['template' => $template, 'targets' => new \Twig\Node\Node($targets)])); + $this->parser->addTrait(new Node(['template' => $template, 'targets' => new Node($targets)])); - return new \Twig\Node\Node(); + return new Node(); } public function getTag() diff --git a/lib/Twig/TokenParser/With.php b/lib/Twig/TokenParser/With.php index 66e55ace5..b8f8478fb 100644 --- a/lib/Twig/TokenParser/With.php +++ b/lib/Twig/TokenParser/With.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\WithNode; +use Twig\Token; + /** * Creates a nested scope. * @@ -16,29 +20,29 @@ * * @final */ -class Twig_TokenParser_With extends \Twig\TokenParser\AbstractTokenParser +class Twig_TokenParser_With extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { $stream = $this->parser->getStream(); $variables = null; $only = false; - if (!$stream->test(\Twig\Token::BLOCK_END_TYPE)) { + if (!$stream->test(Token::BLOCK_END_TYPE)) { $variables = $this->parser->getExpressionParser()->parseExpression(); - $only = $stream->nextIf(\Twig\Token::NAME_TYPE, 'only'); + $only = $stream->nextIf(Token::NAME_TYPE, 'only'); } - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); $body = $this->parser->subparse([$this, 'decideWithEnd'], true); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\WithNode($body, $variables, $only, $token->getLine(), $this->getTag()); + return new WithNode($body, $variables, $only, $token->getLine(), $this->getTag()); } - public function decideWithEnd(\Twig\Token $token) + public function decideWithEnd(Token $token) { return $token->test('endwith'); } diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php index 3e1871f48..8cca809b8 100644 --- a/lib/Twig/TokenParserBroker.php +++ b/lib/Twig/TokenParserBroker.php @@ -10,6 +10,8 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\TokenParserInterface; + /** * Default implementation of a token parser broker. * @@ -35,7 +37,7 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface } foreach ($parsers as $parser) { - if (!$parser instanceof \Twig\TokenParser\TokenParserInterface) { + if (!$parser instanceof TokenParserInterface) { throw new \LogicException('$parsers must a an array of Twig_TokenParserInterface.'); } $this->parsers[$parser->getTag()] = $parser; @@ -48,12 +50,12 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface } } - public function addTokenParser(\Twig\TokenParser\TokenParserInterface $parser) + public function addTokenParser(TokenParserInterface $parser) { $this->parsers[$parser->getTag()] = $parser; } - public function removeTokenParser(\Twig\TokenParser\TokenParserInterface $parser) + public function removeTokenParser(TokenParserInterface $parser) { $name = $parser->getTag(); if (isset($this->parsers[$name]) && $parser === $this->parsers[$name]) { @@ -80,7 +82,7 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface * * @param string $tag A tag name * - * @return \Twig\TokenParser\TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found + * @return TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found */ public function getTokenParser($tag) { diff --git a/lib/Twig/TokenParserBrokerInterface.php b/lib/Twig/TokenParserBrokerInterface.php index 10f79209b..f369264d9 100644 --- a/lib/Twig/TokenParserBrokerInterface.php +++ b/lib/Twig/TokenParserBrokerInterface.php @@ -10,6 +10,8 @@ * file that was distributed with this source code. */ +use Twig\TokenParser\TokenParserInterface; + /** * Interface implemented by token parser brokers. * @@ -26,7 +28,7 @@ interface Twig_TokenParserBrokerInterface * * @param string $tag A tag name * - * @return \Twig\TokenParser\TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found + * @return TokenParserInterface|null A Twig_TokenParserInterface or null if no suitable TokenParser was found */ public function getTokenParser($tag); diff --git a/lib/Twig/TokenParserInterface.php b/lib/Twig/TokenParserInterface.php index 2090ae187..82ca3125a 100644 --- a/lib/Twig/TokenParserInterface.php +++ b/lib/Twig/TokenParserInterface.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Error\SyntaxError; +use Twig\Parser; +use Twig\Token; + /** * Interface implemented by token parsers. * @@ -19,16 +23,16 @@ interface Twig_TokenParserInterface /** * Sets the parser associated with this token parser. */ - public function setParser(\Twig\Parser $parser); + public function setParser(Parser $parser); /** * Parses a token and returns a node. * * @return Twig_NodeInterface * - * @throws \Twig\Error\SyntaxError + * @throws SyntaxError */ - public function parse(\Twig\Token $token); + public function parse(Token $token); /** * Gets the tag name associated with this token parser. diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index 89b1fb711..7bafc0d4f 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -10,6 +10,10 @@ * file that was distributed with this source code. */ +use Twig\Source; +use Twig\Token; +use Twig\Error\SyntaxError; + /** * Represents a token stream. * @@ -32,11 +36,11 @@ class Twig_TokenStream */ public function __construct(array $tokens, $name = null, $source = null) { - if (!$name instanceof \Twig\Source) { + if (!$name instanceof Source) { if (null !== $name || null !== $source) { @trigger_error(sprintf('Passing a string as the $name argument of %s() is deprecated since version 1.27. Pass a Twig_Source instance instead.', __METHOD__), E_USER_DEPRECATED); } - $this->source = new \Twig\Source($source, $name); + $this->source = new Source($source, $name); } else { $this->source = $name; } @@ -60,12 +64,12 @@ class Twig_TokenStream /** * Sets the pointer to the next token and returns the old one. * - * @return \Twig\Token + * @return Token */ public function next() { if (!isset($this->tokens[++$this->current])) { - throw new \Twig\Error\SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current - 1]->getLine(), $this->source); } return $this->tokens[$this->current - 1]; @@ -74,7 +78,7 @@ class Twig_TokenStream /** * Tests a token, sets the pointer to the next one and returns it or throws a syntax error. * - * @return \Twig\Token|null The next token if the condition is true, null otherwise + * @return Token|null The next token if the condition is true, null otherwise */ public function nextIf($primary, $secondary = null) { @@ -86,17 +90,17 @@ class Twig_TokenStream /** * Tests a token and returns it or throws a syntax error. * - * @return \Twig\Token + * @return Token */ public function expect($type, $value = null, $message = null) { $token = $this->tokens[$this->current]; if (!$token->test($type, $value)) { $line = $token->getLine(); - throw new \Twig\Error\SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', + throw new SyntaxError(sprintf('%sUnexpected token "%s" of value "%s" ("%s" expected%s).', $message ? $message.'. ' : '', - \Twig\Token::typeToEnglish($token->getType()), $token->getValue(), - \Twig\Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), + Token::typeToEnglish($token->getType()), $token->getValue(), + Token::typeToEnglish($type), $value ? sprintf(' with value "%s"', $value) : ''), $line, $this->source ); @@ -111,12 +115,12 @@ class Twig_TokenStream * * @param int $number * - * @return \Twig\Token + * @return Token */ public function look($number = 1) { if (!isset($this->tokens[$this->current + $number])) { - throw new \Twig\Error\SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); + throw new SyntaxError('Unexpected end of template.', $this->tokens[$this->current + $number - 1]->getLine(), $this->source); } return $this->tokens[$this->current + $number]; @@ -139,11 +143,11 @@ class Twig_TokenStream */ public function isEOF() { - return \Twig\Token::EOF_TYPE === $this->tokens[$this->current]->getType(); + return Token::EOF_TYPE === $this->tokens[$this->current]->getType(); } /** - * @return \Twig\Token + * @return Token */ public function getCurrent() { @@ -183,7 +187,7 @@ class Twig_TokenStream /** * Gets the source associated with this stream. * - * @return \Twig\Source + * @return Source * * @internal */ diff --git a/lib/Twig/Util/DeprecationCollector.php b/lib/Twig/Util/DeprecationCollector.php index f4c2bd25e..2729f91a5 100644 --- a/lib/Twig/Util/DeprecationCollector.php +++ b/lib/Twig/Util/DeprecationCollector.php @@ -9,6 +9,11 @@ * file that was distributed with this source code. */ +use Twig\Util\TemplateDirIterator; +use Twig\Source; +use Twig\Environment; +use Twig\Error\SyntaxError; + /** * @author Fabien Potencier * @@ -19,7 +24,7 @@ class Twig_Util_DeprecationCollector private $twig; private $deprecations; - public function __construct(\Twig\Environment $twig) + public function __construct(Environment $twig) { $this->twig = $twig; } @@ -40,7 +45,7 @@ class Twig_Util_DeprecationCollector ), '{'.preg_quote($ext).'$}' ); - return $this->collect(new \Twig\Util\TemplateDirIterator($iterator)); + return $this->collect(new TemplateDirIterator($iterator)); } /** @@ -58,8 +63,8 @@ class Twig_Util_DeprecationCollector foreach ($iterator as $name => $contents) { try { - $this->twig->parse($this->twig->tokenize(new \Twig\Source($contents, $name))); - } catch (\Twig\Error\SyntaxError $e) { + $this->twig->parse($this->twig->tokenize(new Source($contents, $name))); + } catch (SyntaxError $e) { // ignore templates containing syntax errors } } diff --git a/test/Twig/Tests/Cache/FilesystemTest.php b/test/Twig/Tests/Cache/FilesystemTest.php index 9657a1adb..8ea464d63 100644 --- a/test/Twig/Tests/Cache/FilesystemTest.php +++ b/test/Twig/Tests/Cache/FilesystemTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Cache\FilesystemCache; + require_once \dirname(__DIR__).'/FilesystemHelper.php'; class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase @@ -22,7 +24,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase $nonce = hash('sha256', uniqid(mt_rand(), true)); $this->classname = '__Twig_Tests_Cache_FilesystemTest_Template_'.$nonce; $this->directory = sys_get_temp_dir().'/twig-test'; - $this->cache = new \Twig\Cache\FilesystemCache($this->directory); + $this->cache = new FilesystemCache($this->directory); } protected function tearDown() @@ -166,7 +168,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testGenerateKey($expected, $input) { - $cache = new \Twig\Cache\FilesystemCache($input); + $cache = new FilesystemCache($input); $this->assertRegExp($expected, $cache->generateKey('_test_', \get_class($this))); } diff --git a/test/Twig/Tests/CompilerTest.php b/test/Twig/Tests/CompilerTest.php index f02a0ce06..5191b28cb 100644 --- a/test/Twig/Tests/CompilerTest.php +++ b/test/Twig/Tests/CompilerTest.php @@ -9,11 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Compiler; +use Twig\Environment; + class Twig_Tests_CompilerTest extends \PHPUnit\Framework\TestCase { public function testReprNumericValueWithLocale() { - $compiler = new \Twig\Compiler(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $compiler = new Compiler(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $locale = setlocale(LC_NUMERIC, 0); if (false === $locale) { diff --git a/test/Twig/Tests/ContainerRuntimeLoaderTest.php b/test/Twig/Tests/ContainerRuntimeLoaderTest.php index 3eefcfb9a..1c04ef201 100644 --- a/test/Twig/Tests/ContainerRuntimeLoaderTest.php +++ b/test/Twig/Tests/ContainerRuntimeLoaderTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\RuntimeLoader\ContainerRuntimeLoader; + class Twig_Tests_ContainerRuntimeLoaderTest extends \PHPUnit\Framework\TestCase { /** @@ -20,7 +22,7 @@ class Twig_Tests_ContainerRuntimeLoaderTest extends \PHPUnit\Framework\TestCase $container->expects($this->once())->method('has')->with('stdClass')->willReturn(true); $container->expects($this->once())->method('get')->with('stdClass')->willReturn(new \stdClass()); - $loader = new \Twig\RuntimeLoader\ContainerRuntimeLoader($container); + $loader = new ContainerRuntimeLoader($container); $this->assertInstanceOf('stdClass', $loader->load('stdClass')); } @@ -34,7 +36,7 @@ class Twig_Tests_ContainerRuntimeLoaderTest extends \PHPUnit\Framework\TestCase $container->expects($this->once())->method('has')->with('Foo'); $container->expects($this->never())->method('get'); - $loader = new \Twig\RuntimeLoader\ContainerRuntimeLoader($container); + $loader = new ContainerRuntimeLoader($container); $this->assertNull($loader->load('Foo')); } } diff --git a/test/Twig/Tests/CustomExtensionTest.php b/test/Twig/Tests/CustomExtensionTest.php index 40dc3fe9e..650531373 100644 --- a/test/Twig/Tests/CustomExtensionTest.php +++ b/test/Twig/Tests/CustomExtensionTest.php @@ -9,13 +9,16 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Extension\ExtensionInterface; + class CustomExtensionTest extends \PHPUnit\Framework\TestCase { /** * @requires PHP 5.3 * @dataProvider provideInvalidExtensions */ - public function testGetInvalidOperators(\Twig\Extension\ExtensionInterface $extension, $expectedExceptionMessage) + public function testGetInvalidOperators(ExtensionInterface $extension, $expectedExceptionMessage) { if (method_exists($this, 'expectException')) { $this->expectException('InvalidArgumentException'); @@ -24,7 +27,7 @@ class CustomExtensionTest extends \PHPUnit\Framework\TestCase $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage); } - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $env->addExtension($extension); $env->getUnaryOperators(); } @@ -38,7 +41,7 @@ class CustomExtensionTest extends \PHPUnit\Framework\TestCase } } -class InvalidOperatorExtension implements \Twig\Extension\ExtensionInterface +class InvalidOperatorExtension implements ExtensionInterface { private $operators; @@ -47,7 +50,7 @@ class InvalidOperatorExtension implements \Twig\Extension\ExtensionInterface $this->operators = $operators; } - public function initRuntime(\Twig\Environment $environment) + public function initRuntime(Environment $environment) { } diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index e63a42e00..5387300ff 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -9,6 +9,21 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Loader\ArrayLoader; +use Twig\Source; +use Twig\Cache\FilesystemCache; +use Twig\Extension\AbstractExtension; +use Twig\Extension\GlobalsInterface; +use Twig\TwigFilter; +use Twig\TwigTest; +use Twig\TwigFunction; +use Twig\TokenParser\AbstractTokenParser; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Extension\InitRuntimeInterface; +use Twig\Loader\LoaderInterface; +use Twig\Token; + require_once __DIR__.'/FilesystemHelper.php'; class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase @@ -20,7 +35,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testLegacyTokenizeSignature() { - $env = new \Twig\Environment(); + $env = new Environment(); $stream = $env->tokenize('{{ foo }}', 'foo'); $this->assertEquals('{{ foo }}', $stream->getSource()); $this->assertEquals('foo', $stream->getFilename()); @@ -31,8 +46,8 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testLegacyCompileSourceSignature() { - $loader = new \Twig\Loader\ArrayLoader(['foo' => '{{ foo }}']); - $env = new \Twig\Environment($loader); + $loader = new ArrayLoader(['foo' => '{{ foo }}']); + $env = new Environment($loader); $this->assertContains('getTemplateName', $env->compileSource('{{ foo }}', 'foo')); } @@ -43,18 +58,18 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testRenderNoLoader() { - $env = new \Twig\Environment(); + $env = new Environment(); $env->render('test'); } public function testAutoescapeOption() { - $loader = new \Twig\Loader\ArrayLoader([ + $loader = new ArrayLoader([ 'html' => '{{ foo }} {{ foo }}', 'js' => '{{ bar }} {{ bar }}', ]); - $twig = new \Twig\Environment($loader, [ + $twig = new Environment($loader, [ 'debug' => true, 'cache' => false, 'autoescape' => [$this, 'escapingStrategyCallback'], @@ -74,11 +89,11 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase // to be removed in 2.0 $loader = $this->getMockBuilder('Twig_EnvironmentTestLoaderInterface')->getMock(); //$loader = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock(); - $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new \Twig\Source('', ''))); + $loader->expects($this->any())->method('getSourceContext')->will($this->returnValue(new Source('', ''))); // globals can be added after calling getGlobals - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->addGlobal('foo', 'bar'); @@ -86,7 +101,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $this->assertEquals('bar', $globals['foo']); // globals can be modified after a template has been loaded - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->loadTemplate('index'); @@ -95,7 +110,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $this->assertEquals('bar', $globals['foo']); // globals can be modified after extensions init - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -104,8 +119,8 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $this->assertEquals('bar', $globals['foo']); // globals can be modified after extensions and a template has been loaded - $arrayLoader = new \Twig\Loader\ArrayLoader(['index' => '{{foo}}']); - $twig = new \Twig\Environment($arrayLoader); + $arrayLoader = new ArrayLoader(['index' => '{{foo}}']); + $twig = new Environment($arrayLoader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -114,7 +129,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $globals = $twig->getGlobals(); $this->assertEquals('bar', $globals['foo']); - $twig = new \Twig\Environment($arrayLoader); + $twig = new Environment($arrayLoader); $twig->getGlobals(); $twig->addGlobal('foo', 'bar'); $template = $twig->loadTemplate('index'); @@ -122,7 +137,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase /* to be uncomment in Twig 2.0 // globals cannot be added after a template has been loaded - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->loadTemplate('index'); @@ -134,7 +149,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase } // globals cannot be added after extensions init - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -146,7 +161,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase } // globals cannot be added after extensions and a template has been loaded - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addGlobal('foo', 'foo'); $twig->getGlobals(); $twig->getFunctions(); @@ -159,7 +174,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase } // test adding globals after a template has been loaded without call to getGlobals - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->loadTemplate('index'); try { $twig->addGlobal('bar', 'bar'); @@ -172,14 +187,14 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() { - $cache = new \Twig\Cache\FilesystemCache($dir = sys_get_temp_dir().'/twig'); + $cache = new FilesystemCache($dir = sys_get_temp_dir().'/twig'); $options = ['cache' => $cache, 'auto_reload' => false, 'debug' => false]; // force compilation - $twig = new \Twig\Environment($loader = new \Twig\Loader\ArrayLoader(['index' => '{{ foo }}']), $options); + $twig = new Environment($loader = new ArrayLoader(['index' => '{{ foo }}']), $options); $key = $cache->generateKey('index', $twig->getTemplateClass('index')); - $cache->write($key, $twig->compileSource(new \Twig\Source('{{ foo }}', 'index'))); + $cache->write($key, $twig->compileSource(new Source('{{ foo }}', 'index'))); // check that extensions won't be initialized when rendering a template that is already in the cache $twig = $this @@ -205,7 +220,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock(); $loader = $this->getMockLoader($templateName, $templateContent); - $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); + $twig = new Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); // Cache miss: getTimestamp returns 0 and as a result the load() is // skipped. @@ -232,7 +247,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock(); $loader = $this->getMockLoader($templateName, $templateContent); - $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); + $twig = new Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); $now = time(); @@ -260,7 +275,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase $cache = $this->getMockBuilder('\Twig\Cache\CacheInterface')->getMock(); $loader = $this->getMockLoader($templateName, $templateContent); - $twig = new \Twig\Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); + $twig = new Environment($loader, ['cache' => $cache, 'auto_reload' => true, 'debug' => false]); $now = time(); @@ -286,7 +301,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testHasGetExtensionWithDynamicName() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $ext1 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext1'); $ext2 = new Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName('ext2'); @@ -304,7 +319,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase public function testHasGetExtensionByClassName() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension($ext = new Twig_Tests_EnvironmentTest_Extension()); $this->assertTrue($twig->hasExtension('Twig_Tests_EnvironmentTest_Extension')); $this->assertTrue($twig->hasExtension('\Twig_Tests_EnvironmentTest_Extension')); @@ -318,7 +333,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase public function testAddExtension() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension()); $this->assertArrayHasKey('test', $twig->getTags()); @@ -343,7 +358,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testAddExtensionWithDeprecatedGetGlobals() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithGlobals()); $this->deprecations = []; @@ -362,7 +377,7 @@ class Twig_Tests_EnvironmentTest extends \PHPUnit\Framework\TestCase */ public function testRemoveExtension() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName()); $twig->removeExtension('environment_test'); @@ -390,9 +405,9 @@ EOF ); $extension = new Twig_Tests_EnvironmentTest_ExtensionInEval(); - $loader = new \Twig\Loader\ArrayLoader(['page' => 'hey']); + $loader = new ArrayLoader(['page' => 'hey']); - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addExtension($extension); $this->assertInstanceOf('\Twig\Extension\ExtensionInterface', $twig->getExtension(\get_class($extension))); @@ -401,7 +416,7 @@ EOF public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime()); $twig->initRuntime(); @@ -415,7 +430,7 @@ EOF */ public function testInitRuntimeWithAnExtensionUsingInitRuntimeDeprecation() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime()); $this->deprecations = []; @@ -441,7 +456,7 @@ EOF */ public function testOverrideExtension() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime()); $this->deprecations = []; @@ -461,7 +476,7 @@ EOF $runtimeLoader = $this->getMockBuilder('\Twig\RuntimeLoader\RuntimeLoaderInterface')->getMock(); $runtimeLoader->expects($this->any())->method('load')->will($this->returnValue(new Twig_Tests_EnvironmentTest_Runtime())); - $loader = new \Twig\Loader\ArrayLoader([ + $loader = new ArrayLoader([ 'func_array' => '{{ from_runtime_array("foo") }}', 'func_array_default' => '{{ from_runtime_array() }}', 'func_array_named_args' => '{{ from_runtime_array(name="foo") }}', @@ -470,7 +485,7 @@ EOF 'func_string_named_args' => '{{ from_runtime_string(name="foo") }}', ]); - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $twig->addExtension(new Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime()); $twig->addRuntimeLoader($runtimeLoader); @@ -488,7 +503,7 @@ EOF */ public function testFailLoadTemplateOnCircularReference() { - $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ + $twig = new Environment(new ArrayLoader([ 'base.html.twig' => '{% extends "base.html.twig" %}', ])); @@ -501,7 +516,7 @@ EOF */ public function testFailLoadTemplateOnComplexCircularReference() { - $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ + $twig = new Environment(new ArrayLoader([ 'base1.html.twig' => '{% extends "base2.html.twig" %}', 'base2.html.twig' => '{% extends "base1.html.twig" %}', ])); @@ -517,7 +532,7 @@ EOF $loader->expects($this->any()) ->method('getSourceContext') ->with($templateName) - ->will($this->returnValue(new \Twig\Source($templateContent, $templateName))); + ->will($this->returnValue(new Source($templateContent, $templateName))); $loader->expects($this->any()) ->method('getCacheKey') ->with($templateName) @@ -527,7 +542,7 @@ EOF } } -class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends \Twig\Extension\AbstractExtension +class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends AbstractExtension { public function getGlobals() { @@ -537,7 +552,7 @@ class Twig_Tests_EnvironmentTest_Extension_WithGlobals extends \Twig\Extension\A } } -class Twig_Tests_EnvironmentTest_Extension extends \Twig\Extension\AbstractExtension implements \Twig\Extension\GlobalsInterface +class Twig_Tests_EnvironmentTest_Extension extends AbstractExtension implements GlobalsInterface { public function getTokenParsers() { @@ -556,21 +571,21 @@ class Twig_Tests_EnvironmentTest_Extension extends \Twig\Extension\AbstractExten public function getFilters() { return [ - new \Twig\TwigFilter('foo_filter', 'foo_filter'), + new TwigFilter('foo_filter', 'foo_filter'), ]; } public function getTests() { return [ - new \Twig\TwigTest('foo_test', 'foo_test'), + new TwigTest('foo_test', 'foo_test'), ]; } public function getFunctions() { return [ - new \Twig\TwigFunction('foo_function', 'foo_function'), + new TwigFunction('foo_function', 'foo_function'), ]; } @@ -591,7 +606,7 @@ class Twig_Tests_EnvironmentTest_Extension extends \Twig\Extension\AbstractExten } class_alias('Twig_Tests_EnvironmentTest_Extension', 'Twig\Tests\EnvironmentTest\Extension', false); -class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends \Twig\Extension\AbstractExtension +class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends AbstractExtension { public function getName() { @@ -599,7 +614,7 @@ class Twig_Tests_EnvironmentTest_Extension_WithDeprecatedName extends \Twig\Exte } } -class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends \Twig\Extension\AbstractExtension +class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends AbstractExtension { private $name; @@ -614,9 +629,9 @@ class Twig_Tests_EnvironmentTest_Extension_DynamicWithDeprecatedName extends \Tw } } -class Twig_Tests_EnvironmentTest_TokenParser extends \Twig\TokenParser\AbstractTokenParser +class Twig_Tests_EnvironmentTest_TokenParser extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { } @@ -626,14 +641,14 @@ class Twig_Tests_EnvironmentTest_TokenParser extends \Twig\TokenParser\AbstractT } } -class Twig_Tests_EnvironmentTest_NodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface +class Twig_Tests_EnvironmentTest_NodeVisitor implements NodeVisitorInterface { - public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) + public function enterNode(Twig_NodeInterface $node, Environment $env) { return $node; } - public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env) + public function leaveNode(Twig_NodeInterface $node, Environment $env) { return $node; } @@ -644,27 +659,27 @@ class Twig_Tests_EnvironmentTest_NodeVisitor implements \Twig\NodeVisitor\NodeVi } } -class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends \Twig\Extension\AbstractExtension +class Twig_Tests_EnvironmentTest_ExtensionWithDeprecationInitRuntime extends AbstractExtension { - public function initRuntime(\Twig\Environment $env) + public function initRuntime(Environment $env) { } } -class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends \Twig\Extension\AbstractExtension implements \Twig\Extension\InitRuntimeInterface +class Twig_Tests_EnvironmentTest_ExtensionWithoutDeprecationInitRuntime extends AbstractExtension implements InitRuntimeInterface { - public function initRuntime(\Twig\Environment $env) + public function initRuntime(Environment $env) { } } -class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends \Twig\Extension\AbstractExtension +class Twig_Tests_EnvironmentTest_ExtensionWithoutRuntime extends AbstractExtension { public function getFunctions() { return [ - new \Twig\TwigFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']), - new \Twig\TwigFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'), + new TwigFunction('from_runtime_array', ['Twig_Tests_EnvironmentTest_Runtime', 'fromRuntime']), + new TwigFunction('from_runtime_string', 'Twig_Tests_EnvironmentTest_Runtime::fromRuntime'), ]; } @@ -683,6 +698,6 @@ class Twig_Tests_EnvironmentTest_Runtime } // to be removed in 2.0 -interface Twig_EnvironmentTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_EnvironmentTestLoaderInterface extends LoaderInterface, Twig_SourceContextLoaderInterface { } diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php index 2337e2399..4170eb7bd 100644 --- a/test/Twig/Tests/ErrorTest.php +++ b/test/Twig/Tests/ErrorTest.php @@ -9,27 +9,34 @@ * file that was distributed with this source code. */ +use Twig\Error\Error; +use Twig\Source; +use Twig\Loader\ArrayLoader; +use Twig\Environment; +use Twig\Loader\FilesystemLoader; +use Twig\Error\RuntimeError; + class Twig_Tests_ErrorTest extends \PHPUnit\Framework\TestCase { public function testErrorWithObjectFilename() { - $error = new \Twig\Error\Error('foo'); - $error->setSourceContext(new \Twig\Source('', new \SplFileInfo(__FILE__))); + $error = new Error('foo'); + $error->setSourceContext(new Source('', new \SplFileInfo(__FILE__))); $this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage()); } public function testErrorWithArrayFilename() { - $error = new \Twig\Error\Error('foo'); - $error->setSourceContext(new \Twig\Source('', ['foo' => 'bar'])); + $error = new Error('foo'); + $error->setSourceContext(new Source('', ['foo' => 'bar'])); $this->assertEquals('foo in {"foo":"bar"}', $error->getMessage()); } public function testTwigExceptionGuessWithMissingVarAndArrayLoader() { - $loader = new \Twig\Loader\ArrayLoader([ + $loader = new ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', 'index.html' => << true, 'debug' => true, 'cache' => false]); + $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render([]); $this->fail(); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertEquals('Variable "foo" does not exist in "index.html" at line 3.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -57,7 +64,7 @@ EOHTML public function testTwigExceptionGuessWithExceptionAndArrayLoader() { - $loader = new \Twig\Loader\ArrayLoader([ + $loader = new ArrayLoader([ 'base.html' => '{% block content %}{% endblock %}', 'index.html' => << true, 'debug' => true, 'cache' => false]); + $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $this->fail(); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -85,15 +92,15 @@ EOHTML public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader() { - $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Fixtures/errors'); - $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); + $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); + $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render([]); $this->fail(); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertEquals('Variable "foo" does not exist.', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -104,15 +111,15 @@ EOHTML public function testTwigExceptionGuessWithExceptionAndFilesystemLoader() { - $loader = new \Twig\Loader\FilesystemLoader(__DIR__.'/Fixtures/errors'); - $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); + $loader = new FilesystemLoader(__DIR__.'/Fixtures/errors'); + $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index.html'); try { $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $this->fail(); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage()); $this->assertEquals(3, $e->getTemplateLine()); $this->assertEquals('index.html', $e->getSourceContext()->getName()); @@ -126,8 +133,8 @@ EOHTML */ public function testTwigExceptionAddsFileAndLine($templates, $name, $line) { - $loader = new \Twig\Loader\ArrayLoader($templates); - $twig = new \Twig\Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); + $loader = new ArrayLoader($templates); + $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); $template = $twig->loadTemplate('index'); @@ -135,7 +142,7 @@ EOHTML $template->render([]); $this->fail(); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d.', $name, $line), $e->getMessage()); $this->assertEquals($line, $e->getTemplateLine()); $this->assertEquals($name, $e->getSourceContext()->getName()); @@ -145,7 +152,7 @@ EOHTML $template->render(['foo' => new Twig_Tests_ErrorTest_Foo()]); $this->fail(); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e->getMessage()); $this->assertEquals($line, $e->getTemplateLine()); $this->assertEquals($name, $e->getSourceContext()->getName()); diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php index 6982c66bf..e70716afb 100644 --- a/test/Twig/Tests/ExpressionParserTest.php +++ b/test/Twig/Tests/ExpressionParserTest.php @@ -9,6 +9,14 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Parser; +use Twig\Source; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\ConcatBinary; +use Twig\Node\Expression\NameExpression; + class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase { /** @@ -17,10 +25,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testCanOnlyAssignToNames($template) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); + $parser->parse($env->tokenize(new Source($template, 'index'))); } public function getFailingTestsForAssignment() @@ -46,9 +54,9 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testArrayExpression($template, $expected) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->tokenize(new \Twig\Source($template, '')); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $stream = $env->tokenize(new Source($template, '')); + $parser = new Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); } @@ -59,10 +67,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testArraySyntaxError($template) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); + $parser->parse($env->tokenize(new Source($template, 'index'))); } public function getFailingTestsForArray() @@ -77,73 +85,73 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase { return [ // simple array - ['{{ [1, 2] }}', new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression(0, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), + ['{{ [1, 2] }}', new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(2, 1), + new ConstantExpression(1, 1), + new ConstantExpression(2, 1), ], 1), ], // array with trailing , - ['{{ [1, 2, ] }}', new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression(0, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), + ['{{ [1, 2, ] }}', new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(2, 1), + new ConstantExpression(1, 1), + new ConstantExpression(2, 1), ], 1), ], // simple hash - ['{{ {"a": "b", "b": "c"} }}', new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression('a', 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), + ['{{ {"a": "b", "b": "c"} }}', new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('c', 1), + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), ], 1), ], // hash with trailing , - ['{{ {"a": "b", "b": "c", } }}', new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression('a', 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), + ['{{ {"a": "b", "b": "c", } }}', new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('c', 1), + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), ], 1), ], // hash in an array - ['{{ [1, {"a": "b", "b": "c"}] }}', new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression(0, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), + ['{{ [1, {"a": "b", "b": "c"}] }}', new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), - new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression('a', 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), + new ConstantExpression(1, 1), + new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('c', 1), + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), ], 1), ], 1), ], // array in a hash - ['{{ {"a": [1, 2], "b": "c"} }}', new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression('a', 1), - new \Twig\Node\Expression\ArrayExpression([ - new \Twig\Node\Expression\ConstantExpression(0, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), + ['{{ {"a": [1, 2], "b": "c"} }}', new ArrayExpression([ + new ConstantExpression('a', 1), + new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(1, 1), - new \Twig\Node\Expression\ConstantExpression(2, 1), + new ConstantExpression(1, 1), + new ConstantExpression(2, 1), ], 1), - new \Twig\Node\Expression\ConstantExpression('b', 1), - new \Twig\Node\Expression\ConstantExpression('c', 1), + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), ], 1), ], ]; @@ -154,9 +162,9 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); - $stream = $env->tokenize(new \Twig\Source('{{ "a" "b" }}', 'index')); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); + $stream = $env->tokenize(new Source('{{ "a" "b" }}', 'index')); + $parser = new Parser($env); $parser->parse($stream); } @@ -166,9 +174,9 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testStringExpression($template, $expected) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); - $stream = $env->tokenize(new \Twig\Source($template, '')); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); + $stream = $env->tokenize(new Source($template, '')); + $parser = new Parser($env); $this->assertEquals($expected, $parser->parse($stream)->getNode('body')->getNode(0)->getNode('expr')); } @@ -177,43 +185,43 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase { return [ [ - '{{ "foo" }}', new \Twig\Node\Expression\ConstantExpression('foo', 1), + '{{ "foo" }}', new ConstantExpression('foo', 1), ], [ - '{{ "foo #{bar}" }}', new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\ConstantExpression('foo ', 1), - new \Twig\Node\Expression\NameExpression('bar', 1), + '{{ "foo #{bar}" }}', new ConcatBinary( + new ConstantExpression('foo ', 1), + new NameExpression('bar', 1), 1 ), ], [ - '{{ "foo #{bar} baz" }}', new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\ConstantExpression('foo ', 1), - new \Twig\Node\Expression\NameExpression('bar', 1), + '{{ "foo #{bar} baz" }}', new ConcatBinary( + new ConcatBinary( + new ConstantExpression('foo ', 1), + new NameExpression('bar', 1), 1 ), - new \Twig\Node\Expression\ConstantExpression(' baz', 1), + new ConstantExpression(' baz', 1), 1 ), ], [ - '{{ "foo #{"foo #{bar} baz"} baz" }}', new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\ConstantExpression('foo ', 1), - new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\Binary\ConcatBinary( - new \Twig\Node\Expression\ConstantExpression('foo ', 1), - new \Twig\Node\Expression\NameExpression('bar', 1), + '{{ "foo #{"foo #{bar} baz"} baz" }}', new ConcatBinary( + new ConcatBinary( + new ConstantExpression('foo ', 1), + new ConcatBinary( + new ConcatBinary( + new ConstantExpression('foo ', 1), + new NameExpression('bar', 1), 1 ), - new \Twig\Node\Expression\ConstantExpression(' baz', 1), + new ConstantExpression(' baz', 1), 1 ), 1 ), - new \Twig\Node\Expression\ConstantExpression(' baz', 1), + new ConstantExpression(' baz', 1), 1 ), ], @@ -225,10 +233,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testAttributeCallDoesNotSupportNamedArguments() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{{ foo.bar(name="Foo") }}', 'index'))); + $parser->parse($env->tokenize(new Source('{{ foo.bar(name="Foo") }}', 'index'))); } /** @@ -236,10 +244,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testMacroCallDoesNotSupportNamedArguments() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index'))); + $parser->parse($env->tokenize(new Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index'))); } /** @@ -248,10 +256,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testMacroDefinitionDoesNotSupportNonNameVariableName() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{% macro foo("a") %}{% endmacro %}', 'index'))); + $parser->parse($env->tokenize(new Source('{% macro foo("a") %}{% endmacro %}', 'index'))); } /** @@ -261,10 +269,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); + $parser->parse($env->tokenize(new Source($template, 'index'))); } public function getMacroDefinitionDoesNotSupportNonConstantDefaultValues() @@ -280,10 +288,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testMacroDefinitionSupportsConstantDefaultValues($template) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source($template, 'index'))); + $parser->parse($env->tokenize(new Source($template, 'index'))); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -309,10 +317,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownFunction() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{{ cycl() }}', 'index'))); + $parser->parse($env->tokenize(new Source('{{ cycl() }}', 'index'))); } /** @@ -321,10 +329,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownFunctionWithoutSuggestions() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{{ foobar() }}', 'index'))); + $parser->parse($env->tokenize(new Source('{{ foobar() }}', 'index'))); } /** @@ -333,10 +341,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownFilter() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{{ 1|lowe }}', 'index'))); + $parser->parse($env->tokenize(new Source('{{ 1|lowe }}', 'index'))); } /** @@ -345,10 +353,10 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownFilterWithoutSuggestions() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{{ 1|foobar }}', 'index'))); + $parser->parse($env->tokenize(new Source('{{ 1|foobar }}', 'index'))); } /** @@ -357,9 +365,9 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownTest() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); - $stream = $env->tokenize(new \Twig\Source('{{ 1 is nul }}', 'index')); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); + $stream = $env->tokenize(new Source('{{ 1 is nul }}', 'index')); $parser->parse($stream); } @@ -369,9 +377,9 @@ class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownTestWithoutSuggestions() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $parser = new \Twig\Parser($env); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $parser = new Parser($env); - $parser->parse($env->tokenize(new \Twig\Source('{{ 1 is foobar }}', 'index'))); + $parser->parse($env->tokenize(new Source('{{ 1 is foobar }}', 'index'))); } } diff --git a/test/Twig/Tests/Extension/CoreTest.php b/test/Twig/Tests/Extension/CoreTest.php index a8b707b14..fdcb4fb06 100644 --- a/test/Twig/Tests/Extension/CoreTest.php +++ b/test/Twig/Tests/Extension/CoreTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Environment; + class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase { /** @@ -16,7 +18,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testRandomFunction($value, $expectedInArray) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); for ($i = 0; $i < 100; ++$i) { $this->assertTrue(\in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type @@ -62,18 +64,18 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase $max = mt_getrandmax(); for ($i = 0; $i < 100; ++$i) { - $val = twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $val = twig_random(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $this->assertTrue(\is_int($val) && $val >= 0 && $val <= $max); } } public function testRandomFunctionReturnsAsIs() { - $this->assertSame('', twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), '')); - $this->assertSame('', twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['charset' => null]), '')); + $this->assertSame('', twig_random(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), '')); + $this->assertSame('', twig_random(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['charset' => null]), '')); $instance = new \stdClass(); - $this->assertSame($instance, twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), $instance)); + $this->assertSame($instance, twig_random(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), $instance)); } /** @@ -81,7 +83,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testRandomFunctionOfEmptyArrayThrowsException() { - twig_random(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), []); + twig_random(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), []); } public function testRandomFunctionOnNonUTF8String() @@ -90,7 +92,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase $this->markTestSkipped('needs iconv or mbstring'); } - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->setCharset('ISO-8859-1'); $text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); @@ -106,7 +108,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase $this->markTestSkipped('needs iconv or mbstring'); } - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->setCharset('ISO-8859-1'); $input = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); @@ -120,7 +122,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testCustomEscaper($expected, $string, $strategy) { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $twig->getExtension('\Twig\Extension\CoreExtension')->setEscaper('foo', 'foo_escaper_for_test'); $this->assertSame($expected, twig_escape_filter($twig, $string, $strategy)); @@ -140,7 +142,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testUnknownCustomEscaper() { - twig_escape_filter(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), 'foo', 'bar'); + twig_escape_filter(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()), 'foo', 'bar'); } /** @@ -148,7 +150,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testTwigFirst($expected, $input) { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $this->assertSame($expected, twig_first($twig, $input)); } @@ -170,7 +172,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testTwigLast($expected, $input) { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $this->assertSame($expected, twig_last($twig, $input)); } @@ -243,7 +245,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase */ public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false) { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $this->assertSame($expected, twig_slice($twig, $input, $start, $length, $preserveKeys)); } diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php index 5e49f9f0c..49da23574 100644 --- a/test/Twig/Tests/Extension/SandboxTest.php +++ b/test/Twig/Tests/Extension/SandboxTest.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\Loader\ArrayLoader; +use Twig\Environment; +use Twig\Sandbox\SecurityPolicy; +use Twig\Extension\SandboxExtension; +use Twig\Sandbox\SecurityError; + class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { protected static $params; @@ -62,7 +68,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic1')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method is called'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('foo', $e->getMethodName(), 'Exception should be raised on the "foo" method'); @@ -75,7 +81,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic2')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed filter is called'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFilterError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFilterError'); $this->assertEquals('upper', $e->getFilterName(), 'Exception should be raised on the "upper" filter'); } @@ -87,7 +93,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic3')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed tag is used in the template'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); $this->assertEquals('if', $e->getTagName(), 'Exception should be raised on the "if" tag'); } @@ -99,7 +105,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic4')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed property is called in the template'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedPropertyError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedPropertyError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('bar', $e->getPropertyName(), 'Exception should be raised on the "bar" property'); @@ -112,7 +118,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic5')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('__tostring', $e->getMethodName(), 'Exception should be raised on the "__toString" method'); @@ -125,7 +131,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic6')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed method (__toString()) is called in the template'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedMethodError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedMethodError'); $this->assertEquals('FooObject', $e->getClassName(), 'Exception should be raised on the "FooObject" class'); $this->assertEquals('__tostring', $e->getMethodName(), 'Exception should be raised on the "__toString" method'); @@ -138,7 +144,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_basic7')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if an unallowed function is called in the template'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); $this->assertEquals('cycle', $e->getFunctionName(), 'Exception should be raised on the "cycle" function'); } @@ -150,7 +156,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('1_range_operator')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception if the unallowed range operator is called'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedFunctionError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedFunctionError'); $this->assertEquals('range', $e->getFunctionName(), 'Exception should be raised on the "range" function'); } @@ -241,7 +247,7 @@ class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase try { $twig->loadTemplate('3_basic')->render(self::$params); $this->fail('Sandbox throws a SecurityError exception when the included file is sandboxed'); - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { $this->assertInstanceOf('\Twig\Sandbox\SecurityNotAllowedTagError', $e, 'Exception should be an instance of Twig_Sandbox_SecurityNotAllowedTagError'); $this->assertEquals('sandbox', $e->getTagName()); } @@ -280,10 +286,10 @@ EOF protected function getEnvironment($sandboxed, $options, $templates, $tags = [], $filters = [], $methods = [], $properties = [], $functions = []) { - $loader = new \Twig\Loader\ArrayLoader($templates); - $twig = new \Twig\Environment($loader, array_merge(['debug' => true, 'cache' => false, 'autoescape' => false], $options)); - $policy = new \Twig\Sandbox\SecurityPolicy($tags, $filters, $methods, $properties, $functions); - $twig->addExtension(new \Twig\Extension\SandboxExtension($policy, $sandboxed)); + $loader = new ArrayLoader($templates); + $twig = new Environment($loader, array_merge(['debug' => true, 'cache' => false, 'autoescape' => false], $options)); + $policy = new SecurityPolicy($tags, $filters, $methods, $properties, $functions); + $twig->addExtension(new SandboxExtension($policy, $sandboxed)); return $twig; } diff --git a/test/Twig/Tests/FactoryRuntimeLoaderTest.php b/test/Twig/Tests/FactoryRuntimeLoaderTest.php index 59328eeea..47d62afc8 100644 --- a/test/Twig/Tests/FactoryRuntimeLoaderTest.php +++ b/test/Twig/Tests/FactoryRuntimeLoaderTest.php @@ -9,18 +9,20 @@ * file that was distributed with this source code. */ +use Twig\RuntimeLoader\FactoryRuntimeLoader; + class Twig_Tests_FactoryRuntimeLoaderTest extends \PHPUnit\Framework\TestCase { public function testLoad() { - $loader = new \Twig\RuntimeLoader\FactoryRuntimeLoader(['stdClass' => 'getRuntime']); + $loader = new FactoryRuntimeLoader(['stdClass' => 'getRuntime']); $this->assertInstanceOf('stdClass', $loader->load('stdClass')); } public function testLoadReturnsNullForUnmappedRuntime() { - $loader = new \Twig\RuntimeLoader\FactoryRuntimeLoader(); + $loader = new FactoryRuntimeLoader(); $this->assertNull($loader->load('stdClass')); } diff --git a/test/Twig/Tests/FileCachingTest.php b/test/Twig/Tests/FileCachingTest.php index 640f13b4a..aa41b8326 100644 --- a/test/Twig/Tests/FileCachingTest.php +++ b/test/Twig/Tests/FileCachingTest.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Loader\ArrayLoader; + require_once __DIR__.'/FilesystemHelper.php'; class Twig_Tests_FileCachingTest extends \PHPUnit\Framework\TestCase @@ -27,7 +30,7 @@ class Twig_Tests_FileCachingTest extends \PHPUnit\Framework\TestCase $this->markTestSkipped(sprintf('Unable to run the tests as "%s" is not writable.', $this->tmpDir)); } - $this->env = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => 'index', 'index2' => 'index2']), ['cache' => $this->tmpDir]); + $this->env = new Environment(new ArrayLoader(['index' => 'index', 'index2' => 'index2']), ['cache' => $this->tmpDir]); } protected function tearDown() diff --git a/test/Twig/Tests/FileExtensionEscapingStrategyTest.php b/test/Twig/Tests/FileExtensionEscapingStrategyTest.php index a6959744b..120d9ce7c 100644 --- a/test/Twig/Tests/FileExtensionEscapingStrategyTest.php +++ b/test/Twig/Tests/FileExtensionEscapingStrategyTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\FileExtensionEscapingStrategy; + class Twig_Tests_FileExtensionEscapingStrategyTest extends \PHPUnit\Framework\TestCase { /** @@ -16,7 +18,7 @@ class Twig_Tests_FileExtensionEscapingStrategyTest extends \PHPUnit\Framework\Te */ public function testGuess($strategy, $filename) { - $this->assertSame($strategy, \Twig\FileExtensionEscapingStrategy::guess($filename)); + $this->assertSame($strategy, FileExtensionEscapingStrategy::guess($filename)); } public function getGuessData() diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php index 1cef44929..acec89bf6 100644 --- a/test/Twig/Tests/IntegrationTest.php +++ b/test/Twig/Tests/IntegrationTest.php @@ -9,6 +9,20 @@ * file that was distributed with this source code. */ +use Twig\Test\IntegrationTestCase; +use Twig\Sandbox\SecurityPolicy; +use Twig\Extension\DebugExtension; +use Twig\Extension\SandboxExtension; +use Twig\Extension\StringLoaderExtension; +use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\PrintNode; +use Twig\Node\Expression\ConstantExpression; +use Twig\Extension\AbstractExtension; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; +use Twig\Token; + // This function is defined to check that escaping strategies // like html works even if a function with the same name is defined. function html() @@ -16,16 +30,16 @@ function html() return 'foo'; } -class Twig_Tests_IntegrationTest extends \Twig\Test\IntegrationTestCase +class Twig_Tests_IntegrationTest extends IntegrationTestCase { public function getExtensions() { - $policy = new \Twig\Sandbox\SecurityPolicy([], [], [], [], []); + $policy = new SecurityPolicy([], [], [], [], []); return [ - new \Twig\Extension\DebugExtension(), - new \Twig\Extension\SandboxExtension($policy, false), - new \Twig\Extension\StringLoaderExtension(), + new DebugExtension(), + new SandboxExtension($policy, false), + new StringLoaderExtension(), new TwigTestExtension(), ]; } @@ -109,13 +123,13 @@ class TwigTestFoo implements Iterator } } -class TwigTestTokenParser_§ extends \Twig\TokenParser\AbstractTokenParser +class TwigTestTokenParser_§ extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\PrintNode(new \Twig\Node\Expression\ConstantExpression('§', -1), -1); + return new PrintNode(new ConstantExpression('§', -1), -1); } public function getTag() @@ -124,7 +138,7 @@ class TwigTestTokenParser_§ extends \Twig\TokenParser\AbstractTokenParser } } -class TwigTestExtension extends \Twig\Extension\AbstractExtension +class TwigTestExtension extends AbstractExtension { public function getTokenParsers() { @@ -136,39 +150,39 @@ class TwigTestExtension extends \Twig\Extension\AbstractExtension public function getFilters() { return [ - new \Twig\TwigFilter('§', [$this, '§Filter']), - new \Twig\TwigFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]), - new \Twig\TwigFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]), - new \Twig\TwigFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]), - new \Twig\TwigFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]), - new \Twig\TwigFilter('static_call_string', 'TwigTestExtension::staticCall'), - new \Twig\TwigFilter('static_call_array', ['TwigTestExtension', 'staticCall']), - new \Twig\TwigFilter('magic_call', [$this, 'magicCall']), - new \Twig\TwigFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'), - new \Twig\TwigFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']), - new \Twig\TwigFilter('*_path', [$this, 'dynamic_path']), - new \Twig\TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']), + new TwigFilter('§', [$this, '§Filter']), + new TwigFilter('escape_and_nl2br', [$this, 'escape_and_nl2br'], ['needs_environment' => true, 'is_safe' => ['html']]), + new TwigFilter('nl2br', [$this, 'nl2br'], ['pre_escape' => 'html', 'is_safe' => ['html']]), + new TwigFilter('escape_something', [$this, 'escape_something'], ['is_safe' => ['something']]), + new TwigFilter('preserves_safety', [$this, 'preserves_safety'], ['preserves_safety' => ['html']]), + new TwigFilter('static_call_string', 'TwigTestExtension::staticCall'), + new TwigFilter('static_call_array', ['TwigTestExtension', 'staticCall']), + new TwigFilter('magic_call', [$this, 'magicCall']), + new TwigFilter('magic_call_string', 'TwigTestExtension::magicStaticCall'), + new TwigFilter('magic_call_array', ['TwigTestExtension', 'magicStaticCall']), + new TwigFilter('*_path', [$this, 'dynamic_path']), + new TwigFilter('*_foo_*_bar', [$this, 'dynamic_foo']), ]; } public function getFunctions() { return [ - new \Twig\TwigFunction('§', [$this, '§Function']), - new \Twig\TwigFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]), - new \Twig\TwigFunction('unsafe_br', [$this, 'br']), - new \Twig\TwigFunction('static_call_string', 'TwigTestExtension::staticCall'), - new \Twig\TwigFunction('static_call_array', ['TwigTestExtension', 'staticCall']), - new \Twig\TwigFunction('*_path', [$this, 'dynamic_path']), - new \Twig\TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']), + new TwigFunction('§', [$this, '§Function']), + new TwigFunction('safe_br', [$this, 'br'], ['is_safe' => ['html']]), + new TwigFunction('unsafe_br', [$this, 'br']), + new TwigFunction('static_call_string', 'TwigTestExtension::staticCall'), + new TwigFunction('static_call_array', ['TwigTestExtension', 'staticCall']), + new TwigFunction('*_path', [$this, 'dynamic_path']), + new TwigFunction('*_foo_*_bar', [$this, 'dynamic_foo']), ]; } public function getTests() { return [ - new \Twig\TwigTest('multi word', [$this, 'is_multi_word']), - new \Twig\TwigTest('test_*', [$this, 'dynamic_test']), + new TwigTest('multi word', [$this, 'is_multi_word']), + new TwigTest('test_*', [$this, 'dynamic_test']), ]; } diff --git a/test/Twig/Tests/LegacyIntegrationTest.php b/test/Twig/Tests/LegacyIntegrationTest.php index 578609546..c840f3e77 100644 --- a/test/Twig/Tests/LegacyIntegrationTest.php +++ b/test/Twig/Tests/LegacyIntegrationTest.php @@ -9,7 +9,10 @@ * file that was distributed with this source code. */ -class Twig_Tests_LegacyIntegrationTest extends \Twig\Test\IntegrationTestCase +use Twig\Test\IntegrationTestCase; +use Twig\Extension\AbstractExtension; + +class Twig_Tests_LegacyIntegrationTest extends IntegrationTestCase { public function getExtensions() { @@ -33,7 +36,7 @@ class Twig_Tests_LegacyIntegrationTest extends \Twig\Test\IntegrationTestCase } } -class LegacyTwigTestExtension extends \Twig\Extension\AbstractExtension +class LegacyTwigTestExtension extends AbstractExtension { public function getTests() { diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php index 8984c7f34..b67cda6ee 100644 --- a/test/Twig/Tests/LexerTest.php +++ b/test/Twig/Tests/LexerTest.php @@ -8,6 +8,11 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + +use Twig\Lexer; +use Twig\Environment; +use Twig\Source; +use Twig\Token; class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { /** @@ -15,7 +20,7 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase */ public function testLegacyConstructorSignature() { - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $stream = $lexer->tokenize('{{ foo }}', 'foo'); $this->assertEquals('foo', $stream->getFilename()); $this->assertEquals('{{ foo }}', $stream->getSource()); @@ -25,36 +30,36 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{% § %}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); - $stream->expect(\Twig\Token::BLOCK_START_TYPE); - $this->assertSame('§', $stream->expect(\Twig\Token::NAME_TYPE)->getValue()); + $stream->expect(Token::BLOCK_START_TYPE); + $this->assertSame('§', $stream->expect(Token::NAME_TYPE)->getValue()); } public function testNameLabelForFunction() { $template = '{{ §() }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $this->assertSame('§', $stream->expect(\Twig\Token::NAME_TYPE)->getValue()); + $stream->expect(Token::VAR_START_TYPE); + $this->assertSame('§', $stream->expect(Token::NAME_TYPE)->getValue()); } public function testBracketsNesting() { $template = '{{ {"a":{"b":"c"}} }}'; - $this->assertEquals(2, $this->countToken($template, \Twig\Token::PUNCTUATION_TYPE, '{')); - $this->assertEquals(2, $this->countToken($template, \Twig\Token::PUNCTUATION_TYPE, '}')); + $this->assertEquals(2, $this->countToken($template, Token::PUNCTUATION_TYPE, '{')); + $this->assertEquals(2, $this->countToken($template, Token::PUNCTUATION_TYPE, '}')); } protected function countToken($template, $type, $value = null) { - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); $count = 0; while (!$stream->isEOF()) { @@ -78,17 +83,17 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase ."baz\n" ."}}\n"; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); // foo\nbar\n - $this->assertSame(1, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine()); + $this->assertSame(1, $stream->expect(Token::TEXT_TYPE)->getLine()); // \n (after {% line %}) - $this->assertSame(10, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine()); + $this->assertSame(10, $stream->expect(Token::TEXT_TYPE)->getLine()); // {{ - $this->assertSame(11, $stream->expect(\Twig\Token::VAR_START_TYPE)->getLine()); + $this->assertSame(11, $stream->expect(Token::VAR_START_TYPE)->getLine()); // baz - $this->assertSame(12, $stream->expect(\Twig\Token::NAME_TYPE)->getLine()); + $this->assertSame(12, $stream->expect(Token::NAME_TYPE)->getLine()); } public function testLineDirectiveInline() @@ -98,23 +103,23 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase ."baz\n" ."}}\n"; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); // foo\nbar - $this->assertSame(1, $stream->expect(\Twig\Token::TEXT_TYPE)->getLine()); + $this->assertSame(1, $stream->expect(Token::TEXT_TYPE)->getLine()); // {{ - $this->assertSame(10, $stream->expect(\Twig\Token::VAR_START_TYPE)->getLine()); + $this->assertSame(10, $stream->expect(Token::VAR_START_TYPE)->getLine()); // baz - $this->assertSame(11, $stream->expect(\Twig\Token::NAME_TYPE)->getLine()); + $this->assertSame(11, $stream->expect(Token::NAME_TYPE)->getLine()); } public function testLongComments() { $template = '{# '.str_repeat('*', 100000).' #}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -125,8 +130,8 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{% verbatim %}'.str_repeat('*', 100000).'{% endverbatim %}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -137,8 +142,8 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{{ '.str_repeat('x', 100000).' }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -149,8 +154,8 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{% '.str_repeat('x', 100000).' %}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -161,8 +166,8 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{{ 922337203685477580700 }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); $stream->next(); $node = $stream->next(); $this->assertEquals('922337203685477580700', $node->getValue()); @@ -174,11 +179,11 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase "{{ 'foo \' bar' }}" => 'foo \' bar', '{{ "foo \" bar" }}' => 'foo " bar', ]; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); foreach ($tests as $template => $expected) { - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, $expected); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::VAR_START_TYPE); + $stream->expect(Token::STRING_TYPE, $expected); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -190,17 +195,17 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = 'foo {{ "bar #{ baz + 1 }" }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::TEXT_TYPE, 'foo '); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, 'bar '); - $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); - $stream->expect(\Twig\Token::NAME_TYPE, 'baz'); - $stream->expect(\Twig\Token::OPERATOR_TYPE, '+'); - $stream->expect(\Twig\Token::NUMBER_TYPE, '1'); - $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); - $stream->expect(\Twig\Token::VAR_END_TYPE); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::TEXT_TYPE, 'foo '); + $stream->expect(Token::VAR_START_TYPE); + $stream->expect(Token::STRING_TYPE, 'bar '); + $stream->expect(Token::INTERPOLATION_START_TYPE); + $stream->expect(Token::NAME_TYPE, 'baz'); + $stream->expect(Token::OPERATOR_TYPE, '+'); + $stream->expect(Token::NUMBER_TYPE, '1'); + $stream->expect(Token::INTERPOLATION_END_TYPE); + $stream->expect(Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -211,11 +216,11 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{{ "bar \#{baz+1}" }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, 'bar #{baz+1}'); - $stream->expect(\Twig\Token::VAR_END_TYPE); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::VAR_START_TYPE); + $stream->expect(Token::STRING_TYPE, 'bar #{baz+1}'); + $stream->expect(Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -226,11 +231,11 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{{ "bar # baz" }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, 'bar # baz'); - $stream->expect(\Twig\Token::VAR_END_TYPE); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::VAR_START_TYPE); + $stream->expect(Token::STRING_TYPE, 'bar # baz'); + $stream->expect(Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -245,25 +250,25 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{{ "bar #{x" }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); } public function testStringWithNestedInterpolations() { $template = '{{ "bar #{ "foo#{bar}" }" }}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, 'bar '); - $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, 'foo'); - $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); - $stream->expect(\Twig\Token::NAME_TYPE, 'bar'); - $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); - $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); - $stream->expect(\Twig\Token::VAR_END_TYPE); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::VAR_START_TYPE); + $stream->expect(Token::STRING_TYPE, 'bar '); + $stream->expect(Token::INTERPOLATION_START_TYPE); + $stream->expect(Token::STRING_TYPE, 'foo'); + $stream->expect(Token::INTERPOLATION_START_TYPE); + $stream->expect(Token::NAME_TYPE, 'bar'); + $stream->expect(Token::INTERPOLATION_END_TYPE); + $stream->expect(Token::INTERPOLATION_END_TYPE); + $stream->expect(Token::VAR_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -274,18 +279,18 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = '{% foo "bar #{ "foo#{bar}" }" %}'; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::BLOCK_START_TYPE); - $stream->expect(\Twig\Token::NAME_TYPE, 'foo'); - $stream->expect(\Twig\Token::STRING_TYPE, 'bar '); - $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); - $stream->expect(\Twig\Token::STRING_TYPE, 'foo'); - $stream->expect(\Twig\Token::INTERPOLATION_START_TYPE); - $stream->expect(\Twig\Token::NAME_TYPE, 'bar'); - $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); - $stream->expect(\Twig\Token::INTERPOLATION_END_TYPE); - $stream->expect(\Twig\Token::BLOCK_END_TYPE); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::BLOCK_START_TYPE); + $stream->expect(Token::NAME_TYPE, 'foo'); + $stream->expect(Token::STRING_TYPE, 'bar '); + $stream->expect(Token::INTERPOLATION_START_TYPE); + $stream->expect(Token::STRING_TYPE, 'foo'); + $stream->expect(Token::INTERPOLATION_START_TYPE); + $stream->expect(Token::NAME_TYPE, 'bar'); + $stream->expect(Token::INTERPOLATION_END_TYPE); + $stream->expect(Token::INTERPOLATION_END_TYPE); + $stream->expect(Token::BLOCK_END_TYPE); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -296,11 +301,11 @@ class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { $template = "{{ 1 and\n0}}"; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $stream = $lexer->tokenize(new \Twig\Source($template, 'index')); - $stream->expect(\Twig\Token::VAR_START_TYPE); - $stream->expect(\Twig\Token::NUMBER_TYPE, 1); - $stream->expect(\Twig\Token::OPERATOR_TYPE, 'and'); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $stream = $lexer->tokenize(new Source($template, 'index')); + $stream->expect(Token::VAR_START_TYPE); + $stream->expect(Token::NUMBER_TYPE, 1); + $stream->expect(Token::OPERATOR_TYPE, 'and'); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above // can be executed without throwing any exceptions @@ -322,8 +327,8 @@ bar '; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); } /** @@ -341,7 +346,7 @@ bar '; - $lexer = new \Twig\Lexer(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $lexer->tokenize(new \Twig\Source($template, 'index')); + $lexer = new Lexer(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $lexer->tokenize(new Source($template, 'index')); } } diff --git a/test/Twig/Tests/Loader/ArrayTest.php b/test/Twig/Tests/Loader/ArrayTest.php index bc9fa2ffa..6f308f597 100644 --- a/test/Twig/Tests/Loader/ArrayTest.php +++ b/test/Twig/Tests/Loader/ArrayTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Loader\ArrayLoader; + class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase { /** @@ -16,7 +18,7 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase */ public function testGetSource() { - $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); + $loader = new ArrayLoader(['foo' => 'bar']); $this->assertEquals('bar', $loader->getSource('foo')); } @@ -27,7 +29,7 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase */ public function testGetSourceWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ArrayLoader([]); + $loader = new ArrayLoader([]); $loader->getSource('foo'); } @@ -37,21 +39,21 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase */ public function testGetSourceContextWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ArrayLoader([]); + $loader = new ArrayLoader([]); $loader->getSourceContext('foo'); } public function testGetCacheKey() { - $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); + $loader = new ArrayLoader(['foo' => 'bar']); $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); } public function testGetCacheKeyWhenTemplateHasDuplicateContent() { - $loader = new \Twig\Loader\ArrayLoader([ + $loader = new ArrayLoader([ 'foo' => 'bar', 'baz' => 'bar', ]); @@ -62,7 +64,7 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase public function testGetCacheKeyIsProtectedFromEdgeCollisions() { - $loader = new \Twig\Loader\ArrayLoader([ + $loader = new ArrayLoader([ 'foo__' => 'bar', 'foo' => '__bar', ]); @@ -76,14 +78,14 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase */ public function testGetCacheKeyWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ArrayLoader([]); + $loader = new ArrayLoader([]); $loader->getCacheKey('foo'); } public function testSetTemplate() { - $loader = new \Twig\Loader\ArrayLoader([]); + $loader = new ArrayLoader([]); $loader->setTemplate('foo', 'bar'); $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode()); @@ -91,7 +93,7 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase public function testIsFresh() { - $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); + $loader = new ArrayLoader(['foo' => 'bar']); $this->assertTrue($loader->isFresh('foo', time())); } @@ -100,7 +102,7 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase */ public function testIsFreshWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ArrayLoader([]); + $loader = new ArrayLoader([]); $loader->isFresh('foo', time()); } @@ -108,7 +110,7 @@ class Twig_Tests_Loader_ArrayTest extends \PHPUnit\Framework\TestCase public function testTemplateReference() { $name = new Twig_Test_Loader_TemplateReference('foo'); - $loader = new \Twig\Loader\ArrayLoader(['foo' => 'bar']); + $loader = new ArrayLoader(['foo' => 'bar']); $loader->getCacheKey($name); $loader->getSourceContext($name); diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index 609a979b9..a2173a637 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -9,6 +9,12 @@ * file that was distributed with this source code. */ +use Twig\Loader\ChainLoader; +use Twig\Loader\ArrayLoader; +use Twig\Loader\FilesystemLoader; +use Twig\Source; +use Twig\Loader\LoaderInterface; + class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase { /** @@ -16,9 +22,9 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase */ public function testGetSource() { - $loader = new \Twig\Loader\ChainLoader([ - new \Twig\Loader\ArrayLoader(['foo' => 'bar']), - new \Twig\Loader\ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']), + $loader = new ChainLoader([ + new ArrayLoader(['foo' => 'bar']), + new ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']), ]); $this->assertEquals('bar', $loader->getSource('foo')); @@ -28,10 +34,10 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase public function testGetSourceContext() { $path = __DIR__.'/../Fixtures'; - $loader = new \Twig\Loader\ChainLoader([ - new \Twig\Loader\ArrayLoader(['foo' => 'bar']), - new \Twig\Loader\ArrayLoader(['errors/index.html' => 'baz']), - new \Twig\Loader\FilesystemLoader([$path]), + $loader = new ChainLoader([ + new ArrayLoader(['foo' => 'bar']), + new ArrayLoader(['errors/index.html' => 'baz']), + new FilesystemLoader([$path]), ]); $this->assertEquals('foo', $loader->getSourceContext('foo')->getName()); @@ -51,7 +57,7 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase */ public function testGetSourceContextWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ChainLoader([]); + $loader = new ChainLoader([]); $loader->getSourceContext('foo'); } @@ -62,16 +68,16 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase */ public function testGetSourceWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ChainLoader([]); + $loader = new ChainLoader([]); $loader->getSource('foo'); } public function testGetCacheKey() { - $loader = new \Twig\Loader\ChainLoader([ - new \Twig\Loader\ArrayLoader(['foo' => 'bar']), - new \Twig\Loader\ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']), + $loader = new ChainLoader([ + new ArrayLoader(['foo' => 'bar']), + new ArrayLoader(['foo' => 'foobar', 'bar' => 'foo']), ]); $this->assertEquals('foo:bar', $loader->getCacheKey('foo')); @@ -83,15 +89,15 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase */ public function testGetCacheKeyWhenTemplateDoesNotExist() { - $loader = new \Twig\Loader\ChainLoader([]); + $loader = new ChainLoader([]); $loader->getCacheKey('foo'); } public function testAddLoader() { - $loader = new \Twig\Loader\ChainLoader(); - $loader->addLoader(new \Twig\Loader\ArrayLoader(['foo' => 'bar'])); + $loader = new ChainLoader(); + $loader->addLoader(new ArrayLoader(['foo' => 'bar'])); $this->assertEquals('bar', $loader->getSourceContext('foo')->getCode()); } @@ -105,9 +111,9 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase // can be removed in 2.0 $loader2 = $this->getMockBuilder('Twig_ChainTestLoaderInterface')->getMock(); //$loader2 = $this->getMockBuilder(['\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface'])->getMock(); - $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new \Twig\Source('content', 'index'))); + $loader2->expects($this->once())->method('getSourceContext')->will($this->returnValue(new Source('content', 'index'))); - $loader = new \Twig\Loader\ChainLoader(); + $loader = new ChainLoader(); $loader->addLoader($loader1); $loader->addLoader($loader2); @@ -115,10 +121,10 @@ class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase } } -interface Twig_ChainTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_ChainTestLoaderInterface extends LoaderInterface, Twig_SourceContextLoaderInterface { } -interface Twig_ChainTestLoaderWithExistsInterface extends \Twig\Loader\LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_ChainTestLoaderWithExistsInterface extends LoaderInterface, Twig_ExistsLoaderInterface, Twig_SourceContextLoaderInterface { } diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index c9574cd98..2c8db82e2 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -9,12 +9,16 @@ * file that was distributed with this source code. */ +use Twig\Loader\FilesystemLoader; +use Twig\Environment; +use Twig\Error\LoaderError; + class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase { public function testGetSourceContext() { $path = __DIR__.'/../Fixtures'; - $loader = new \Twig\Loader\FilesystemLoader([$path]); + $loader = new FilesystemLoader([$path]); $this->assertEquals('errors/index.html', $loader->getSourceContext('errors/index.html')->getName()); $this->assertEquals(realpath($path.'/errors/index.html'), realpath($loader->getSourceContext('errors/index.html')->getPath())); } @@ -24,12 +28,12 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testSecurity($template) { - $loader = new \Twig\Loader\FilesystemLoader([__DIR__.'/../Fixtures']); + $loader = new FilesystemLoader([__DIR__.'/../Fixtures']); try { $loader->getCacheKey($template); $this->fail(); - } catch (\Twig\Error\LoaderError $e) { + } catch (LoaderError $e) { $this->assertNotContains('Unable to find template', $e->getMessage()); } } @@ -64,7 +68,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testPaths($basePath, $cacheKey, $rootPath) { - $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath); + $loader = new FilesystemLoader([$basePath.'/normal', $basePath.'/normal_bis'], $rootPath); $loader->setPaths([$basePath.'/named', $basePath.'/named_bis'], 'named'); $loader->addPath($basePath.'/named_ter', 'named'); $loader->addPath($basePath.'/normal_ter'); @@ -126,24 +130,24 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase public function testEmptyConstructor() { - $loader = new \Twig\Loader\FilesystemLoader(); + $loader = new FilesystemLoader(); $this->assertEquals([], $loader->getPaths()); } public function testGetNamespaces() { - $loader = new \Twig\Loader\FilesystemLoader(sys_get_temp_dir()); - $this->assertEquals([\Twig\Loader\FilesystemLoader::MAIN_NAMESPACE], $loader->getNamespaces()); + $loader = new FilesystemLoader(sys_get_temp_dir()); + $this->assertEquals([FilesystemLoader::MAIN_NAMESPACE], $loader->getNamespaces()); $loader->addPath(sys_get_temp_dir(), 'named'); - $this->assertEquals([\Twig\Loader\FilesystemLoader::MAIN_NAMESPACE, 'named'], $loader->getNamespaces()); + $this->assertEquals([FilesystemLoader::MAIN_NAMESPACE, 'named'], $loader->getNamespaces()); } public function testFindTemplateExceptionNamespace() { $basePath = __DIR__.'/Fixtures'; - $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal']); + $loader = new FilesystemLoader([$basePath.'/normal']); $loader->addPath($basePath.'/named', 'named'); try { @@ -158,7 +162,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase { $basePath = __DIR__.'/Fixtures'; - $loader = new \Twig\Loader\FilesystemLoader([$basePath.'/normal']); + $loader = new FilesystemLoader([$basePath.'/normal']); $loader->addPath($basePath.'/named', 'named'); // prime the cache for index.html in the named namespace @@ -171,12 +175,12 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase public function testLoadTemplateAndRenderBlockWithCache() { - $loader = new \Twig\Loader\FilesystemLoader([]); + $loader = new FilesystemLoader([]); $loader->addPath(__DIR__.'/Fixtures/themes/theme2'); $loader->addPath(__DIR__.'/Fixtures/themes/theme1'); $loader->addPath(__DIR__.'/Fixtures/themes/theme1', 'default_theme'); - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $template = $twig->loadTemplate('blocks.html.twig'); $this->assertSame('block from theme 1', $template->renderBlock('b1', [])); @@ -202,10 +206,10 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testArrayInheritance($templateName) { - $loader = new \Twig\Loader\FilesystemLoader([]); + $loader = new FilesystemLoader([]); $loader->addPath(__DIR__.'/Fixtures/inheritance'); - $twig = new \Twig\Environment($loader); + $twig = new Environment($loader); $template = $twig->loadTemplate($templateName); $this->assertSame('VALID Child', $template->renderBlock('body', [])); @@ -216,7 +220,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testLoadTemplateFromPhar() { - $loader = new \Twig\Loader\FilesystemLoader([]); + $loader = new FilesystemLoader([]); // phar-sample.phar was created with the following script: // $f = new Phar('phar-test.phar'); // $f->addFromString('hello.twig', 'hello from phar'); @@ -226,7 +230,7 @@ class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase public function testTemplateExistsAlwaysReturnsBool() { - $loader = new \Twig\Loader\FilesystemLoader([]); + $loader = new FilesystemLoader([]); $this->assertFalse($loader->exists("foo\0.twig")); $this->assertFalse($loader->exists('../foo.twig')); $this->assertFalse($loader->exists('@foo')); diff --git a/test/Twig/Tests/NativeExtensionTest.php b/test/Twig/Tests/NativeExtensionTest.php index 379132d77..6a122fa7f 100644 --- a/test/Twig/Tests/NativeExtensionTest.php +++ b/test/Twig/Tests/NativeExtensionTest.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Loader\ArrayLoader; + class Twig_Tests_NativeExtensionTest extends \PHPUnit\Framework\TestCase { /** @@ -20,7 +23,7 @@ class Twig_Tests_NativeExtensionTest extends \PHPUnit\Framework\TestCase $this->markTestSkipped('Extension is not available on PHP 7+'); } - $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader(['index' => '{{ d1.date }}{{ d2.date }}']), [ + $twig = new Environment(new ArrayLoader(['index' => '{{ d1.date }}{{ d2.date }}']), [ 'debug' => true, 'cache' => false, 'autoescape' => false, diff --git a/test/Twig/Tests/Node/AutoEscapeTest.php b/test/Twig/Tests/Node/AutoEscapeTest.php index 1eeddc457..6a50d69cd 100644 --- a/test/Twig/Tests/Node/AutoEscapeTest.php +++ b/test/Twig/Tests/Node/AutoEscapeTest.php @@ -9,12 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_AutoEscapeTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Node\AutoEscapeNode; + +class Twig_Tests_Node_AutoEscapeTest extends NodeTestCase { public function testConstructor() { - $body = new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)]); - $node = new \Twig\Node\AutoEscapeNode(true, $body, 1); + $body = new Node([new TextNode('foo', 1)]); + $node = new AutoEscapeNode(true, $body, 1); $this->assertEquals($body, $node->getNode('body')); $this->assertTrue($node->getAttribute('value')); @@ -22,8 +27,8 @@ class Twig_Tests_Node_AutoEscapeTest extends \Twig\Test\NodeTestCase public function getTests() { - $body = new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)]); - $node = new \Twig\Node\AutoEscapeNode(true, $body, 1); + $body = new Node([new TextNode('foo', 1)]); + $node = new AutoEscapeNode(true, $body, 1); return [ [$node, "// line 1\necho \"foo\";"], diff --git a/test/Twig/Tests/Node/BlockReferenceTest.php b/test/Twig/Tests/Node/BlockReferenceTest.php index de37e37f1..b20fd0a51 100644 --- a/test/Twig/Tests/Node/BlockReferenceTest.php +++ b/test/Twig/Tests/Node/BlockReferenceTest.php @@ -9,11 +9,14 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_BlockReferenceTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\BlockReferenceNode; + +class Twig_Tests_Node_BlockReferenceTest extends NodeTestCase { public function testConstructor() { - $node = new \Twig\Node\BlockReferenceNode('foo', 1); + $node = new BlockReferenceNode('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } @@ -21,7 +24,7 @@ class Twig_Tests_Node_BlockReferenceTest extends \Twig\Test\NodeTestCase public function getTests() { return [ - [new \Twig\Node\BlockReferenceNode('foo', 1), <<displayBlock('foo', \$context, \$blocks); EOF diff --git a/test/Twig/Tests/Node/BlockTest.php b/test/Twig/Tests/Node/BlockTest.php index d2256a6d8..d6ba624c5 100644 --- a/test/Twig/Tests/Node/BlockTest.php +++ b/test/Twig/Tests/Node/BlockTest.php @@ -9,12 +9,16 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_BlockTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\TextNode; +use Twig\Node\BlockNode; + +class Twig_Tests_Node_BlockTest extends NodeTestCase { public function testConstructor() { - $body = new \Twig\Node\TextNode('foo', 1); - $node = new \Twig\Node\BlockNode('foo', $body, 1); + $body = new TextNode('foo', 1); + $node = new BlockNode('foo', $body, 1); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals('foo', $node->getAttribute('name')); @@ -22,8 +26,8 @@ class Twig_Tests_Node_BlockTest extends \Twig\Test\NodeTestCase public function getTests() { - $body = new \Twig\Node\TextNode('foo', 1); - $node = new \Twig\Node\BlockNode('foo', $body, 1); + $body = new TextNode('foo', 1); + $node = new BlockNode('foo', $body, 1); return [ [$node, <<assertEquals($expr, $node->getNode('expr')); } @@ -23,8 +32,8 @@ class Twig_Tests_Node_DeprecatedTest extends \Twig\Test\NodeTestCase { $tests = []; - $expr = new \Twig\Node\Expression\ConstantExpression('This section is deprecated', 1); - $node = new \Twig\Node\DeprecatedNode($expr, 1, 'deprecated'); + $expr = new ConstantExpression('This section is deprecated', 1); + $node = new DeprecatedNode($expr, 1, 'deprecated'); $node->setTemplateName('foo.twig'); $tests[] = [$node, <<setTemplateName('foo.twig'); $tests[] = [$node, <<getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); - $environment->addFunction(new \Twig\TwigFunction('foo', 'foo', [])); + $environment = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addFunction(new TwigFunction('foo', 'foo', [])); - $expr = new \Twig\Node\Expression\FunctionExpression('foo', new \Twig\Node\Node(), 1); - $node = new \Twig\Node\DeprecatedNode($expr, 1, 'deprecated'); + $expr = new FunctionExpression('foo', new Node(), 1); + $node = new DeprecatedNode($expr, 1, 'deprecated'); $node->setTemplateName('foo.twig'); $compiler = $this->getCompiler($environment); diff --git a/test/Twig/Tests/Node/DoTest.php b/test/Twig/Tests/Node/DoTest.php index 6e60ab413..8cac0cb1f 100644 --- a/test/Twig/Tests/Node/DoTest.php +++ b/test/Twig/Tests/Node/DoTest.php @@ -9,12 +9,16 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_DoTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\DoNode; + +class Twig_Tests_Node_DoTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); - $node = new \Twig\Node\DoNode($expr, 1); + $expr = new ConstantExpression('foo', 1); + $node = new DoNode($expr, 1); $this->assertEquals($expr, $node->getNode('expr')); } @@ -23,8 +27,8 @@ class Twig_Tests_Node_DoTest extends \Twig\Test\NodeTestCase { $tests = []; - $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); - $node = new \Twig\Node\DoNode($expr, 1); + $expr = new ConstantExpression('foo', 1); + $node = new DoNode($expr, 1); $tests[] = [$node, "// line 1\n\"foo\";"]; return $tests; diff --git a/test/Twig/Tests/Node/Expression/ArrayTest.php b/test/Twig/Tests/Node/Expression/ArrayTest.php index 2175ccc2e..6c3ce1c0b 100644 --- a/test/Twig/Tests/Node/Expression/ArrayTest.php +++ b/test/Twig/Tests/Node/Expression/ArrayTest.php @@ -9,12 +9,16 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ArrayTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\ArrayExpression; + +class Twig_Tests_Node_Expression_ArrayTest extends NodeTestCase { public function testConstructor() { - $elements = [new \Twig\Node\Expression\ConstantExpression('foo', 1), $foo = new \Twig\Node\Expression\ConstantExpression('bar', 1)]; - $node = new \Twig\Node\Expression\ArrayExpression($elements, 1); + $elements = [new ConstantExpression('foo', 1), $foo = new ConstantExpression('bar', 1)]; + $node = new ArrayExpression($elements, 1); $this->assertEquals($foo, $node->getNode(1)); } @@ -22,13 +26,13 @@ class Twig_Tests_Node_Expression_ArrayTest extends \Twig\Test\NodeTestCase public function getTests() { $elements = [ - new \Twig\Node\Expression\ConstantExpression('foo', 1), - new \Twig\Node\Expression\ConstantExpression('bar', 1), + new ConstantExpression('foo', 1), + new ConstantExpression('bar', 1), - new \Twig\Node\Expression\ConstantExpression('bar', 1), - new \Twig\Node\Expression\ConstantExpression('foo', 1), + new ConstantExpression('bar', 1), + new ConstantExpression('foo', 1), ]; - $node = new \Twig\Node\Expression\ArrayExpression($elements, 1); + $node = new ArrayExpression($elements, 1); return [ [$node, '["foo" => "bar", "bar" => "foo"]'], diff --git a/test/Twig/Tests/Node/Expression/AssignNameTest.php b/test/Twig/Tests/Node/Expression/AssignNameTest.php index 28470e500..8e398bb58 100644 --- a/test/Twig/Tests/Node/Expression/AssignNameTest.php +++ b/test/Twig/Tests/Node/Expression/AssignNameTest.php @@ -9,18 +9,21 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_AssignNameTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\AssignNameExpression; + +class Twig_Tests_Node_Expression_AssignNameTest extends NodeTestCase { public function testConstructor() { - $node = new \Twig\Node\Expression\AssignNameExpression('foo', 1); + $node = new AssignNameExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } public function getTests() { - $node = new \Twig\Node\Expression\AssignNameExpression('foo', 1); + $node = new AssignNameExpression('foo', 1); return [ [$node, '$context["foo"]'], diff --git a/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/test/Twig/Tests/Node/Expression/Binary/AddTest.php index 64a1c06b7..0df68285c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AddTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AddTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_AddTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\AddBinary; + +class Twig_Tests_Node_Expression_Binary_AddTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\AddBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new AddBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_AddTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\AddBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new AddBinary($left, $right, 1); return [ [$node, '(1 + 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/test/Twig/Tests/Node/Expression/Binary/AndTest.php index 6292f9e38..e7aea1d52 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AndTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AndTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_AndTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\AndBinary; + +class Twig_Tests_Node_Expression_Binary_AndTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\AndBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new AndBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_AndTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\AndBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new AndBinary($left, $right, 1); return [ [$node, '(1 && 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php index 9a6f56acf..993082515 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_ConcatTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\ConcatBinary; + +class Twig_Tests_Node_Expression_Binary_ConcatTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\ConcatBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new ConcatBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_ConcatTest extends \Twig\Test\NodeTestCa public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\ConcatBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new ConcatBinary($left, $right, 1); return [ [$node, '(1 . 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/test/Twig/Tests/Node/Expression/Binary/DivTest.php index 58719c2b2..830e9c996 100644 --- a/test/Twig/Tests/Node/Expression/Binary/DivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/DivTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_DivTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\DivBinary; + +class Twig_Tests_Node_Expression_Binary_DivTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\DivBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new DivBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_DivTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\DivBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new DivBinary($left, $right, 1); return [ [$node, '(1 / 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php index 4ca384021..f94fca736 100644 --- a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_FloorDivTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\FloorDivBinary; + +class Twig_Tests_Node_Expression_Binary_FloorDivTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\FloorDivBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new FloorDivBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_FloorDivTest extends \Twig\Test\NodeTest public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\FloorDivBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new FloorDivBinary($left, $right, 1); return [ [$node, '(int) floor((1 / 2))'], diff --git a/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/test/Twig/Tests/Node/Expression/Binary/ModTest.php index d4d48acdb..5697c02d2 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ModTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ModTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_ModTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\ModBinary; + +class Twig_Tests_Node_Expression_Binary_ModTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\ModBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new ModBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_ModTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\ModBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new ModBinary($left, $right, 1); return [ [$node, '(1 % 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/test/Twig/Tests/Node/Expression/Binary/MulTest.php index b35655b75..8027926a9 100644 --- a/test/Twig/Tests/Node/Expression/Binary/MulTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/MulTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_MulTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\MulBinary; + +class Twig_Tests_Node_Expression_Binary_MulTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\MulBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new MulBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_MulTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\MulBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new MulBinary($left, $right, 1); return [ [$node, '(1 * 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/test/Twig/Tests/Node/Expression/Binary/OrTest.php index 9a40ffbd9..a1159ad5c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/OrTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/OrTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_OrTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\OrBinary; + +class Twig_Tests_Node_Expression_Binary_OrTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\OrBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new OrBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_OrTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\OrBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new OrBinary($left, $right, 1); return [ [$node, '(1 || 2)'], diff --git a/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/test/Twig/Tests/Node/Expression/Binary/SubTest.php index 191ad7e96..e039c1609 100644 --- a/test/Twig/Tests/Node/Expression/Binary/SubTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/SubTest.php @@ -9,13 +9,17 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Binary_SubTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Binary\SubBinary; + +class Twig_Tests_Node_Expression_Binary_SubTest extends NodeTestCase { public function testConstructor() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\SubBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new SubBinary($left, $right, 1); $this->assertEquals($left, $node->getNode('left')); $this->assertEquals($right, $node->getNode('right')); @@ -23,9 +27,9 @@ class Twig_Tests_Node_Expression_Binary_SubTest extends \Twig\Test\NodeTestCase public function getTests() { - $left = new \Twig\Node\Expression\ConstantExpression(1, 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\Binary\SubBinary($left, $right, 1); + $left = new ConstantExpression(1, 1); + $right = new ConstantExpression(2, 1); + $node = new SubBinary($left, $right, 1); return [ [$node, '(1 - 2)'], diff --git a/test/Twig/Tests/Node/Expression/CallTest.php b/test/Twig/Tests/Node/Expression/CallTest.php index 72780d711..32b5d19a7 100644 --- a/test/Twig/Tests/Node/Expression/CallTest.php +++ b/test/Twig/Tests/Node/Expression/CallTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Node\Expression\CallExpression; + class Twig_Tests_Node_Expression_CallTest extends \PHPUnit\Framework\TestCase { public function testGetArguments() @@ -123,7 +125,7 @@ class Twig_Tests_Node_Expression_CallTest extends \PHPUnit\Framework\TestCase } } -class Twig_Tests_Node_Expression_Call extends \Twig\Node\Expression\CallExpression +class Twig_Tests_Node_Expression_Call extends CallExpression { public function getArguments($callable, $arguments) { diff --git a/test/Twig/Tests/Node/Expression/ConditionalTest.php b/test/Twig/Tests/Node/Expression/ConditionalTest.php index 1c37e6106..7d2ac5433 100644 --- a/test/Twig/Tests/Node/Expression/ConditionalTest.php +++ b/test/Twig/Tests/Node/Expression/ConditionalTest.php @@ -9,14 +9,18 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ConditionalTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\ConditionalExpression; + +class Twig_Tests_Node_Expression_ConditionalTest extends NodeTestCase { public function testConstructor() { - $expr1 = new \Twig\Node\Expression\ConstantExpression(1, 1); - $expr2 = new \Twig\Node\Expression\ConstantExpression(2, 1); - $expr3 = new \Twig\Node\Expression\ConstantExpression(3, 1); - $node = new \Twig\Node\Expression\ConditionalExpression($expr1, $expr2, $expr3, 1); + $expr1 = new ConstantExpression(1, 1); + $expr2 = new ConstantExpression(2, 1); + $expr3 = new ConstantExpression(3, 1); + $node = new ConditionalExpression($expr1, $expr2, $expr3, 1); $this->assertEquals($expr1, $node->getNode('expr1')); $this->assertEquals($expr2, $node->getNode('expr2')); @@ -27,10 +31,10 @@ class Twig_Tests_Node_Expression_ConditionalTest extends \Twig\Test\NodeTestCase { $tests = []; - $expr1 = new \Twig\Node\Expression\ConstantExpression(1, 1); - $expr2 = new \Twig\Node\Expression\ConstantExpression(2, 1); - $expr3 = new \Twig\Node\Expression\ConstantExpression(3, 1); - $node = new \Twig\Node\Expression\ConditionalExpression($expr1, $expr2, $expr3, 1); + $expr1 = new ConstantExpression(1, 1); + $expr2 = new ConstantExpression(2, 1); + $expr3 = new ConstantExpression(3, 1); + $node = new ConditionalExpression($expr1, $expr2, $expr3, 1); $tests[] = [$node, '((1) ? (2) : (3))']; return $tests; diff --git a/test/Twig/Tests/Node/Expression/ConstantTest.php b/test/Twig/Tests/Node/Expression/ConstantTest.php index 1cb1242e7..850b8ca59 100644 --- a/test/Twig/Tests/Node/Expression/ConstantTest.php +++ b/test/Twig/Tests/Node/Expression/ConstantTest.php @@ -9,11 +9,14 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ConstantTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; + +class Twig_Tests_Node_Expression_ConstantTest extends NodeTestCase { public function testConstructor() { - $node = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $node = new ConstantExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('value')); } @@ -22,7 +25,7 @@ class Twig_Tests_Node_Expression_ConstantTest extends \Twig\Test\NodeTestCase { $tests = []; - $node = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $node = new ConstantExpression('foo', 1); $tests[] = [$node, '"foo"']; return $tests; diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index a21650f83..727cb3db4 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -9,14 +9,21 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\Node\Expression\FilterExpression; +use Twig\Environment; +use Twig\TwigFilter; + +class Twig_Tests_Node_Expression_FilterTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); - $name = new \Twig\Node\Expression\ConstantExpression('upper', 1); - $args = new \Twig\Node\Node(); - $node = new \Twig\Node\Expression\FilterExpression($expr, $name, $args, 1); + $expr = new ConstantExpression('foo', 1); + $name = new ConstantExpression('upper', 1); + $args = new Node(); + $node = new FilterExpression($expr, $name, $args, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($name, $node->getNode('filter')); @@ -25,15 +32,15 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase public function getTests() { - $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); - $environment->addFilter(new \Twig\TwigFilter('bar', 'bar', ['needs_environment' => true])); - $environment->addFilter(new \Twig\TwigFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true])); + $environment = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addFilter(new TwigFilter('bar', 'bar', ['needs_environment' => true])); + $environment->addFilter(new TwigFilter('barbar', 'twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true])); $tests = []; - $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); + $expr = new ConstantExpression('foo', 1); $node = $this->createFilter($expr, 'upper'); - $node = $this->createFilter($node, 'number_format', [new \Twig\Node\Expression\ConstantExpression(2, 1), new \Twig\Node\Expression\ConstantExpression('.', 1), new \Twig\Node\Expression\ConstantExpression(',', 1)]); + $node = $this->createFilter($node, 'number_format', [new ConstantExpression(2, 1), new ConstantExpression('.', 1), new ConstantExpression(',', 1)]); if (\function_exists('mb_get_info')) { $tests[] = [$node, 'twig_number_format_filter($this->env, twig_upper_filter($this->env, "foo"), 2, ".", ",")']; @@ -42,34 +49,34 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase } // named arguments - $date = new \Twig\Node\Expression\ConstantExpression(0, 1); + $date = new ConstantExpression(0, 1); $node = $this->createFilter($date, 'date', [ - 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), - 'format' => new \Twig\Node\Expression\ConstantExpression('d/m/Y H:i:s P', 1), + 'timezone' => new ConstantExpression('America/Chicago', 1), + 'format' => new ConstantExpression('d/m/Y H:i:s P', 1), ]); $tests[] = [$node, 'twig_date_format_filter($this->env, 0, "d/m/Y H:i:s P", "America/Chicago")']; // skip an optional argument - $date = new \Twig\Node\Expression\ConstantExpression(0, 1); + $date = new ConstantExpression(0, 1); $node = $this->createFilter($date, 'date', [ - 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), + 'timezone' => new ConstantExpression('America/Chicago', 1), ]); $tests[] = [$node, 'twig_date_format_filter($this->env, 0, null, "America/Chicago")']; // underscores vs camelCase for named arguments - $string = new \Twig\Node\Expression\ConstantExpression('abc', 1); + $string = new ConstantExpression('abc', 1); $node = $this->createFilter($string, 'reverse', [ - 'preserve_keys' => new \Twig\Node\Expression\ConstantExpression(true, 1), + 'preserve_keys' => new ConstantExpression(true, 1), ]); $tests[] = [$node, 'twig_reverse_filter($this->env, "abc", true)']; $node = $this->createFilter($string, 'reverse', [ - 'preserveKeys' => new \Twig\Node\Expression\ConstantExpression(true, 1), + 'preserveKeys' => new ConstantExpression(true, 1), ]); $tests[] = [$node, 'twig_reverse_filter($this->env, "abc", true)']; // filter as an anonymous function if (PHP_VERSION_ID >= 50300) { - $node = $this->createFilter(new \Twig\Node\Expression\ConstantExpression('foo', 1), 'anonymous'); + $node = $this->createFilter(new ConstantExpression('foo', 1), 'anonymous'); $tests[] = [$node, 'call_user_func_array($this->env->getFilter(\'anonymous\')->getCallable(), ["foo"])']; } @@ -77,24 +84,24 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase $node = $this->createFilter($string, 'bar'); $tests[] = [$node, 'bar($this->env, "abc")', $environment]; - $node = $this->createFilter($string, 'bar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFilter($string, 'bar', [new ConstantExpression('bar', 1)]); $tests[] = [$node, 'bar($this->env, "abc", "bar")', $environment]; // arbitrary named arguments $node = $this->createFilter($string, 'barbar'); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc")', $environment]; - $node = $this->createFilter($string, 'barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFilter($string, 'barbar', ['foo' => new ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", null, null, ["foo" => "bar"])', $environment]; - $node = $this->createFilter($string, 'barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFilter($string, 'barbar', ['arg2' => new ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", null, "bar")', $environment]; $node = $this->createFilter($string, 'barbar', [ - new \Twig\Node\Expression\ConstantExpression('1', 1), - new \Twig\Node\Expression\ConstantExpression('2', 1), - new \Twig\Node\Expression\ConstantExpression('3', 1), - 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1), + new ConstantExpression('1', 1), + new ConstantExpression('2', 1), + new ConstantExpression('3', 1), + 'foo' => new ConstantExpression('bar', 1), ]); $tests[] = [$node, 'twig_tests_filter_barbar($context, "abc", "1", "2", [0 => "3", "foo" => "bar"])', $environment]; @@ -107,9 +114,9 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase */ public function testCompileWithWrongNamedArgumentName() { - $date = new \Twig\Node\Expression\ConstantExpression(0, 1); + $date = new ConstantExpression(0, 1); $node = $this->createFilter($date, 'date', [ - 'foobar' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), + 'foobar' => new ConstantExpression('America/Chicago', 1), ]); $compiler = $this->getCompiler(); @@ -122,9 +129,9 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase */ public function testCompileWithMissingNamedArgument() { - $value = new \Twig\Node\Expression\ConstantExpression(0, 1); + $value = new ConstantExpression(0, 1); $node = $this->createFilter($value, 'replace', [ - 'to' => new \Twig\Node\Expression\ConstantExpression('foo', 1), + 'to' => new ConstantExpression('foo', 1), ]); $compiler = $this->getCompiler(); @@ -133,10 +140,10 @@ class Twig_Tests_Node_Expression_FilterTest extends \Twig\Test\NodeTestCase protected function createFilter($node, $name, array $arguments = []) { - $name = new \Twig\Node\Expression\ConstantExpression($name, 1); - $arguments = new \Twig\Node\Node($arguments); + $name = new ConstantExpression($name, 1); + $arguments = new Node($arguments); - return new \Twig\Node\Expression\FilterExpression($node, $name, $arguments, 1); + return new FilterExpression($node, $name, $arguments, 1); } protected function getEnvironment() diff --git a/test/Twig/Tests/Node/Expression/FunctionTest.php b/test/Twig/Tests/Node/Expression/FunctionTest.php index 2aa3a2c2d..8ca3eec48 100644 --- a/test/Twig/Tests/Node/Expression/FunctionTest.php +++ b/test/Twig/Tests/Node/Expression/FunctionTest.php @@ -9,13 +9,20 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Node; +use Twig\Node\Expression\FunctionExpression; +use Twig\Environment; +use Twig\TwigFunction; +use Twig\Node\Expression\ConstantExpression; + +class Twig_Tests_Node_Expression_FunctionTest extends NodeTestCase { public function testConstructor() { $name = 'function'; - $args = new \Twig\Node\Node(); - $node = new \Twig\Node\Expression\FunctionExpression($name, $args, 1); + $args = new Node(); + $node = new FunctionExpression($name, $args, 1); $this->assertEquals($name, $node->getAttribute('name')); $this->assertEquals($args, $node->getNode('arguments')); @@ -23,43 +30,43 @@ class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase public function getTests() { - $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); - $environment->addFunction(new \Twig\TwigFunction('foo', 'foo', [])); - $environment->addFunction(new \Twig\TwigFunction('bar', 'bar', ['needs_environment' => true])); - $environment->addFunction(new \Twig\TwigFunction('foofoo', 'foofoo', ['needs_context' => true])); - $environment->addFunction(new \Twig\TwigFunction('foobar', 'foobar', ['needs_environment' => true, 'needs_context' => true])); - $environment->addFunction(new \Twig\TwigFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true])); + $environment = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addFunction(new TwigFunction('foo', 'foo', [])); + $environment->addFunction(new TwigFunction('bar', 'bar', ['needs_environment' => true])); + $environment->addFunction(new TwigFunction('foofoo', 'foofoo', ['needs_context' => true])); + $environment->addFunction(new TwigFunction('foobar', 'foobar', ['needs_environment' => true, 'needs_context' => true])); + $environment->addFunction(new TwigFunction('barbar', 'twig_tests_function_barbar', ['is_variadic' => true])); $tests = []; $node = $this->createFunction('foo'); $tests[] = [$node, 'foo()', $environment]; - $node = $this->createFunction('foo', [new \Twig\Node\Expression\ConstantExpression('bar', 1), new \Twig\Node\Expression\ConstantExpression('foobar', 1)]); + $node = $this->createFunction('foo', [new ConstantExpression('bar', 1), new ConstantExpression('foobar', 1)]); $tests[] = [$node, 'foo("bar", "foobar")', $environment]; $node = $this->createFunction('bar'); $tests[] = [$node, 'bar($this->env)', $environment]; - $node = $this->createFunction('bar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFunction('bar', [new ConstantExpression('bar', 1)]); $tests[] = [$node, 'bar($this->env, "bar")', $environment]; $node = $this->createFunction('foofoo'); $tests[] = [$node, 'foofoo($context)', $environment]; - $node = $this->createFunction('foofoo', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFunction('foofoo', [new ConstantExpression('bar', 1)]); $tests[] = [$node, 'foofoo($context, "bar")', $environment]; $node = $this->createFunction('foobar'); $tests[] = [$node, 'foobar($this->env, $context)', $environment]; - $node = $this->createFunction('foobar', [new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFunction('foobar', [new ConstantExpression('bar', 1)]); $tests[] = [$node, 'foobar($this->env, $context, "bar")', $environment]; // named arguments $node = $this->createFunction('date', [ - 'timezone' => new \Twig\Node\Expression\ConstantExpression('America/Chicago', 1), - 'date' => new \Twig\Node\Expression\ConstantExpression(0, 1), + 'timezone' => new ConstantExpression('America/Chicago', 1), + 'date' => new ConstantExpression(0, 1), ]); $tests[] = [$node, 'twig_date_converter($this->env, 0, "America/Chicago")']; @@ -67,23 +74,23 @@ class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase $node = $this->createFunction('barbar'); $tests[] = [$node, 'twig_tests_function_barbar()', $environment]; - $node = $this->createFunction('barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFunction('barbar', ['foo' => new ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_function_barbar(null, null, ["foo" => "bar"])', $environment]; - $node = $this->createFunction('barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createFunction('barbar', ['arg2' => new ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_function_barbar(null, "bar")', $environment]; $node = $this->createFunction('barbar', [ - new \Twig\Node\Expression\ConstantExpression('1', 1), - new \Twig\Node\Expression\ConstantExpression('2', 1), - new \Twig\Node\Expression\ConstantExpression('3', 1), - 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1), + new ConstantExpression('1', 1), + new ConstantExpression('2', 1), + new ConstantExpression('3', 1), + 'foo' => new ConstantExpression('bar', 1), ]); $tests[] = [$node, 'twig_tests_function_barbar("1", "2", [0 => "3", "foo" => "bar"])', $environment]; // function as an anonymous function if (PHP_VERSION_ID >= 50300) { - $node = $this->createFunction('anonymous', [new \Twig\Node\Expression\ConstantExpression('foo', 1)]); + $node = $this->createFunction('anonymous', [new ConstantExpression('foo', 1)]); $tests[] = [$node, 'call_user_func_array($this->env->getFunction(\'anonymous\')->getCallable(), ["foo"])']; } @@ -92,7 +99,7 @@ class Twig_Tests_Node_Expression_FunctionTest extends \Twig\Test\NodeTestCase protected function createFunction($name, array $arguments = []) { - return new \Twig\Node\Expression\FunctionExpression($name, new \Twig\Node\Node($arguments), 1); + return new FunctionExpression($name, new Node($arguments), 1); } protected function getEnvironment() diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php index 130fd9fb4..048e82089 100644 --- a/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -9,40 +9,47 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_GetAttrTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Template; + +class Twig_Tests_Node_Expression_GetAttrTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\NameExpression('foo', 1); - $attr = new \Twig\Node\Expression\ConstantExpression('bar', 1); - $args = new \Twig\Node\Expression\ArrayExpression([], 1); - $args->addElement(new \Twig\Node\Expression\NameExpression('foo', 1)); - $args->addElement(new \Twig\Node\Expression\ConstantExpression('bar', 1)); - $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ARRAY_CALL, 1); + $expr = new NameExpression('foo', 1); + $attr = new ConstantExpression('bar', 1); + $args = new ArrayExpression([], 1); + $args->addElement(new NameExpression('foo', 1)); + $args->addElement(new ConstantExpression('bar', 1)); + $node = new GetAttrExpression($expr, $attr, $args, Template::ARRAY_CALL, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($attr, $node->getNode('attribute')); $this->assertEquals($args, $node->getNode('arguments')); - $this->assertEquals(\Twig\Template::ARRAY_CALL, $node->getAttribute('type')); + $this->assertEquals(Template::ARRAY_CALL, $node->getAttribute('type')); } public function getTests() { $tests = []; - $expr = new \Twig\Node\Expression\NameExpression('foo', 1); - $attr = new \Twig\Node\Expression\ConstantExpression('bar', 1); - $args = new \Twig\Node\Expression\ArrayExpression([], 1); - $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ANY_CALL, 1); + $expr = new NameExpression('foo', 1); + $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", [])', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; - $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::ARRAY_CALL, 1); + $node = new GetAttrExpression($expr, $attr, $args, Template::ARRAY_CALL, 1); $tests[] = [$node, sprintf('%s%s, "bar", [], "array")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1))]; - $args = new \Twig\Node\Expression\ArrayExpression([], 1); - $args->addElement(new \Twig\Node\Expression\NameExpression('foo', 1)); - $args->addElement(new \Twig\Node\Expression\ConstantExpression('bar', 1)); - $node = new \Twig\Node\Expression\GetAttrExpression($expr, $attr, $args, \Twig\Template::METHOD_CALL, 1); + $args = new ArrayExpression([], 1); + $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", [0 => %s, 1 => "bar"], "method")', $this->getAttributeGetter(), $this->getVariableGetter('foo', 1), $this->getVariableGetter('foo'))]; return $tests; diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index 25eaa0273..f9611d5a9 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -9,22 +9,26 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_NameTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\NameExpression; +use Twig\Environment; + +class Twig_Tests_Node_Expression_NameTest extends NodeTestCase { public function testConstructor() { - $node = new \Twig\Node\Expression\NameExpression('foo', 1); + $node = new NameExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } public function getTests() { - $node = new \Twig\Node\Expression\NameExpression('foo', 1); - $context = new \Twig\Node\Expression\NameExpression('_context', 1); + $node = new NameExpression('foo', 1); + $context = new NameExpression('_context', 1); - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]); - $env1 = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => false]); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true]); + $env1 = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => false]); if (PHP_VERSION_ID >= 70000) { $output = '($context["foo"] ?? $this->getContext($context, "foo"))'; diff --git a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php index 398c12f46..57a7bd490 100644 --- a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php +++ b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php @@ -9,15 +9,20 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_NullCoalesceTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NullCoalesceExpression; + +class Twig_Tests_Node_Expression_NullCoalesceTest extends NodeTestCase { public function getTests() { $tests = []; - $left = new \Twig\Node\Expression\NameExpression('foo', 1); - $right = new \Twig\Node\Expression\ConstantExpression(2, 1); - $node = new \Twig\Node\Expression\NullCoalesceExpression($left, $right, 1); + $left = new NameExpression('foo', 1); + $right = new ConstantExpression(2, 1); + $node = new NullCoalesceExpression($left, $right, 1); if (PHP_VERSION_ID >= 70000) { $tests[] = [$node, "((// line 1\n\$context[\"foo\"]) ?? (2))"]; } elseif (PHP_VERSION_ID >= 50400) { diff --git a/test/Twig/Tests/Node/Expression/ParentTest.php b/test/Twig/Tests/Node/Expression/ParentTest.php index 940db7169..988ad34ac 100644 --- a/test/Twig/Tests/Node/Expression/ParentTest.php +++ b/test/Twig/Tests/Node/Expression/ParentTest.php @@ -9,11 +9,14 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_ParentTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ParentExpression; + +class Twig_Tests_Node_Expression_ParentTest extends NodeTestCase { public function testConstructor() { - $node = new \Twig\Node\Expression\ParentExpression('foo', 1); + $node = new ParentExpression('foo', 1); $this->assertEquals('foo', $node->getAttribute('name')); } @@ -21,7 +24,7 @@ class Twig_Tests_Node_Expression_ParentTest extends \Twig\Test\NodeTestCase public function getTests() { $tests = []; - $tests[] = [new \Twig\Node\Expression\ParentExpression('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)']; + $tests[] = [new ParentExpression('foo', 1), '$this->renderParentBlock("foo", $context, $blocks)']; return $tests; } diff --git a/test/Twig/Tests/Node/Expression/TestTest.php b/test/Twig/Tests/Node/Expression/TestTest.php index c23b2b222..712568785 100644 --- a/test/Twig/Tests/Node/Expression/TestTest.php +++ b/test/Twig/Tests/Node/Expression/TestTest.php @@ -9,14 +9,22 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\Node\Expression\TestExpression; +use Twig\Environment; +use Twig\TwigTest; +use Twig\Node\Expression\Test\NullTest; + +class Twig_Tests_Node_Expression_TestTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); - $name = new \Twig\Node\Expression\ConstantExpression('null', 1); - $args = new \Twig\Node\Node(); - $node = new \Twig\Node\Expression\TestExpression($expr, $name, $args, 1); + $expr = new ConstantExpression('foo', 1); + $name = new ConstantExpression('null', 1); + $args = new Node(); + $node = new TestExpression($expr, $name, $args, 1); $this->assertEquals($expr, $node->getNode('node')); $this->assertEquals($args, $node->getNode('arguments')); @@ -25,37 +33,37 @@ class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase public function getTests() { - $environment = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); - $environment->addTest(new \Twig\TwigTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true])); + $environment = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $environment->addTest(new TwigTest('barbar', 'twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true])); $tests = []; - $expr = new \Twig\Node\Expression\ConstantExpression('foo', 1); - $node = new \Twig\Node\Expression\Test\NullTest($expr, 'null', new \Twig\Node\Node([]), 1); + $expr = new ConstantExpression('foo', 1); + $node = new NullTest($expr, 'null', new Node([]), 1); $tests[] = [$node, '(null === "foo")']; // test as an anonymous function if (PHP_VERSION_ID >= 50300) { - $node = $this->createTest(new \Twig\Node\Expression\ConstantExpression('foo', 1), 'anonymous', [new \Twig\Node\Expression\ConstantExpression('foo', 1)]); + $node = $this->createTest(new ConstantExpression('foo', 1), 'anonymous', [new ConstantExpression('foo', 1)]); $tests[] = [$node, 'call_user_func_array($this->env->getTest(\'anonymous\')->getCallable(), ["foo", "foo"])']; } // arbitrary named arguments - $string = new \Twig\Node\Expression\ConstantExpression('abc', 1); + $string = new ConstantExpression('abc', 1); $node = $this->createTest($string, 'barbar'); $tests[] = [$node, 'twig_tests_test_barbar("abc")', $environment]; - $node = $this->createTest($string, 'barbar', ['foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createTest($string, 'barbar', ['foo' => new ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_test_barbar("abc", null, null, ["foo" => "bar"])', $environment]; - $node = $this->createTest($string, 'barbar', ['arg2' => new \Twig\Node\Expression\ConstantExpression('bar', 1)]); + $node = $this->createTest($string, 'barbar', ['arg2' => new ConstantExpression('bar', 1)]); $tests[] = [$node, 'twig_tests_test_barbar("abc", null, "bar")', $environment]; $node = $this->createTest($string, 'barbar', [ - new \Twig\Node\Expression\ConstantExpression('1', 1), - new \Twig\Node\Expression\ConstantExpression('2', 1), - new \Twig\Node\Expression\ConstantExpression('3', 1), - 'foo' => new \Twig\Node\Expression\ConstantExpression('bar', 1), + new ConstantExpression('1', 1), + new ConstantExpression('2', 1), + new ConstantExpression('3', 1), + 'foo' => new ConstantExpression('bar', 1), ]); $tests[] = [$node, 'twig_tests_test_barbar("abc", "1", "2", [0 => "3", "foo" => "bar"])', $environment]; @@ -64,7 +72,7 @@ class Twig_Tests_Node_Expression_TestTest extends \Twig\Test\NodeTestCase protected function createTest($node, $name, array $arguments = []) { - return new \Twig\Node\Expression\TestExpression($node, $name, new \Twig\Node\Node($arguments), 1); + return new TestExpression($node, $name, new Node($arguments), 1); } protected function getEnvironment() diff --git a/test/Twig/Tests/Node/Expression/Unary/NegTest.php b/test/Twig/Tests/Node/Expression/Unary/NegTest.php index d46f2ae9a..d2b72a79b 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NegTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NegTest.php @@ -9,24 +9,28 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Unary_NegTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Unary\NegUnary; + +class Twig_Tests_Node_Expression_Unary_NegTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\ConstantExpression(1, 1); - $node = new \Twig\Node\Expression\Unary\NegUnary($expr, 1); + $expr = new ConstantExpression(1, 1); + $node = new NegUnary($expr, 1); $this->assertEquals($expr, $node->getNode('node')); } public function getTests() { - $node = new \Twig\Node\Expression\ConstantExpression(1, 1); - $node = new \Twig\Node\Expression\Unary\NegUnary($node, 1); + $node = new ConstantExpression(1, 1); + $node = new NegUnary($node, 1); return [ [$node, '-1'], - [new \Twig\Node\Expression\Unary\NegUnary($node, 1), '- -1'], + [new NegUnary($node, 1), '- -1'], ]; } } diff --git a/test/Twig/Tests/Node/Expression/Unary/NotTest.php b/test/Twig/Tests/Node/Expression/Unary/NotTest.php index 95ab487e2..05ea3ffce 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NotTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NotTest.php @@ -9,20 +9,24 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Unary_NotTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Unary\NotUnary; + +class Twig_Tests_Node_Expression_Unary_NotTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\ConstantExpression(1, 1); - $node = new \Twig\Node\Expression\Unary\NotUnary($expr, 1); + $expr = new ConstantExpression(1, 1); + $node = new NotUnary($expr, 1); $this->assertEquals($expr, $node->getNode('node')); } public function getTests() { - $node = new \Twig\Node\Expression\ConstantExpression(1, 1); - $node = new \Twig\Node\Expression\Unary\NotUnary($node, 1); + $node = new ConstantExpression(1, 1); + $node = new NotUnary($node, 1); return [ [$node, '!1'], diff --git a/test/Twig/Tests/Node/Expression/Unary/PosTest.php b/test/Twig/Tests/Node/Expression/Unary/PosTest.php index 38469c437..294b2ff92 100644 --- a/test/Twig/Tests/Node/Expression/Unary/PosTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/PosTest.php @@ -9,20 +9,24 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_Expression_Unary_PosTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\Unary\PosUnary; + +class Twig_Tests_Node_Expression_Unary_PosTest extends NodeTestCase { public function testConstructor() { - $expr = new \Twig\Node\Expression\ConstantExpression(1, 1); - $node = new \Twig\Node\Expression\Unary\PosUnary($expr, 1); + $expr = new ConstantExpression(1, 1); + $node = new PosUnary($expr, 1); $this->assertEquals($expr, $node->getNode('node')); } public function getTests() { - $node = new \Twig\Node\Expression\ConstantExpression(1, 1); - $node = new \Twig\Node\Expression\Unary\PosUnary($node, 1); + $node = new ConstantExpression(1, 1); + $node = new PosUnary($node, 1); return [ [$node, '+1'], diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php index 5a065681e..60265a0d3 100644 --- a/test/Twig/Tests/Node/ForTest.php +++ b/test/Twig/Tests/Node/ForTest.php @@ -9,17 +9,25 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_ForTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\Node\PrintNode; +use Twig\Node\ForNode; + +class Twig_Tests_Node_ForTest extends NodeTestCase { public function testConstructor() { - $keyTarget = new \Twig\Node\Expression\AssignNameExpression('key', 1); - $valueTarget = new \Twig\Node\Expression\AssignNameExpression('item', 1); - $seq = new \Twig\Node\Expression\NameExpression('items', 1); - $ifexpr = new \Twig\Node\Expression\ConstantExpression(true, 1); - $body = new \Twig\Node\Node([new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1)], [], 1); + $keyTarget = new AssignNameExpression('key', 1); + $valueTarget = new AssignNameExpression('item', 1); + $seq = new NameExpression('items', 1); + $ifexpr = new ConstantExpression(true, 1); + $body = new Node([new PrintNode(new NameExpression('foo', 1), 1)], [], 1); $else = null; - $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node = new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); $node->setAttribute('with_loop', false); $this->assertEquals($keyTarget, $node->getNode('key_target')); @@ -30,8 +38,8 @@ class Twig_Tests_Node_ForTest extends \Twig\Test\NodeTestCase $this->assertEquals($body, $node->getNode('body')->getNode('tests')->getNode(1)->getNode(0)); $this->assertFalse($node->hasNode('else')); - $else = new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1); - $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $else = new PrintNode(new NameExpression('foo', 1), 1); + $node = new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); $node->setAttribute('with_loop', false); $this->assertEquals($else, $node->getNode('else')); } @@ -40,13 +48,13 @@ class Twig_Tests_Node_ForTest extends \Twig\Test\NodeTestCase { $tests = []; - $keyTarget = new \Twig\Node\Expression\AssignNameExpression('key', 1); - $valueTarget = new \Twig\Node\Expression\AssignNameExpression('item', 1); - $seq = new \Twig\Node\Expression\NameExpression('items', 1); + $keyTarget = new AssignNameExpression('key', 1); + $valueTarget = new AssignNameExpression('item', 1); + $seq = new NameExpression('items', 1); $ifexpr = null; - $body = new \Twig\Node\Node([new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1)], [], 1); + $body = new Node([new PrintNode(new NameExpression('foo', 1), 1)], [], 1); $else = null; - $node = new \Twig\Node\ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); + $node = new ForNode($keyTarget, $valueTarget, $seq, $ifexpr, $body, $else, 1); $node->setAttribute('with_loop', false); $tests[] = [$node, <<setAttribute('with_loop', true); $tests[] = [$node, <<setAttribute('with_loop', true); $tests[] = [$node, <<setAttribute('with_loop', true); $tests[] = [$node, <<assertEquals($t, $node->getNode('tests')); $this->assertFalse($node->hasNode('else')); - $else = new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('bar', 1), 1); - $node = new \Twig\Node\IfNode($t, $else, 1); + $else = new PrintNode(new NameExpression('bar', 1), 1); + $node = new IfNode($t, $else, 1); $this->assertEquals($else, $node->getNode('else')); } @@ -32,12 +39,12 @@ class Twig_Tests_Node_IfTest extends \Twig\Test\NodeTestCase { $tests = []; - $t = new \Twig\Node\Node([ - new \Twig\Node\Expression\ConstantExpression(true, 1), - new \Twig\Node\PrintNode(new \Twig\Node\Expression\NameExpression('foo', 1), 1), + $t = new Node([ + new ConstantExpression(true, 1), + new PrintNode(new NameExpression('foo', 1), 1), ], [], 1); $else = null; - $node = new \Twig\Node\IfNode($t, $else, 1); + $node = new IfNode($t, $else, 1); $tests[] = [$node, <<assertEquals($macro, $node->getNode('expr')); $this->assertEquals($var, $node->getNode('var')); @@ -25,9 +30,9 @@ class Twig_Tests_Node_ImportTest extends \Twig\Test\NodeTestCase { $tests = []; - $macro = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1); - $var = new \Twig\Node\Expression\AssignNameExpression('macro', 1); - $node = new \Twig\Node\ImportNode($macro, $var, 1); + $macro = new ConstantExpression('foo.twig', 1); + $var = new AssignNameExpression('macro', 1); + $node = new ImportNode($macro, $var, 1); $tests[] = [$node, <<assertFalse($node->hasNode('variables')); $this->assertEquals($expr, $node->getNode('expr')); $this->assertFalse($node->getAttribute('only')); - $vars = new \Twig\Node\Expression\ArrayExpression([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\ConstantExpression(true, 1)], 1); - $node = new \Twig\Node\IncludeNode($expr, $vars, true, false, 1); + $vars = new ArrayExpression([new ConstantExpression('foo', 1), new ConstantExpression(true, 1)], 1); + $node = new IncludeNode($expr, $vars, true, false, 1); $this->assertEquals($vars, $node->getNode('variables')); $this->assertTrue($node->getAttribute('only')); } @@ -30,49 +37,49 @@ class Twig_Tests_Node_IncludeTest extends \Twig\Test\NodeTestCase { $tests = []; - $expr = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1); - $node = new \Twig\Node\IncludeNode($expr, null, false, false, 1); + $expr = new ConstantExpression('foo.twig', 1); + $node = new IncludeNode($expr, null, false, false, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(\$context); EOF ]; - $expr = new \Twig\Node\Expression\ConditionalExpression( - new \Twig\Node\Expression\ConstantExpression(true, 1), - new \Twig\Node\Expression\ConstantExpression('foo', 1), - new \Twig\Node\Expression\ConstantExpression('foo', 1), + $expr = new ConditionalExpression( + new ConstantExpression(true, 1), + new ConstantExpression('foo', 1), + new ConstantExpression('foo', 1), 0 ); - $node = new \Twig\Node\IncludeNode($expr, null, false, false, 1); + $node = new IncludeNode($expr, null, false, false, 1); $tests[] = [$node, <<loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context); EOF ]; - $expr = new \Twig\Node\Expression\ConstantExpression('foo.twig', 1); - $vars = new \Twig\Node\Expression\ArrayExpression([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\ConstantExpression(true, 1)], 1); - $node = new \Twig\Node\IncludeNode($expr, $vars, false, false, 1); + $expr = new ConstantExpression('foo.twig', 1); + $vars = new ArrayExpression([new ConstantExpression('foo', 1), new ConstantExpression(true, 1)], 1); + $node = new IncludeNode($expr, $vars, false, false, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, ["foo" => true])); EOF ]; - $node = new \Twig\Node\IncludeNode($expr, $vars, true, false, 1); + $node = new IncludeNode($expr, $vars, true, false, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(["foo" => true]); EOF ]; - $node = new \Twig\Node\IncludeNode($expr, $vars, true, true, 1); + $node = new IncludeNode($expr, $vars, true, true, 1); $tests[] = [$node, <<loadTemplate("foo.twig", null, 1)->display(["foo" => true]); -} catch (\Twig\Error\LoaderError \$e) { +} catch (LoaderError \$e) { // ignore missing template } EOF diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 944532ca1..838337687 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -9,13 +9,21 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_MacroTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\TextNode; +use Twig\Node\Node; +use Twig\Node\Expression\NameExpression; +use Twig\Node\MacroNode; +use Twig\Node\Expression\ConstantExpression; +use Twig\Markup; + +class Twig_Tests_Node_MacroTest extends NodeTestCase { public function testConstructor() { - $body = new \Twig\Node\TextNode('foo', 1); - $arguments = new \Twig\Node\Node([new \Twig\Node\Expression\NameExpression('foo', 1)], [], 1); - $node = new \Twig\Node\MacroNode('foo', $body, $arguments, 1); + $body = new TextNode('foo', 1); + $arguments = new Node([new NameExpression('foo', 1)], [], 1); + $node = new MacroNode('foo', $body, $arguments, 1); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals($arguments, $node->getNode('arguments')); @@ -24,12 +32,12 @@ class Twig_Tests_Node_MacroTest extends \Twig\Test\NodeTestCase public function getTests() { - $body = new \Twig\Node\TextNode('foo', 1); - $arguments = new \Twig\Node\Node([ - 'foo' => new \Twig\Node\Expression\ConstantExpression(null, 1), - 'bar' => new \Twig\Node\Expression\ConstantExpression('Foo', 1), + $body = new TextNode('foo', 1); + $arguments = new Node([ + 'foo' => new ConstantExpression(null, 1), + 'bar' => new ConstantExpression('Foo', 1), ], [], 1); - $node = new \Twig\Node\MacroNode('foo', $body, $arguments, 1); + $node = new MacroNode('foo', $body, $arguments, 1); if (PHP_VERSION_ID >= 50600) { $declaration = ', ...$__varargs__'; @@ -65,7 +73,7 @@ public function getfoo(\$__foo__ = null, \$__bar__ = "Foo"$declaration) throw \$e; } - return ('' === \$tmp = ob_get_clean()) ? '' : new \Twig\Markup(\$tmp, \$this->env->getCharset()); + return ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset()); } EOF ], diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 871d80947..8c7b2b059 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -9,17 +9,29 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_ModuleTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\TextNode; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\Source; +use Twig\Node\ModuleNode; +use Twig\Environment; +use Twig\Node\ImportNode; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\SetNode; +use Twig\Node\Expression\ConditionalExpression; + +class Twig_Tests_Node_ModuleTest extends NodeTestCase { public function testConstructor() { - $body = new \Twig\Node\TextNode('foo', 1); - $parent = new \Twig\Node\Expression\ConstantExpression('layout.twig', 1); - $blocks = new \Twig\Node\Node(); - $macros = new \Twig\Node\Node(); - $traits = new \Twig\Node\Node(); - $source = new \Twig\Source('{{ foo }}', 'foo.twig'); - $node = new \Twig\Node\ModuleNode($body, $parent, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source); + $body = new TextNode('foo', 1); + $parent = new ConstantExpression('layout.twig', 1); + $blocks = new Node(); + $macros = new Node(); + $traits = new Node(); + $source = new Source('{{ foo }}', 'foo.twig'); + $node = new ModuleNode($body, $parent, $blocks, $macros, $traits, new Node([]), $source); $this->assertEquals($body, $node->getNode('body')); $this->assertEquals($blocks, $node->getNode('blocks')); @@ -30,18 +42,18 @@ class Twig_Tests_Node_ModuleTest extends \Twig\Test\NodeTestCase public function getTests() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); $tests = []; - $body = new \Twig\Node\TextNode('foo', 1); + $body = new TextNode('foo', 1); $extends = null; - $blocks = new \Twig\Node\Node(); - $macros = new \Twig\Node\Node(); - $traits = new \Twig\Node\Node(); - $source = new \Twig\Source('{{ foo }}', 'foo.twig'); + $blocks = new Node(); + $macros = new Node(); + $traits = new Node(); + $source = new Source('{{ foo }}', 'foo.twig'); - $node = new \Twig\Node\ModuleNode($body, $extends, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source); + $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); $tests[] = [$node, <<getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['debug' => true]); - $node = new \Twig\Node\ModuleNode($body, $extends, $blocks, $macros, $traits, new \Twig\Node\Node([]), $source); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['debug' => true]); + $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); $tests[] = [$node, <<assertEquals($expr, $node->getNode('expr')); } @@ -22,7 +26,7 @@ class Twig_Tests_Node_PrintTest extends \Twig\Test\NodeTestCase public function getTests() { $tests = []; - $tests[] = [new \Twig\Node\PrintNode(new \Twig\Node\Expression\ConstantExpression('foo', 1), 1), "// line 1\necho \"foo\";"]; + $tests[] = [new PrintNode(new ConstantExpression('foo', 1), 1), "// line 1\necho \"foo\";"]; return $tests; } diff --git a/test/Twig/Tests/Node/SandboxTest.php b/test/Twig/Tests/Node/SandboxTest.php index bfb361391..2d8e1778b 100644 --- a/test/Twig/Tests/Node/SandboxTest.php +++ b/test/Twig/Tests/Node/SandboxTest.php @@ -9,12 +9,16 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SandboxTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\TextNode; +use Twig\Node\SandboxNode; + +class Twig_Tests_Node_SandboxTest extends NodeTestCase { public function testConstructor() { - $body = new \Twig\Node\TextNode('foo', 1); - $node = new \Twig\Node\SandboxNode($body, 1); + $body = new TextNode('foo', 1); + $node = new SandboxNode($body, 1); $this->assertEquals($body, $node->getNode('body')); } @@ -23,8 +27,8 @@ class Twig_Tests_Node_SandboxTest extends \Twig\Test\NodeTestCase { $tests = []; - $body = new \Twig\Node\TextNode('foo', 1); - $node = new \Twig\Node\SandboxNode($body, 1); + $body = new TextNode('foo', 1); + $node = new SandboxNode($body, 1); $tests[] = [$node, <<assertEquals($expr, $node->getNode('expr')); } @@ -22,7 +26,7 @@ class Twig_Tests_Node_SandboxedPrintTest extends \Twig\Test\NodeTestCase { $tests = []; - $tests[] = [new \Twig\Node\SandboxedPrintNode(new \Twig\Node\Expression\ConstantExpression('foo', 1), 1), <<env->getExtension('\Twig\Extension\SandboxExtension')->ensureToStringAllowed("foo"); EOF diff --git a/test/Twig/Tests/Node/SetTest.php b/test/Twig/Tests/Node/SetTest.php index d1b12d620..5e6a7ff08 100644 --- a/test/Twig/Tests/Node/SetTest.php +++ b/test/Twig/Tests/Node/SetTest.php @@ -9,13 +9,23 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SetTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Node; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\SetNode; +use Twig\Node\PrintNode; +use Twig\Markup; +use Twig\Node\TextNode; +use Twig\Node\Expression\NameExpression; + +class Twig_Tests_Node_SetTest extends NodeTestCase { public function testConstructor() { - $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1); - $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1)], [], 1); - $node = new \Twig\Node\SetNode(false, $names, $values, 1); + $names = new Node([new AssignNameExpression('foo', 1)], [], 1); + $values = new Node([new ConstantExpression('foo', 1)], [], 1); + $node = new SetNode(false, $names, $values, 1); $this->assertEquals($names, $node->getNode('names')); $this->assertEquals($values, $node->getNode('values')); @@ -26,38 +36,38 @@ class Twig_Tests_Node_SetTest extends \Twig\Test\NodeTestCase { $tests = []; - $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1); - $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1)], [], 1); - $node = new \Twig\Node\SetNode(false, $names, $values, 1); + $names = new Node([new AssignNameExpression('foo', 1)], [], 1); + $values = new Node([new ConstantExpression('foo', 1)], [], 1); + $node = new SetNode(false, $names, $values, 1); $tests[] = [$node, <<env->getCharset()); +\$context["foo"] = ('' === \$tmp = ob_get_clean()) ? '' : new Markup(\$tmp, \$this->env->getCharset()); EOF ]; - $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1)], [], 1); - $values = new \Twig\Node\TextNode('foo', 1); - $node = new \Twig\Node\SetNode(true, $names, $values, 1); + $names = new Node([new AssignNameExpression('foo', 1)], [], 1); + $values = new TextNode('foo', 1); + $node = new SetNode(true, $names, $values, 1); $tests[] = [$node, <<env->getCharset()); +\$context["foo"] = ('' === \$tmp = "foo") ? '' : new Markup(\$tmp, \$this->env->getCharset()); EOF ]; - $names = new \Twig\Node\Node([new \Twig\Node\Expression\AssignNameExpression('foo', 1), new \Twig\Node\Expression\AssignNameExpression('bar', 1)], [], 1); - $values = new \Twig\Node\Node([new \Twig\Node\Expression\ConstantExpression('foo', 1), new \Twig\Node\Expression\NameExpression('bar', 1)], [], 1); - $node = new \Twig\Node\SetNode(false, $names, $values, 1); + $names = new Node([new AssignNameExpression('foo', 1), new AssignNameExpression('bar', 1)], [], 1); + $values = new Node([new ConstantExpression('foo', 1), new NameExpression('bar', 1)], [], 1); + $node = new SetNode(false, $names, $values, 1); $tests[] = [$node, <<getVariableGetter('bar')}]; diff --git a/test/Twig/Tests/Node/SpacelessTest.php b/test/Twig/Tests/Node/SpacelessTest.php index 4cb5f996e..22e59e476 100644 --- a/test/Twig/Tests/Node/SpacelessTest.php +++ b/test/Twig/Tests/Node/SpacelessTest.php @@ -9,20 +9,25 @@ * file that was distributed with this source code. */ -class Twig_Tests_Node_SpacelessTest extends \Twig\Test\NodeTestCase +use Twig\Test\NodeTestCase; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Node\SpacelessNode; + +class Twig_Tests_Node_SpacelessTest extends NodeTestCase { public function testConstructor() { - $body = new \Twig\Node\Node([new \Twig\Node\TextNode('
foo
', 1)]); - $node = new \Twig\Node\SpacelessNode($body, 1); + $body = new Node([new TextNode('
foo
', 1)]); + $node = new SpacelessNode($body, 1); $this->assertEquals($body, $node->getNode('body')); } public function getTests() { - $body = new \Twig\Node\Node([new \Twig\Node\TextNode('
foo
', 1)]); - $node = new \Twig\Node\SpacelessNode($body, 1); + $body = new Node([new TextNode('
foo
', 1)]); + $node = new SpacelessNode($body, 1); return [ [$node, <<assertEquals('foo', $node->getAttribute('data')); } @@ -21,7 +24,7 @@ class Twig_Tests_Node_TextTest extends \Twig\Test\NodeTestCase public function getTests() { $tests = []; - $tests[] = [new \Twig\Node\TextNode('foo', 1), "// line 1\necho \"foo\";"]; + $tests[] = [new TextNode('foo', 1), "// line 1\necho \"foo\";"]; return $tests; } diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 0f5d2e347..83969d703 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -8,13 +8,17 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + +use Twig\Environment; +use Twig\Source; +use Twig\Node\ForNode; class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase { public function testRenderBlockOptimizer() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->parse($env->tokenize(new \Twig\Source('{{ block("foo") }}', 'index'))); + $stream = $env->parse($env->tokenize(new Source('{{ block("foo") }}', 'index'))); $node = $stream->getNode('body')->getNode(0); @@ -24,9 +28,9 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase public function testRenderParentBlockOptimizer() { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->parse($env->tokenize(new \Twig\Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index'))); + $stream = $env->parse($env->tokenize(new Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index'))); $node = $stream->getNode('blocks')->getNode('content')->getNode(0)->getNode('body'); @@ -40,8 +44,8 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase $this->markTestSkipped('not needed on PHP >= 5.4'); } - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); - $stream = $env->parse($env->tokenize(new \Twig\Source('{{ block(name|lower) }}', 'index'))); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false, 'autoescape' => false]); + $stream = $env->parse($env->tokenize(new Source('{{ block(name|lower) }}', 'index'))); $node = $stream->getNode('body')->getNode(0)->getNode(1); @@ -54,9 +58,9 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase */ public function testForOptimizer($template, $expected) { - $env = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false]); + $env = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['cache' => false]); - $stream = $env->parse($env->tokenize(new \Twig\Source($template, 'index'))); + $stream = $env->parse($env->tokenize(new Source($template, 'index'))); foreach ($expected as $target => $withLoop) { $this->assertTrue($this->checkForConfiguration($stream, $target, $withLoop), sprintf('variable %s is %soptimized', $target, $withLoop ? 'not ' : '')); @@ -109,7 +113,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase } foreach ($node as $n) { - if ($n instanceof \Twig\Node\ForNode) { + if ($n instanceof ForNode) { if ($target === $n->getNode('value_target')->getAttribute('name')) { return $withLoop == $n->getAttribute('with_loop'); } diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 4f8299eb5..2a07e7341 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -8,6 +8,16 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + +use Twig\TokenStream; +use Twig\Token; +use Twig\Parser; +use Twig\Environment; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Node\SetNode; +use Twig\Source; +use Twig\TokenParser\AbstractTokenParser; class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase { /** @@ -25,13 +35,13 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownTag() { - $stream = new \Twig\TokenStream([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), - new \Twig\Token(\Twig\Token::NAME_TYPE, 'foo', 1), - new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), - new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), + $stream = new TokenStream([ + new Token(Token::BLOCK_START_TYPE, '', 1), + new Token(Token::NAME_TYPE, 'foo', 1), + new Token(Token::BLOCK_END_TYPE, '', 1), + new Token(Token::EOF_TYPE, '', 1), ]); - $parser = new \Twig\Parser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $parser = new Parser(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $parser->parse($stream); } @@ -41,13 +51,13 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase */ public function testUnknownTagWithoutSuggestions() { - $stream = new \Twig\TokenStream([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), - new \Twig\Token(\Twig\Token::NAME_TYPE, 'foobar', 1), - new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), - new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), + $stream = new TokenStream([ + new Token(Token::BLOCK_START_TYPE, '', 1), + new Token(Token::NAME_TYPE, 'foobar', 1), + new Token(Token::BLOCK_END_TYPE, '', 1), + new Token(Token::EOF_TYPE, '', 1), ]); - $parser = new \Twig\Parser(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $parser = new Parser(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $parser->parse($stream); } @@ -65,15 +75,15 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase { return [ [ - new \Twig\Node\Node([new \Twig\Node\TextNode(' ', 1)]), - new \Twig\Node\Node([]), + new Node([new TextNode(' ', 1)]), + new Node([]), ], [ - $input = new \Twig\Node\Node([new \Twig\Node\SetNode(false, new \Twig\Node\Node(), new \Twig\Node\Node(), 1)]), + $input = new Node([new SetNode(false, new Node(), new Node(), 1)]), $input, ], [ - $input = new \Twig\Node\Node([new \Twig\Node\SetNode(true, new \Twig\Node\Node(), new \Twig\Node\Node([new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)])]), 1)]), + $input = new Node([new SetNode(true, new Node(), new Node([new Node([new TextNode('foo', 1)])]), 1)]), $input, ], ]; @@ -93,8 +103,8 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase public function getFilterBodyNodesDataThrowsException() { return [ - [new \Twig\Node\TextNode('foo', 1)], - [new \Twig\Node\Node([new \Twig\Node\Node([new \Twig\Node\TextNode('foo', 1)])])], + [new TextNode('foo', 1)], + [new Node([new Node([new TextNode('foo', 1)])])], ]; } @@ -103,7 +113,7 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase */ public function testFilterBodyNodesWithBOM($emptyNode) { - $this->assertNull($this->getParser()->filterBodyNodes(new \Twig\Node\TextNode(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1))); + $this->assertNull($this->getParser()->filterBodyNodes(new TextNode(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1))); } public function getFilterBodyNodesWithBOMData() @@ -118,22 +128,22 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase public function testParseIsReentrant() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [ + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [ 'autoescape' => false, 'optimizations' => 0, ]); $twig->addTokenParser(new TestTokenParser()); - $parser = new \Twig\Parser($twig); + $parser = new Parser($twig); - $parser->parse(new \Twig\TokenStream([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), - new \Twig\Token(\Twig\Token::NAME_TYPE, 'test', 1), - new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), - new \Twig\Token(\Twig\Token::VAR_START_TYPE, '', 1), - new \Twig\Token(\Twig\Token::NAME_TYPE, 'foo', 1), - new \Twig\Token(\Twig\Token::VAR_END_TYPE, '', 1), - new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), + $parser->parse(new TokenStream([ + new Token(Token::BLOCK_START_TYPE, '', 1), + new Token(Token::NAME_TYPE, 'test', 1), + new Token(Token::BLOCK_END_TYPE, '', 1), + new Token(Token::VAR_START_TYPE, '', 1), + new Token(Token::NAME_TYPE, 'foo', 1), + new Token(Token::VAR_END_TYPE, '', 1), + new Token(Token::EOF_TYPE, '', 1), ])); $this->assertNull($parser->getParent()); @@ -141,12 +151,12 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase public function testGetVarName() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [ + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), [ 'autoescape' => false, 'optimizations' => 0, ]); - $twig->parse($twig->tokenize(new \Twig\Source(<<parse($twig->tokenize(new Source(<<getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); - $parser->setParent(new \Twig\Node\Node()); - $parser->stream = new \Twig\TokenStream([]); + $parser = new TestParser(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $parser->setParent(new Node()); + $parser->stream = new TokenStream([]); return $parser; } } -class TestParser extends \Twig\Parser +class TestParser extends Parser { public $stream; @@ -181,22 +191,22 @@ class TestParser extends \Twig\Parser } } -class TestTokenParser extends \Twig\TokenParser\AbstractTokenParser +class TestTokenParser extends AbstractTokenParser { - public function parse(\Twig\Token $token) + public function parse(Token $token) { // simulate the parsing of another template right in the middle of the parsing of the current template - $this->parser->parse(new \Twig\TokenStream([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, '', 1), - new \Twig\Token(\Twig\Token::NAME_TYPE, 'extends', 1), - new \Twig\Token(\Twig\Token::STRING_TYPE, 'base', 1), - new \Twig\Token(\Twig\Token::BLOCK_END_TYPE, '', 1), - new \Twig\Token(\Twig\Token::EOF_TYPE, '', 1), + $this->parser->parse(new TokenStream([ + new Token(Token::BLOCK_START_TYPE, '', 1), + new Token(Token::NAME_TYPE, 'extends', 1), + new Token(Token::STRING_TYPE, 'base', 1), + new Token(Token::BLOCK_END_TYPE, '', 1), + new Token(Token::EOF_TYPE, '', 1), ])); - $this->parser->getStream()->expect(\Twig\Token::BLOCK_END_TYPE); + $this->parser->getStream()->expect(Token::BLOCK_END_TYPE); - return new \Twig\Node\Node([]); + return new Node([]); } public function getTag() diff --git a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php index 62f3821cf..bf25b7328 100644 --- a/test/Twig/Tests/Profiler/Dumper/AbstractTest.php +++ b/test/Twig/Tests/Profiler/Dumper/AbstractTest.php @@ -9,6 +9,8 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Profile; + abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framework\TestCase { protected function getProfile() @@ -79,7 +81,7 @@ abstract class Twig_Tests_Profiler_Dumper_AbstractTest extends \PHPUnit\Framewor * @param string $templateName * @param array $subProfiles * - * @return \Twig\Profiler\Profile + * @return Profile */ private function generateProfile($name, $duration, $isTemplate, $type, $templateName, array $subProfiles = []) { diff --git a/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php b/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php index 23846630e..26ef2dad2 100644 --- a/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php +++ b/test/Twig/Tests/Profiler/Dumper/BlackfireTest.php @@ -9,11 +9,13 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Dumper\BlackfireDumper; + class Twig_Tests_Profiler_Dumper_BlackfireTest extends Twig_Tests_Profiler_Dumper_AbstractTest { public function testDump() { - $dumper = new \Twig\Profiler\Dumper\BlackfireDumper(); + $dumper = new BlackfireDumper(); $this->assertStringMatchesFormat(<<assertStringMatchesFormat(<<main %d.%dms/%d% â”” index.twig %d.%dms/%d% diff --git a/test/Twig/Tests/Profiler/Dumper/TextTest.php b/test/Twig/Tests/Profiler/Dumper/TextTest.php index fbd7475c0..e36d0ad60 100644 --- a/test/Twig/Tests/Profiler/Dumper/TextTest.php +++ b/test/Twig/Tests/Profiler/Dumper/TextTest.php @@ -9,11 +9,13 @@ * file that was distributed with this source code. */ +use Twig\Profiler\Dumper\TextDumper; + class Twig_Tests_Profiler_Dumper_TextTest extends Twig_Tests_Profiler_Dumper_AbstractTest { public function testDump() { - $dumper = new \Twig\Profiler\Dumper\TextDumper(); + $dumper = new TextDumper(); $this->assertStringMatchesFormat(<<assertEquals('template', $profile->getTemplate()); $this->assertEquals('type', $profile->getType()); @@ -22,45 +24,45 @@ class Twig_Tests_Profiler_ProfileTest extends \PHPUnit\Framework\TestCase public function testIsRoot() { - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); + $profile = new Profile('template', Profile::ROOT); $this->assertTrue($profile->isRoot()); - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::TEMPLATE); + $profile = new Profile('template', Profile::TEMPLATE); $this->assertFalse($profile->isRoot()); } public function testIsTemplate() { - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::TEMPLATE); + $profile = new Profile('template', Profile::TEMPLATE); $this->assertTrue($profile->isTemplate()); - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); + $profile = new Profile('template', Profile::ROOT); $this->assertFalse($profile->isTemplate()); } public function testIsBlock() { - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::BLOCK); + $profile = new Profile('template', Profile::BLOCK); $this->assertTrue($profile->isBlock()); - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); + $profile = new Profile('template', Profile::ROOT); $this->assertFalse($profile->isBlock()); } public function testIsMacro() { - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::MACRO); + $profile = new Profile('template', Profile::MACRO); $this->assertTrue($profile->isMacro()); - $profile = new \Twig\Profiler\Profile('template', \Twig\Profiler\Profile::ROOT); + $profile = new Profile('template', Profile::ROOT); $this->assertFalse($profile->isMacro()); } public function testGetAddProfile() { - $profile = new \Twig\Profiler\Profile(); - $profile->addProfile($a = new \Twig\Profiler\Profile()); - $profile->addProfile($b = new \Twig\Profiler\Profile()); + $profile = new Profile(); + $profile->addProfile($a = new Profile()); + $profile->addProfile($b = new Profile()); $this->assertSame([$a, $b], $profile->getProfiles()); $this->assertSame([$a, $b], iterator_to_array($profile)); @@ -68,7 +70,7 @@ class Twig_Tests_Profiler_ProfileTest extends \PHPUnit\Framework\TestCase public function testGetDuration() { - $profile = new \Twig\Profiler\Profile(); + $profile = new Profile(); usleep(1); $profile->leave(); @@ -77,8 +79,8 @@ class Twig_Tests_Profiler_ProfileTest extends \PHPUnit\Framework\TestCase public function testSerialize() { - $profile = new \Twig\Profiler\Profile('template', 'type', 'name'); - $profile1 = new \Twig\Profiler\Profile('template1', 'type1', 'name1'); + $profile = new Profile('template', 'type', 'name'); + $profile1 = new Profile('template1', 'type1', 'name1'); $profile->addProfile($profile1); $profile->leave(); $profile1->leave(); @@ -100,7 +102,7 @@ class Twig_Tests_Profiler_ProfileTest extends \PHPUnit\Framework\TestCase public function testReset() { - $profile = new \Twig\Profiler\Profile(); + $profile = new Profile(); usleep(1); $profile->leave(); $profile->reset(); diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index eb499d4d4..56808cbc6 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -8,6 +8,17 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + +use Twig\Environment; +use Twig\Loader\ArrayLoader; +use Twig\Sandbox\SecurityPolicy; +use Twig\Extension\SandboxExtension; +use Twig\Template; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Loader\LoaderInterface; +use Twig\Error\RuntimeError; +use Twig\Sandbox\SecurityError; class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase { /** @@ -25,7 +36,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase public function testGetAttributeExceptions($template, $message) { $templates = ['index' => $template]; - $env = new \Twig\Environment(new \Twig\Loader\ArrayLoader($templates), ['strict_variables' => true]); + $env = new Environment(new ArrayLoader($templates), ['strict_variables' => true]); $template = $env->loadTemplate('index'); $context = [ @@ -41,7 +52,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase try { $template->render($context); $this->fail('Accessing an invalid attribute should throw an exception.'); - } catch (\Twig\Error\RuntimeError $e) { + } catch (RuntimeError $e) { $this->assertSame(sprintf($message, 'index'), $e->getMessage()); } } @@ -74,9 +85,9 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testGetAttributeWithSandbox($object, $item, $allowed) { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); - $policy = new \Twig\Sandbox\SecurityPolicy([], [], [/*method*/], [/*prop*/], []); - $twig->addExtension(new \Twig\Extension\SandboxExtension($policy, !$allowed)); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $policy = new SecurityPolicy([], [], [/*method*/], [/*prop*/], []); + $twig->addExtension(new SandboxExtension($policy, !$allowed)); $template = new Twig_TemplateTest($twig); try { @@ -87,7 +98,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase } else { $this->addToAssertionCount(1); } - } catch (\Twig\Sandbox\SecurityError $e) { + } catch (SecurityError $e) { if ($allowed) { $this->fail(); } else { @@ -114,8 +125,8 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase public function testGetAttributeWithTemplateAsObject() { // to be removed in 2.0 - $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); - //$twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + //$twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock()); $template = new Twig_TemplateTest($twig, 'index.twig'); $template1 = new Twig_TemplateTest($twig, 'index1.twig'); @@ -132,10 +143,10 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase $this->assertNotInstanceof('\Twig\Markup', $template->getAttribute($template1, 'empty')); $this->assertSame('', $template->getAttribute($template1, 'empty')); - $this->assertFalse($template->getAttribute($template1, 'env', [], \Twig\Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'environment', [], \Twig\Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], \Twig\Template::METHOD_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], \Twig\Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'env', [], Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'environment', [], Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], Template::METHOD_CALL, true)); } /** @@ -162,8 +173,8 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase public function testGetAttributeWithTemplateAsObjectForDeprecations() { // to be removed in 2.0 - $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); - //$twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + //$twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface', '\Twig\Loader\SourceContextLoaderInterface')->getMock()); $template = new Twig_TemplateTest($twig, 'index.twig'); $template1 = new Twig_TemplateTest($twig, 'index1.twig'); @@ -195,10 +206,10 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase $template->getAttribute($template1, 'render', [[]]); $template->getAttribute($template1, 'display', [[]]); - $this->assertFalse($template->getAttribute($template1, 'env', [], \Twig\Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'environment', [], \Twig\Template::ANY_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], \Twig\Template::METHOD_CALL, true)); - $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], \Twig\Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'env', [], Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'environment', [], Template::ANY_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'getEnvironment', [], Template::METHOD_CALL, true)); + $this->assertFalse($template->getAttribute($template1, 'displayWithErrorHandling', [], Template::METHOD_CALL, true)); } /** @@ -208,7 +219,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testRenderBlockWithUndefinedBlock() { - $twig = new \Twig\Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); + $twig = new Environment($this->getMockBuilder('Twig_TemplateTestLoaderInterface')->getMock()); $template = new Twig_TemplateTest($twig, 'index.twig'); $template->renderBlock('unknown', []); @@ -217,7 +228,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase public function testGetAttributeOnArrayWithConfusableKey() { - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $array = ['Zero', 'One', -1 => 'MinusOne', '' => 'EmptyString', '1.5' => 'FloatButString', '01' => 'IntegerButStringWithLeadingZeros']; @@ -245,7 +256,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testGetAttribute($defined, $value, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); } @@ -255,7 +266,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testGetAttributeStrict($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null) { - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); if ($defined) { $this->assertEquals($value, $template->getAttribute($object, $item, $arguments, $type)); @@ -277,7 +288,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true)); } @@ -287,14 +298,14 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase */ public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type) { - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); $this->assertEquals($defined, $template->getAttribute($object, $item, $arguments, $type, true)); } public function testGetAttributeCallExceptions() { - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock())); $object = new Twig_TemplateMagicMethodExceptionObject(); @@ -325,9 +336,9 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase $methodObject = new Twig_TemplateMethodObject(); $magicMethodObject = new Twig_TemplateMagicMethodObject(); - $anyType = \Twig\Template::ANY_CALL; - $methodType = \Twig\Template::METHOD_CALL; - $arrayType = \Twig\Template::ARRAY_CALL; + $anyType = Template::ANY_CALL; + $methodType = Template::METHOD_CALL; + $arrayType = Template::ARRAY_CALL; $basicTests = [ // array(defined, value, property to fetch) @@ -439,7 +450,7 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase public function testGetIsMethods() { $getIsObject = new Twig_TemplateGetIsMethods(); - $template = new Twig_TemplateTest(new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); + $template = new Twig_TemplateTest(new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock(), ['strict_variables' => true])); // first time should not create a cache for "get" $this->assertNull($template->getAttribute($getIsObject, 'get')); // 0 should be in the method cache now, so this should fail @@ -447,11 +458,11 @@ class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase } } -class Twig_TemplateTest extends \Twig\Template +class Twig_TemplateTest extends Template { private $name; - public function __construct(\Twig\Environment $env, $name = 'index.twig') + public function __construct(Environment $env, $name = 'index.twig') { parent::__construct($env); self::$cache = []; @@ -497,7 +508,7 @@ class Twig_TemplateTest extends \Twig\Template { } - public function getAttribute($object, $item, array $arguments = [], $type = \Twig\Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) + public function getAttribute($object, $item, array $arguments = [], $type = Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { if (\function_exists('twig_template_get_attributes')) { return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); @@ -771,18 +782,18 @@ class Twig_TemplateMagicMethodExceptionObject } } -class CExtDisablingNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface +class CExtDisablingNodeVisitor implements NodeVisitorInterface { - public function enterNode(Twig_NodeInterface $node, \Twig\Environment $env) + public function enterNode(Twig_NodeInterface $node, Environment $env) { - if ($node instanceof \Twig\Node\Expression\GetAttrExpression) { + if ($node instanceof GetAttrExpression) { $node->setAttribute('disable_c_ext', true); } return $node; } - public function leaveNode(Twig_NodeInterface $node, \Twig\Environment $env) + public function leaveNode(Twig_NodeInterface $node, Environment $env) { return $node; } @@ -794,6 +805,6 @@ class CExtDisablingNodeVisitor implements \Twig\NodeVisitor\NodeVisitorInterface } // to be removed in 2.0 -interface Twig_TemplateTestLoaderInterface extends \Twig\Loader\LoaderInterface, Twig_SourceContextLoaderInterface +interface Twig_TemplateTestLoaderInterface extends LoaderInterface, Twig_SourceContextLoaderInterface { } diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php index 68646e80f..3242dd024 100644 --- a/test/Twig/Tests/TemplateWrapperTest.php +++ b/test/Twig/Tests/TemplateWrapperTest.php @@ -8,11 +8,15 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + +use Twig\Environment; +use Twig\Loader\ArrayLoader; +use Twig\TemplateWrapper; class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase { public function testHasGetBlocks() { - $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ + $twig = new Environment(new ArrayLoader([ 'index' => '{% block foo %}{% endblock %}', 'index_with_use' => '{% use "imported" %}{% block foo %}{% endblock %}', 'index_with_extends' => '{% extends "extended" %}{% block foo %}{% endblock %}', @@ -20,17 +24,17 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase 'extended' => '{% block extended %}{% endblock %}', ])); - $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertFalse($wrapper->hasBlock('bar')); $this->assertEquals(['foo'], $wrapper->getBlockNames()); - $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index_with_use')); + $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index_with_use')); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('imported')); $this->assertEquals(['imported', 'foo'], $wrapper->getBlockNames()); - $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index_with_extends')); + $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index_with_extends')); $this->assertTrue($wrapper->hasBlock('foo')); $this->assertTrue($wrapper->hasBlock('extended')); $this->assertEquals(['foo', 'extended'], $wrapper->getBlockNames()); @@ -38,23 +42,23 @@ class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase public function testRenderBlock() { - $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ + $twig = new Environment(new ArrayLoader([ 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}', ])); $twig->addGlobal('bar', 'BAR'); - $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); $this->assertEquals('FOOBAR', $wrapper->renderBlock('foo', ['foo' => 'FOO'])); } public function testDisplayBlock() { - $twig = new \Twig\Environment(new \Twig\Loader\ArrayLoader([ + $twig = new Environment(new ArrayLoader([ 'index' => '{% block foo %}{{ foo }}{{ bar }}{% endblock %}', ])); $twig->addGlobal('bar', 'BAR'); - $wrapper = new \Twig\TemplateWrapper($twig, $twig->loadTemplate('index')); + $wrapper = new TemplateWrapper($twig, $twig->loadTemplate('index')); ob_start(); $wrapper->displayBlock('foo', ['foo' => 'FOO']); diff --git a/test/Twig/Tests/TokenStreamTest.php b/test/Twig/Tests/TokenStreamTest.php index a7f4d181c..e5cd568b0 100644 --- a/test/Twig/Tests/TokenStreamTest.php +++ b/test/Twig/Tests/TokenStreamTest.php @@ -9,6 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Token; +use Twig\TokenStream; + class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase { protected static $tokens; @@ -16,14 +19,14 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase protected function setUp() { self::$tokens = [ - new \Twig\Token(\Twig\Token::TEXT_TYPE, 1, 1), - new \Twig\Token(\Twig\Token::TEXT_TYPE, 2, 1), - new \Twig\Token(\Twig\Token::TEXT_TYPE, 3, 1), - new \Twig\Token(\Twig\Token::TEXT_TYPE, 4, 1), - new \Twig\Token(\Twig\Token::TEXT_TYPE, 5, 1), - new \Twig\Token(\Twig\Token::TEXT_TYPE, 6, 1), - new \Twig\Token(\Twig\Token::TEXT_TYPE, 7, 1), - new \Twig\Token(\Twig\Token::EOF_TYPE, 0, 1), + new Token(Token::TEXT_TYPE, 1, 1), + new Token(Token::TEXT_TYPE, 2, 1), + new Token(Token::TEXT_TYPE, 3, 1), + new Token(Token::TEXT_TYPE, 4, 1), + new Token(Token::TEXT_TYPE, 5, 1), + new Token(Token::TEXT_TYPE, 6, 1), + new Token(Token::TEXT_TYPE, 7, 1), + new Token(Token::EOF_TYPE, 0, 1), ]; } @@ -32,7 +35,7 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase */ public function testLegacyConstructorSignature() { - $stream = new \Twig\TokenStream([], 'foo', '{{ foo }}'); + $stream = new TokenStream([], 'foo', '{{ foo }}'); $this->assertEquals('foo', $stream->getFilename()); $this->assertEquals('{{ foo }}', $stream->getSource()); $this->assertEquals('foo', $stream->getSourceContext()->getName()); @@ -41,7 +44,7 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase public function testNext() { - $stream = new \Twig\TokenStream(self::$tokens); + $stream = new TokenStream(self::$tokens); $repr = []; while (!$stream->isEOF()) { $token = $stream->next(); @@ -57,8 +60,8 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase */ public function testEndOfTemplateNext() { - $stream = new \Twig\TokenStream([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, 1, 1), + $stream = new TokenStream([ + new Token(Token::BLOCK_START_TYPE, 1, 1), ]); while (!$stream->isEOF()) { $stream->next(); @@ -71,8 +74,8 @@ class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase */ public function testEndOfTemplateLook() { - $stream = new \Twig\TokenStream([ - new \Twig\Token(\Twig\Token::BLOCK_START_TYPE, 1, 1), + $stream = new TokenStream([ + new Token(Token::BLOCK_START_TYPE, 1, 1), ]); while (!$stream->isEOF()) { $stream->look(); diff --git a/test/Twig/Tests/Util/DeprecationCollectorTest.php b/test/Twig/Tests/Util/DeprecationCollectorTest.php index 5d72f9407..0f577c60f 100644 --- a/test/Twig/Tests/Util/DeprecationCollectorTest.php +++ b/test/Twig/Tests/Util/DeprecationCollectorTest.php @@ -9,6 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\TwigFunction; +use Twig\Util\DeprecationCollector; + class Twig_Tests_Util_DeprecationCollectorTest extends \PHPUnit\Framework\TestCase { /** @@ -16,10 +20,10 @@ class Twig_Tests_Util_DeprecationCollectorTest extends \PHPUnit\Framework\TestCa */ public function testCollect() { - $twig = new \Twig\Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); - $twig->addFunction(new \Twig\TwigFunction('deprec', [$this, 'deprec'], ['deprecated' => true])); + $twig = new Environment($this->getMockBuilder('\Twig\Loader\LoaderInterface')->getMock()); + $twig->addFunction(new TwigFunction('deprec', [$this, 'deprec'], ['deprecated' => true])); - $collector = new \Twig\Util\DeprecationCollector($twig); + $collector = new DeprecationCollector($twig); $deprecations = $collector->collect(new Twig_Tests_Util_Iterator()); $this->assertEquals(['Twig Function "deprec" is deprecated in deprec.twig at line 1.'], $deprecations); From e9919c21872b6efe9010c512c5605260cde11d18 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 17 Feb 2019 10:53:37 +0100 Subject: [PATCH 3/3] fixed CS --- lib/Twig/BaseNodeVisitor.php | 4 +- lib/Twig/ContainerRuntimeLoader.php | 3 +- lib/Twig/Environment.php | 66 +++++++++---------- lib/Twig/Error.php | 6 +- lib/Twig/ExpressionParser.php | 28 ++++---- lib/Twig/Extension.php | 2 +- lib/Twig/Extension/Core.php | 40 +++++------ lib/Twig/Extension/Debug.php | 2 +- lib/Twig/Extension/Escaper.php | 2 +- lib/Twig/Extension/Sandbox.php | 2 +- lib/Twig/Extension/StringLoader.php | 2 +- lib/Twig/ExtensionInterface.php | 10 +-- lib/Twig/Lexer.php | 8 +-- lib/Twig/LexerInterface.php | 4 +- lib/Twig/Loader/Array.php | 2 +- lib/Twig/Loader/Chain.php | 4 +- lib/Twig/Loader/Filesystem.php | 2 +- lib/Twig/Node.php | 2 +- lib/Twig/Node/AutoEscape.php | 2 +- lib/Twig/Node/Block.php | 2 +- lib/Twig/Node/BlockReference.php | 2 +- lib/Twig/Node/CheckSecurity.php | 6 +- lib/Twig/Node/Deprecated.php | 6 +- lib/Twig/Node/Do.php | 4 +- lib/Twig/Node/Embed.php | 4 +- lib/Twig/Node/Expression/Array.php | 3 +- lib/Twig/Node/Expression/AssignName.php | 2 +- lib/Twig/Node/Expression/Binary.php | 3 +- lib/Twig/Node/Expression/Binary/Add.php | 3 +- lib/Twig/Node/Expression/Binary/And.php | 3 +- .../Node/Expression/Binary/BitwiseAnd.php | 3 +- lib/Twig/Node/Expression/Binary/BitwiseOr.php | 3 +- .../Node/Expression/Binary/BitwiseXor.php | 3 +- lib/Twig/Node/Expression/Binary/Concat.php | 3 +- lib/Twig/Node/Expression/Binary/Div.php | 3 +- lib/Twig/Node/Expression/Binary/EndsWith.php | 3 +- lib/Twig/Node/Expression/Binary/Equal.php | 3 +- lib/Twig/Node/Expression/Binary/FloorDiv.php | 3 +- lib/Twig/Node/Expression/Binary/Greater.php | 3 +- .../Node/Expression/Binary/GreaterEqual.php | 3 +- lib/Twig/Node/Expression/Binary/In.php | 3 +- lib/Twig/Node/Expression/Binary/Less.php | 3 +- lib/Twig/Node/Expression/Binary/LessEqual.php | 3 +- lib/Twig/Node/Expression/Binary/Matches.php | 3 +- lib/Twig/Node/Expression/Binary/Mod.php | 3 +- lib/Twig/Node/Expression/Binary/Mul.php | 3 +- lib/Twig/Node/Expression/Binary/NotEqual.php | 3 +- lib/Twig/Node/Expression/Binary/NotIn.php | 3 +- lib/Twig/Node/Expression/Binary/Or.php | 3 +- lib/Twig/Node/Expression/Binary/Power.php | 3 +- lib/Twig/Node/Expression/Binary/Range.php | 3 +- .../Node/Expression/Binary/StartsWith.php | 3 +- lib/Twig/Node/Expression/Binary/Sub.php | 3 +- lib/Twig/Node/Expression/BlockReference.php | 2 +- lib/Twig/Node/Expression/Call.php | 13 ++-- lib/Twig/Node/Expression/Conditional.php | 3 +- lib/Twig/Node/Expression/Constant.php | 3 +- .../Node/Expression/ExtensionReference.php | 2 +- lib/Twig/Node/Expression/Filter.php | 5 +- lib/Twig/Node/Expression/Filter/Default.php | 8 +-- lib/Twig/Node/Expression/Function.php | 3 +- lib/Twig/Node/Expression/GetAttr.php | 3 +- lib/Twig/Node/Expression/MethodCall.php | 5 +- lib/Twig/Node/Expression/Name.php | 3 +- lib/Twig/Node/Expression/NullCoalesce.php | 15 +++-- lib/Twig/Node/Expression/Parent.php | 2 +- lib/Twig/Node/Expression/TempName.php | 3 +- lib/Twig/Node/Expression/Test.php | 3 +- lib/Twig/Node/Expression/Test/Constant.php | 2 +- lib/Twig/Node/Expression/Test/Defined.php | 16 ++--- lib/Twig/Node/Expression/Test/Divisibleby.php | 2 +- lib/Twig/Node/Expression/Test/Even.php | 2 +- lib/Twig/Node/Expression/Test/Null.php | 2 +- lib/Twig/Node/Expression/Test/Odd.php | 2 +- lib/Twig/Node/Expression/Test/Sameas.php | 2 +- lib/Twig/Node/Expression/Unary.php | 3 +- lib/Twig/Node/Expression/Unary/Neg.php | 3 +- lib/Twig/Node/Expression/Unary/Not.php | 3 +- lib/Twig/Node/Expression/Unary/Pos.php | 3 +- lib/Twig/Node/Flush.php | 2 +- lib/Twig/Node/For.php | 8 +-- lib/Twig/Node/ForLoop.php | 2 +- lib/Twig/Node/If.php | 2 +- lib/Twig/Node/Import.php | 6 +- lib/Twig/Node/Include.php | 5 +- lib/Twig/Node/Macro.php | 5 +- lib/Twig/Node/Module.php | 14 ++-- lib/Twig/Node/Print.php | 4 +- lib/Twig/Node/Sandbox.php | 2 +- lib/Twig/Node/SandboxedPrint.php | 6 +- lib/Twig/Node/Set.php | 5 +- lib/Twig/Node/SetTemp.php | 2 +- lib/Twig/Node/Spaceless.php | 2 +- lib/Twig/Node/Text.php | 2 +- lib/Twig/Node/With.php | 3 +- lib/Twig/NodeTraverser.php | 2 +- lib/Twig/NodeVisitor/Escaper.php | 16 ++--- lib/Twig/NodeVisitor/Optimizer.php | 30 ++++----- lib/Twig/NodeVisitor/SafeAnalysis.php | 10 +-- lib/Twig/NodeVisitor/Sandbox.php | 12 ++-- lib/Twig/Parser.php | 32 ++++----- lib/Twig/ParserInterface.php | 2 +- lib/Twig/Profiler/Node/EnterProfile.php | 2 +- lib/Twig/Profiler/Node/LeaveProfile.php | 2 +- lib/Twig/Profiler/NodeVisitor/Profiler.php | 12 ++-- lib/Twig/Sandbox/SecurityPolicy.php | 6 +- lib/Twig/SourceContextLoaderInterface.php | 2 +- lib/Twig/Template.php | 10 +-- lib/Twig/TemplateWrapper.php | 2 +- lib/Twig/Test/IntegrationTestCase.php | 15 ++--- lib/Twig/Test/NodeTestCase.php | 3 +- lib/Twig/TokenParser.php | 2 +- lib/Twig/TokenParser/AutoEscape.php | 4 +- lib/Twig/TokenParser/Block.php | 4 +- lib/Twig/TokenParser/Deprecated.php | 2 +- lib/Twig/TokenParser/Do.php | 2 +- lib/Twig/TokenParser/Embed.php | 6 +- lib/Twig/TokenParser/Extends.php | 2 +- lib/Twig/TokenParser/Filter.php | 4 +- lib/Twig/TokenParser/Flush.php | 2 +- lib/Twig/TokenParser/For.php | 8 +-- lib/Twig/TokenParser/From.php | 6 +- lib/Twig/TokenParser/If.php | 2 +- lib/Twig/TokenParser/Import.php | 2 +- lib/Twig/TokenParser/Include.php | 2 +- lib/Twig/TokenParser/Macro.php | 4 +- lib/Twig/TokenParser/Sandbox.php | 6 +- lib/Twig/TokenParser/Set.php | 2 +- lib/Twig/TokenParser/Spaceless.php | 2 +- lib/Twig/TokenParser/Use.php | 4 +- lib/Twig/TokenParser/With.php | 2 +- lib/Twig/TokenStream.php | 2 +- lib/Twig/Util/DeprecationCollector.php | 4 +- test/Twig/Tests/EnvironmentTest.php | 16 ++--- test/Twig/Tests/ErrorTest.php | 8 +-- test/Twig/Tests/ExpressionParserTest.php | 8 +-- test/Twig/Tests/Extension/SandboxTest.php | 4 +- test/Twig/Tests/IntegrationTest.php | 12 ++-- test/Twig/Tests/LegacyIntegrationTest.php | 2 +- test/Twig/Tests/LexerTest.php | 3 +- test/Twig/Tests/Loader/ChainTest.php | 4 +- test/Twig/Tests/Loader/FilesystemTest.php | 2 +- test/Twig/Tests/Node/AutoEscapeTest.php | 4 +- test/Twig/Tests/Node/BlockReferenceTest.php | 2 +- test/Twig/Tests/Node/BlockTest.php | 4 +- test/Twig/Tests/Node/DeprecatedTest.php | 12 ++-- test/Twig/Tests/Node/DoTest.php | 4 +- test/Twig/Tests/Node/Expression/ArrayTest.php | 4 +- .../Tests/Node/Expression/AssignNameTest.php | 2 +- .../Tests/Node/Expression/Binary/AddTest.php | 4 +- .../Tests/Node/Expression/Binary/AndTest.php | 4 +- .../Node/Expression/Binary/ConcatTest.php | 4 +- .../Tests/Node/Expression/Binary/DivTest.php | 4 +- .../Node/Expression/Binary/FloorDivTest.php | 4 +- .../Tests/Node/Expression/Binary/ModTest.php | 4 +- .../Tests/Node/Expression/Binary/MulTest.php | 4 +- .../Tests/Node/Expression/Binary/OrTest.php | 4 +- .../Tests/Node/Expression/Binary/SubTest.php | 4 +- .../Tests/Node/Expression/ConditionalTest.php | 4 +- .../Tests/Node/Expression/ConstantTest.php | 2 +- .../Twig/Tests/Node/Expression/FilterTest.php | 8 +-- .../Tests/Node/Expression/FunctionTest.php | 8 +-- .../Tests/Node/Expression/GetAttrTest.php | 6 +- test/Twig/Tests/Node/Expression/NameTest.php | 4 +- .../Node/Expression/NullCoalesceTest.php | 4 +- .../Twig/Tests/Node/Expression/ParentTest.php | 2 +- test/Twig/Tests/Node/Expression/TestTest.php | 10 +-- .../Tests/Node/Expression/Unary/NegTest.php | 2 +- .../Tests/Node/Expression/Unary/NotTest.php | 2 +- .../Tests/Node/Expression/Unary/PosTest.php | 2 +- test/Twig/Tests/Node/ForTest.php | 6 +- test/Twig/Tests/Node/IfTest.php | 6 +- test/Twig/Tests/Node/ImportTest.php | 4 +- test/Twig/Tests/Node/IncludeTest.php | 7 +- test/Twig/Tests/Node/MacroTest.php | 9 ++- test/Twig/Tests/Node/ModuleTest.php | 16 ++--- test/Twig/Tests/Node/PrintTest.php | 2 +- test/Twig/Tests/Node/SandboxTest.php | 4 +- test/Twig/Tests/Node/SandboxedPrintTest.php | 4 +- test/Twig/Tests/Node/SetTest.php | 11 ++-- test/Twig/Tests/Node/SpacelessTest.php | 4 +- test/Twig/Tests/Node/TextTest.php | 2 +- test/Twig/Tests/NodeVisitor/OptimizerTest.php | 3 +- test/Twig/Tests/ParserTest.php | 9 +-- test/Twig/Tests/TemplateTest.php | 15 +++-- test/Twig/Tests/TemplateWrapperTest.php | 1 + 186 files changed, 514 insertions(+), 483 deletions(-) diff --git a/lib/Twig/BaseNodeVisitor.php b/lib/Twig/BaseNodeVisitor.php index a2cb1a466..ded844ff8 100644 --- a/lib/Twig/BaseNodeVisitor.php +++ b/lib/Twig/BaseNodeVisitor.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\NodeVisitorInterface; -use Twig\Node\Node; use Twig\Environment; +use Twig\Node\Node; +use Twig\NodeVisitor\NodeVisitorInterface; /** * Twig_BaseNodeVisitor can be used to make node visitors compatible with Twig 1.x and 2.x. diff --git a/lib/Twig/ContainerRuntimeLoader.php b/lib/Twig/ContainerRuntimeLoader.php index 9f9bf351d..ceadc1fa7 100644 --- a/lib/Twig/ContainerRuntimeLoader.php +++ b/lib/Twig/ContainerRuntimeLoader.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -use Twig\RuntimeLoader\RuntimeLoaderInterface; - use Psr\Container\ContainerInterface; +use Twig\RuntimeLoader\RuntimeLoaderInterface; /** * Lazily loads Twig runtime implementations from a PSR-11 container. diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 8c626f541..a136f38bc 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -9,38 +9,38 @@ * file that was distributed with this source code. */ -use Twig\Extension\CoreExtension; -use Twig\Extension\EscaperExtension; -use Twig\Extension\OptimizerExtension; -use Twig\Extension\StagingExtension; use Twig\Cache\CacheInterface; use Twig\Cache\FilesystemCache; use Twig\Cache\NullCache; -use Twig\Error\LoaderError; -use Twig\Error\SyntaxError; -use Twig\Error\RuntimeError; -use Twig\TemplateWrapper; -use Twig\Template; -use Twig\Loader\SourceContextLoaderInterface; -use Twig\Source; -use Twig\Loader\ChainLoader; -use Twig\Loader\ArrayLoader; -use Twig\Lexer; -use Twig\TokenStream; -use Twig\Parser; -use Twig\Node\ModuleNode; use Twig\Compiler; -use Twig\Loader\LoaderInterface; -use Twig\Extension\InitRuntimeInterface; -use Twig\Extension\ExtensionInterface; -use Twig\TokenParser\TokenParserInterface; -use Twig\NodeVisitor\NodeVisitorInterface; -use Twig\TwigFilter; -use Twig\TwigTest; -use Twig\TwigFunction; -use Twig\Extension\GlobalsInterface; -use Twig\RuntimeLoader\RuntimeLoaderInterface; use Twig\Error\Error; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\Error\SyntaxError; +use Twig\Extension\CoreExtension; +use Twig\Extension\EscaperExtension; +use Twig\Extension\ExtensionInterface; +use Twig\Extension\GlobalsInterface; +use Twig\Extension\InitRuntimeInterface; +use Twig\Extension\OptimizerExtension; +use Twig\Extension\StagingExtension; +use Twig\Lexer; +use Twig\Loader\ArrayLoader; +use Twig\Loader\ChainLoader; +use Twig\Loader\LoaderInterface; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Node\ModuleNode; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Parser; +use Twig\RuntimeLoader\RuntimeLoaderInterface; +use Twig\Source; +use Twig\Template; +use Twig\TemplateWrapper; +use Twig\TokenParser\TokenParserInterface; +use Twig\TokenStream; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; /** * Stores the Twig configuration. @@ -286,8 +286,8 @@ class Twig_Environment * @param bool $original Whether to return the original cache option or the real cache instance * * @return CacheInterface|string|false A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache + * an absolute path to the compiled templates, + * or false to disable cache */ public function getCache($original = true) { @@ -298,8 +298,8 @@ class Twig_Environment * Sets the current cache implementation. * * @param CacheInterface|string|false $cache A Twig_CacheInterface implementation, - * an absolute path to the compiled templates, - * or false to disable cache + * an absolute path to the compiled templates, + * or false to disable cache */ public function setCache($cache) { @@ -687,7 +687,7 @@ class Twig_Environment * Tokenizes a source code. * * @param string|Source $source The template source code - * @param string $name The template name (deprecated) + * @param string $name The template name (deprecated) * * @return TokenStream * @@ -787,7 +787,7 @@ class Twig_Environment * Compiles a template source code. * * @param string|Source $source The template source code - * @param string $name The template name (deprecated) + * @param string $name The template name (deprecated) * * @return string The compiled PHP source code * diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 4aa0a3e3e..2ff44017a 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -56,10 +56,10 @@ class Twig_Error extends \Exception * * By default, automatic guessing is enabled. * - * @param string $message The error message - * @param int $lineno The template line where the error occurred + * @param string $message The error message + * @param int $lineno The template line where the error occurred * @param Source|string|null $source The source context where the error occurred - * @param \Exception $previous The previous exception + * @param \Exception $previous The previous exception */ public function __construct($message, $lineno = -1, $source = null, \Exception $previous = null) { diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index 5bc2f5a9d..8dcce3ec1 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -11,28 +11,28 @@ */ use Twig\Environment; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\ConditionalExpression; -use Twig\Node\Expression\NameExpression; use Twig\Error\SyntaxError; -use Twig\Node\Expression\Binary\ConcatBinary; +use Twig\Lexer; use Twig\Node\Expression\ArrayExpression; -use Twig\Node\Expression\ParentExpression; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Expression\Binary\ConcatBinary; use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\GetAttrExpression; use Twig\Node\Expression\MethodCallExpression; -use Twig\Node\Node; -use Twig\Node\Expression\AssignNameExpression; -use Twig\Node\Expression\Unary\NotUnary; -use Twig\TwigTest; -use Twig\TwigFunction; -use Twig\TwigFilter; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\ParentExpression; use Twig\Node\Expression\Unary\NegUnary; +use Twig\Node\Expression\Unary\NotUnary; use Twig\Node\Expression\Unary\PosUnary; -use Twig\Token; -use Twig\Lexer; -use Twig\Template; +use Twig\Node\Node; use Twig\Parser; +use Twig\Template; +use Twig\Token; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; /** * Parses expressions. diff --git a/lib/Twig/Extension.php b/lib/Twig/Extension.php index 862062e6b..069f8219d 100644 --- a/lib/Twig/Extension.php +++ b/lib/Twig/Extension.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Extension\ExtensionInterface; use Twig\Environment; +use Twig\Extension\ExtensionInterface; abstract class Twig_Extension implements ExtensionInterface { diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index e15515d3c..44964ac6d 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -13,34 +13,34 @@ if (!\defined('ENT_SUBSTITUTE')) { * file that was distributed with this source code. */ +use Twig\Environment; +use Twig\Error\LoaderError; +use Twig\Error\RuntimeError; +use Twig\ExpressionParser; use Twig\Extension\AbstractExtension; -use Twig\TokenParser\ForTokenParser; -use Twig\TokenParser\IfTokenParser; -use Twig\TokenParser\ExtendsTokenParser; -use Twig\TokenParser\IncludeTokenParser; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\Markup; +use Twig\Node\Expression\ConstantExpression; use Twig\TokenParser\BlockTokenParser; -use Twig\TokenParser\UseTokenParser; -use Twig\TokenParser\FilterTokenParser; -use Twig\TokenParser\MacroTokenParser; -use Twig\TokenParser\ImportTokenParser; -use Twig\TokenParser\FromTokenParser; -use Twig\TokenParser\SetTokenParser; -use Twig\TokenParser\SpacelessTokenParser; -use Twig\TokenParser\FlushTokenParser; +use Twig\TokenParser\DeprecatedTokenParser; use Twig\TokenParser\DoTokenParser; use Twig\TokenParser\EmbedTokenParser; +use Twig\TokenParser\ExtendsTokenParser; +use Twig\TokenParser\FilterTokenParser; +use Twig\TokenParser\FlushTokenParser; +use Twig\TokenParser\ForTokenParser; +use Twig\TokenParser\FromTokenParser; +use Twig\TokenParser\IfTokenParser; +use Twig\TokenParser\ImportTokenParser; +use Twig\TokenParser\IncludeTokenParser; +use Twig\TokenParser\MacroTokenParser; +use Twig\TokenParser\SetTokenParser; +use Twig\TokenParser\SpacelessTokenParser; +use Twig\TokenParser\UseTokenParser; use Twig\TokenParser\WithTokenParser; -use Twig\TokenParser\DeprecatedTokenParser; use Twig\TwigFilter; use Twig\TwigFunction; use Twig\TwigTest; -use Twig\Error\RuntimeError; -use Twig\Markup; -use Twig\Node\Expression\ConstantExpression; -use Twig\Loader\SourceContextLoaderInterface; -use Twig\ExpressionParser; -use Twig\Environment; -use Twig\Error\LoaderError; /** * @final diff --git a/lib/Twig/Extension/Debug.php b/lib/Twig/Extension/Debug.php index 3efeaaed2..489a60a93 100644 --- a/lib/Twig/Extension/Debug.php +++ b/lib/Twig/Extension/Debug.php @@ -10,8 +10,8 @@ */ use Twig\Extension\AbstractExtension; -use Twig\TwigFunction; use Twig\Template; +use Twig\TwigFunction; /** * @final diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index 0fcc7e7f5..c287b25ed 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -10,8 +10,8 @@ */ use Twig\Extension\AbstractExtension; -use Twig\TokenParser\AutoEscapeTokenParser; use Twig\NodeVisitor\EscaperNodeVisitor; +use Twig\TokenParser\AutoEscapeTokenParser; use Twig\TwigFilter; /** diff --git a/lib/Twig/Extension/Sandbox.php b/lib/Twig/Extension/Sandbox.php index a4b5572b5..07121b568 100644 --- a/lib/Twig/Extension/Sandbox.php +++ b/lib/Twig/Extension/Sandbox.php @@ -10,9 +10,9 @@ */ use Twig\Extension\AbstractExtension; -use Twig\TokenParser\SandboxTokenParser; use Twig\NodeVisitor\SandboxNodeVisitor; use Twig\Sandbox\SecurityPolicyInterface; +use Twig\TokenParser\SandboxTokenParser; /** * @final diff --git a/lib/Twig/Extension/StringLoader.php b/lib/Twig/Extension/StringLoader.php index b75e51a9c..93b76c7ca 100644 --- a/lib/Twig/Extension/StringLoader.php +++ b/lib/Twig/Extension/StringLoader.php @@ -10,8 +10,8 @@ */ use Twig\Extension\AbstractExtension; -use Twig\TwigFunction; use Twig\Template; +use Twig\TwigFunction; /** * @final diff --git a/lib/Twig/ExtensionInterface.php b/lib/Twig/ExtensionInterface.php index 2731e6ad5..d5f2fa69b 100644 --- a/lib/Twig/ExtensionInterface.php +++ b/lib/Twig/ExtensionInterface.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\TokenParserInterface; -use Twig\NodeVisitor\NodeVisitorInterface; -use Twig\TwigFilter; -use Twig\TwigTest; -use Twig\TwigFunction; use Twig\Environment; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\TokenParser\TokenParserInterface; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; /** * Interface implemented by extension classes. diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 541b4d0ab..d7e82341f 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -10,11 +10,11 @@ * file that was distributed with this source code. */ -use Twig\Source; -use Twig\Error\SyntaxError; -use Twig\TokenStream; -use Twig\Token; use Twig\Environment; +use Twig\Error\SyntaxError; +use Twig\Source; +use Twig\Token; +use Twig\TokenStream; /** * Lexes a template string. diff --git a/lib/Twig/LexerInterface.php b/lib/Twig/LexerInterface.php index 3e04d8cb5..cc04f6841 100644 --- a/lib/Twig/LexerInterface.php +++ b/lib/Twig/LexerInterface.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\TokenStream; use Twig\Error\SyntaxError; use Twig\Source; +use Twig\TokenStream; /** * Interface implemented by lexer classes. @@ -26,7 +26,7 @@ interface Twig_LexerInterface * Tokenizes a source code. * * @param string|Source $code The source code - * @param string $name A unique identifier for the source code + * @param string $name A unique identifier for the source code * * @return TokenStream * diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 215dbf9c9..8e89dec91 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Loader\LoaderInterface; use Twig\Error\LoaderError; +use Twig\Loader\LoaderInterface; use Twig\Source; /** diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index 48592c6c5..accd8eeb3 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Loader\LoaderInterface; -use Twig\Loader\ExistsLoaderInterface; use Twig\Error\LoaderError; +use Twig\Loader\ExistsLoaderInterface; +use Twig\Loader\LoaderInterface; use Twig\Loader\SourceContextLoaderInterface; use Twig\Source; diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 8d5a2bf92..f93d85c2a 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Loader\LoaderInterface; use Twig\Error\LoaderError; +use Twig\Loader\LoaderInterface; use Twig\Source; /** diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index d53bbf72a..71dec64f1 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a node in the AST. diff --git a/lib/Twig/Node/AutoEscape.php b/lib/Twig/Node/AutoEscape.php index 7f5451a4c..ead0ef270 100644 --- a/lib/Twig/Node/AutoEscape.php +++ b/lib/Twig/Node/AutoEscape.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents an autoescape node. diff --git a/lib/Twig/Node/Block.php b/lib/Twig/Node/Block.php index e2cefe6d5..adcbc8ef2 100644 --- a/lib/Twig/Node/Block.php +++ b/lib/Twig/Node/Block.php @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a block node. diff --git a/lib/Twig/Node/BlockReference.php b/lib/Twig/Node/BlockReference.php index 232ac960d..f97719843 100644 --- a/lib/Twig/Node/BlockReference.php +++ b/lib/Twig/Node/BlockReference.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Node; use Twig\Node\NodeOutputInterface; -use Twig\Compiler; /** * Represents a block call node. diff --git a/lib/Twig/Node/CheckSecurity.php b/lib/Twig/Node/CheckSecurity.php index 54d56422f..173fe2d74 100644 --- a/lib/Twig/Node/CheckSecurity.php +++ b/lib/Twig/Node/CheckSecurity.php @@ -9,12 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Sandbox\SecurityNotAllowedTagError; -use Twig\Sandbox\SecurityNotAllowedFilterError; -use Twig\Sandbox\SecurityNotAllowedFunctionError; use Twig\Compiler; -use Twig\Sandbox\SecurityError; +use Twig\Node\Node; /** * @author Fabien Potencier diff --git a/lib/Twig/Node/Deprecated.php b/lib/Twig/Node/Deprecated.php index 94bd7906b..cc6db57d6 100644 --- a/lib/Twig/Node/Deprecated.php +++ b/lib/Twig/Node/Deprecated.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; /** * Represents a deprecated node. diff --git a/lib/Twig/Node/Do.php b/lib/Twig/Node/Do.php index f5973dcb8..7db57078e 100644 --- a/lib/Twig/Node/Do.php +++ b/lib/Twig/Node/Do.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Node; /** * Represents a do node. diff --git a/lib/Twig/Node/Embed.php b/lib/Twig/Node/Embed.php index b4a77d535..70e418c74 100644 --- a/lib/Twig/Node/Embed.php +++ b/lib/Twig/Node/Embed.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Node\IncludeNode; -use Twig\Node\Expression\ConstantExpression; use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\IncludeNode; /** * Represents an embed node. diff --git a/lib/Twig/Node/Expression/Array.php b/lib/Twig/Node/Expression/Array.php index 092997869..ef5086d05 100644 --- a/lib/Twig/Node/Expression/Array.php +++ b/lib/Twig/Node/Expression/Array.php @@ -9,9 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; use Twig\Node\Expression\ConstantExpression; -use Twig\Compiler; + class Twig_Node_Expression_Array extends AbstractExpression { protected $index; diff --git a/lib/Twig/Node/Expression/AssignName.php b/lib/Twig/Node/Expression/AssignName.php index 48f8aac65..8680ec506 100644 --- a/lib/Twig/Node/Expression/AssignName.php +++ b/lib/Twig/Node/Expression/AssignName.php @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\NameExpression; use Twig\Compiler; +use Twig\Node\Expression\NameExpression; class Twig_Node_Expression_AssignName extends NameExpression { diff --git a/lib/Twig/Node/Expression/Binary.php b/lib/Twig/Node/Expression/Binary.php index c7fcbd50a..b0c73f710 100644 --- a/lib/Twig/Node/Expression/Binary.php +++ b/lib/Twig/Node/Expression/Binary.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + abstract class Twig_Node_Expression_Binary extends AbstractExpression { public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) diff --git a/lib/Twig/Node/Expression/Binary/Add.php b/lib/Twig/Node/Expression/Binary/Add.php index fc46803f0..6a0f50643 100644 --- a/lib/Twig/Node/Expression/Binary/Add.php +++ b/lib/Twig/Node/Expression/Binary/Add.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Add extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/And.php b/lib/Twig/Node/Expression/Binary/And.php index b5d64fa94..455f9117a 100644 --- a/lib/Twig/Node/Expression/Binary/And.php +++ b/lib/Twig/Node/Expression/Binary/And.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_And extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php index ca3795a3e..e372f1a8d 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseAnd.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseAnd.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_BitwiseAnd extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/BitwiseOr.php b/lib/Twig/Node/Expression/Binary/BitwiseOr.php index 36f40d2b0..91dad4da8 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseOr.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseOr.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_BitwiseOr extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/BitwiseXor.php b/lib/Twig/Node/Expression/Binary/BitwiseXor.php index b3b5e72e1..d58ccb1e2 100644 --- a/lib/Twig/Node/Expression/Binary/BitwiseXor.php +++ b/lib/Twig/Node/Expression/Binary/BitwiseXor.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_BitwiseXor extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Concat.php b/lib/Twig/Node/Expression/Binary/Concat.php index fc499c5c4..4e74b0a06 100644 --- a/lib/Twig/Node/Expression/Binary/Concat.php +++ b/lib/Twig/Node/Expression/Binary/Concat.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Concat extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Div.php b/lib/Twig/Node/Expression/Binary/Div.php index b93ebdfc7..ab8a5a8d2 100644 --- a/lib/Twig/Node/Expression/Binary/Div.php +++ b/lib/Twig/Node/Expression/Binary/Div.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Div extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/EndsWith.php b/lib/Twig/Node/Expression/Binary/EndsWith.php index 501966111..7ce7988c8 100644 --- a/lib/Twig/Node/Expression/Binary/EndsWith.php +++ b/lib/Twig/Node/Expression/Binary/EndsWith.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_EndsWith extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Equal.php b/lib/Twig/Node/Expression/Binary/Equal.php index 54e3af9c1..c6a0204f7 100644 --- a/lib/Twig/Node/Expression/Binary/Equal.php +++ b/lib/Twig/Node/Expression/Binary/Equal.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Equal extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/FloorDiv.php b/lib/Twig/Node/Expression/Binary/FloorDiv.php index 193c38319..86086cb8e 100644 --- a/lib/Twig/Node/Expression/Binary/FloorDiv.php +++ b/lib/Twig/Node/Expression/Binary/FloorDiv.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_FloorDiv extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Greater.php b/lib/Twig/Node/Expression/Binary/Greater.php index bdc056ea0..b4042e1fe 100644 --- a/lib/Twig/Node/Expression/Binary/Greater.php +++ b/lib/Twig/Node/Expression/Binary/Greater.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Greater extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/GreaterEqual.php b/lib/Twig/Node/Expression/Binary/GreaterEqual.php index 2ee5fc14d..535d4dc7d 100644 --- a/lib/Twig/Node/Expression/Binary/GreaterEqual.php +++ b/lib/Twig/Node/Expression/Binary/GreaterEqual.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_GreaterEqual extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/In.php b/lib/Twig/Node/Expression/Binary/In.php index a9b91424a..e762a7b82 100644 --- a/lib/Twig/Node/Expression/Binary/In.php +++ b/lib/Twig/Node/Expression/Binary/In.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_In extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Less.php b/lib/Twig/Node/Expression/Binary/Less.php index 1726e23da..3d2dd3198 100644 --- a/lib/Twig/Node/Expression/Binary/Less.php +++ b/lib/Twig/Node/Expression/Binary/Less.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Less extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/LessEqual.php b/lib/Twig/Node/Expression/Binary/LessEqual.php index e59e8d756..892f42412 100644 --- a/lib/Twig/Node/Expression/Binary/LessEqual.php +++ b/lib/Twig/Node/Expression/Binary/LessEqual.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_LessEqual extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Matches.php b/lib/Twig/Node/Expression/Binary/Matches.php index eadae82d9..0ea27746a 100644 --- a/lib/Twig/Node/Expression/Binary/Matches.php +++ b/lib/Twig/Node/Expression/Binary/Matches.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Matches extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Mod.php b/lib/Twig/Node/Expression/Binary/Mod.php index 2519e492c..5cf23d6e2 100644 --- a/lib/Twig/Node/Expression/Binary/Mod.php +++ b/lib/Twig/Node/Expression/Binary/Mod.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Mod extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Mul.php b/lib/Twig/Node/Expression/Binary/Mul.php index 985e6387b..6c1f43d55 100644 --- a/lib/Twig/Node/Expression/Binary/Mul.php +++ b/lib/Twig/Node/Expression/Binary/Mul.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Mul extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/NotEqual.php b/lib/Twig/Node/Expression/Binary/NotEqual.php index 0a59fc556..851c754ae 100644 --- a/lib/Twig/Node/Expression/Binary/NotEqual.php +++ b/lib/Twig/Node/Expression/Binary/NotEqual.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_NotEqual extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/NotIn.php b/lib/Twig/Node/Expression/Binary/NotIn.php index 764e412d8..9136594f2 100644 --- a/lib/Twig/Node/Expression/Binary/NotIn.php +++ b/lib/Twig/Node/Expression/Binary/NotIn.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_NotIn extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Or.php b/lib/Twig/Node/Expression/Binary/Or.php index 9f9d925ed..461bd3357 100644 --- a/lib/Twig/Node/Expression/Binary/Or.php +++ b/lib/Twig/Node/Expression/Binary/Or.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Or extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Power.php b/lib/Twig/Node/Expression/Binary/Power.php index a2f0da65a..d96c526b0 100644 --- a/lib/Twig/Node/Expression/Binary/Power.php +++ b/lib/Twig/Node/Expression/Binary/Power.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Power extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Range.php b/lib/Twig/Node/Expression/Binary/Range.php index e1f7bb9a6..f70fbdef8 100644 --- a/lib/Twig/Node/Expression/Binary/Range.php +++ b/lib/Twig/Node/Expression/Binary/Range.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Range extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/StartsWith.php b/lib/Twig/Node/Expression/Binary/StartsWith.php index f0f3c55c2..7cc1cdc5a 100644 --- a/lib/Twig/Node/Expression/Binary/StartsWith.php +++ b/lib/Twig/Node/Expression/Binary/StartsWith.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_StartsWith extends AbstractBinary { public function compile(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Binary/Sub.php b/lib/Twig/Node/Expression/Binary/Sub.php index adb1ca12a..ea2016630 100644 --- a/lib/Twig/Node/Expression/Binary/Sub.php +++ b/lib/Twig/Node/Expression/Binary/Sub.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Binary\AbstractBinary; use Twig\Compiler; +use Twig\Node\Expression\Binary\AbstractBinary; + class Twig_Node_Expression_Binary_Sub extends AbstractBinary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/BlockReference.php b/lib/Twig/Node/Expression/BlockReference.php index 463d93462..85f490c77 100644 --- a/lib/Twig/Node/Expression/BlockReference.php +++ b/lib/Twig/Node/Expression/BlockReference.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; use Twig\Node\Node; -use Twig\Compiler; /** * Represents a block call node. diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index e670fe242..f5b8142b6 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -9,13 +9,14 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; -use Twig\Extension\ExtensionInterface; -use Twig\Error\SyntaxError; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\ArrayExpression; -use Twig\Node\Node; use Twig\Compiler; +use Twig\Error\SyntaxError; +use Twig\Extension\ExtensionInterface; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; + abstract class Twig_Node_Expression_Call extends AbstractExpression { private $reflector; diff --git a/lib/Twig/Node/Expression/Conditional.php b/lib/Twig/Node/Expression/Conditional.php index 1a535d9f4..35bd44fc6 100644 --- a/lib/Twig/Node/Expression/Conditional.php +++ b/lib/Twig/Node/Expression/Conditional.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + class Twig_Node_Expression_Conditional extends AbstractExpression { public function __construct(AbstractExpression $expr1, AbstractExpression $expr2, AbstractExpression $expr3, $lineno) diff --git a/lib/Twig/Node/Expression/Constant.php b/lib/Twig/Node/Expression/Constant.php index 90a6b51b2..aab558341 100644 --- a/lib/Twig/Node/Expression/Constant.php +++ b/lib/Twig/Node/Expression/Constant.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + class Twig_Node_Expression_Constant extends AbstractExpression { public function __construct($value, $lineno) diff --git a/lib/Twig/Node/Expression/ExtensionReference.php b/lib/Twig/Node/Expression/ExtensionReference.php index 1296aa1ca..9b8927a31 100644 --- a/lib/Twig/Node/Expression/ExtensionReference.php +++ b/lib/Twig/Node/Expression/ExtensionReference.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; @trigger_error('The Twig_Node_Expression_ExtensionReference class is deprecated since version 1.23 and will be removed in 2.0.', E_USER_DEPRECATED); diff --git a/lib/Twig/Node/Expression/Filter.php b/lib/Twig/Node/Expression/Filter.php index 3023d3d7d..0932e6bc7 100644 --- a/lib/Twig/Node/Expression/Filter.php +++ b/lib/Twig/Node/Expression/Filter.php @@ -10,10 +10,11 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\CallExpression; -use Twig\TwigFilter; use Twig\Compiler; +use Twig\Node\Expression\CallExpression; use Twig\Node\Expression\ConstantExpression; +use Twig\TwigFilter; + class Twig_Node_Expression_Filter extends CallExpression { public function __construct(Twig_NodeInterface $node, ConstantExpression $filterName, Twig_NodeInterface $arguments, $lineno, $tag = null) diff --git a/lib/Twig/Node/Expression/Filter/Default.php b/lib/Twig/Node/Expression/Filter/Default.php index 0ee12f660..0e88e1757 100644 --- a/lib/Twig/Node/Expression/Filter/Default.php +++ b/lib/Twig/Node/Expression/Filter/Default.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\FilterExpression; +use Twig\Compiler; +use Twig\Node\Expression\ConditionalExpression; use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\NameExpression; use Twig\Node\Expression\Test\DefinedTest; use Twig\Node\Node; -use Twig\Node\Expression\ConditionalExpression; -use Twig\Compiler; /** * Returns the value or the default value when it is undefined or empty. diff --git a/lib/Twig/Node/Expression/Function.php b/lib/Twig/Node/Expression/Function.php index a8fa8f183..8bb5e6791 100644 --- a/lib/Twig/Node/Expression/Function.php +++ b/lib/Twig/Node/Expression/Function.php @@ -9,9 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Expression\CallExpression; use Twig\TwigFunction; -use Twig\Compiler; + class Twig_Node_Expression_Function extends CallExpression { public function __construct($name, Twig_NodeInterface $arguments, $lineno) diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index 2fd4ec748..8d0dc521f 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -10,9 +10,10 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; use Twig\Template; -use Twig\Compiler; + class Twig_Node_Expression_GetAttr extends AbstractExpression { public function __construct(AbstractExpression $node, AbstractExpression $attribute, AbstractExpression $arguments = null, $type, $lineno) diff --git a/lib/Twig/Node/Expression/MethodCall.php b/lib/Twig/Node/Expression/MethodCall.php index 2b0222618..14cb51132 100644 --- a/lib/Twig/Node/Expression/MethodCall.php +++ b/lib/Twig/Node/Expression/MethodCall.php @@ -9,10 +9,11 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; -use Twig\Node\Expression\NameExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\NameExpression; + class Twig_Node_Expression_MethodCall extends AbstractExpression { public function __construct(AbstractExpression $node, $method, ArrayExpression $arguments, $lineno) diff --git a/lib/Twig/Node/Expression/Name.php b/lib/Twig/Node/Expression/Name.php index 0138b0af3..97737307c 100644 --- a/lib/Twig/Node/Expression/Name.php +++ b/lib/Twig/Node/Expression/Name.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + class Twig_Node_Expression_Name extends AbstractExpression { protected $specialVars = [ diff --git a/lib/Twig/Node/Expression/NullCoalesce.php b/lib/Twig/Node/Expression/NullCoalesce.php index 583976683..6e6f5648e 100644 --- a/lib/Twig/Node/Expression/NullCoalesce.php +++ b/lib/Twig/Node/Expression/NullCoalesce.php @@ -9,14 +9,15 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\ConditionalExpression; -use Twig\Node\Expression\Binary\AndBinary; -use Twig\Node\Expression\Test\DefinedTest; -use Twig\Node\Node; -use Twig\Node\Expression\Unary\NotUnary; -use Twig\Node\Expression\Test\NullTest; -use Twig\Node\Expression\NameExpression; use Twig\Compiler; +use Twig\Node\Expression\Binary\AndBinary; +use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\Test\DefinedTest; +use Twig\Node\Expression\Test\NullTest; +use Twig\Node\Expression\Unary\NotUnary; +use Twig\Node\Node; + class Twig_Node_Expression_NullCoalesce extends ConditionalExpression { public function __construct(Twig_NodeInterface $left, Twig_NodeInterface $right, $lineno) diff --git a/lib/Twig/Node/Expression/Parent.php b/lib/Twig/Node/Expression/Parent.php index c5f77d640..fcbcc04e9 100644 --- a/lib/Twig/Node/Expression/Parent.php +++ b/lib/Twig/Node/Expression/Parent.php @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; /** * Represents a parent node. diff --git a/lib/Twig/Node/Expression/TempName.php b/lib/Twig/Node/Expression/TempName.php index 9565d34e1..b4bc3d8de 100644 --- a/lib/Twig/Node/Expression/TempName.php +++ b/lib/Twig/Node/Expression/TempName.php @@ -9,8 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + class Twig_Node_Expression_TempName extends AbstractExpression { public function __construct($name, $lineno) diff --git a/lib/Twig/Node/Expression/Test.php b/lib/Twig/Node/Expression/Test.php index b60b45c48..7218cad82 100644 --- a/lib/Twig/Node/Expression/Test.php +++ b/lib/Twig/Node/Expression/Test.php @@ -9,9 +9,10 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Expression\CallExpression; use Twig\TwigTest; -use Twig\Compiler; + class Twig_Node_Expression_Test extends CallExpression { public function __construct(Twig_NodeInterface $node, $name, Twig_NodeInterface $arguments = null, $lineno) diff --git a/lib/Twig/Node/Expression/Test/Constant.php b/lib/Twig/Node/Expression/Test/Constant.php index aee1da123..0be95382c 100644 --- a/lib/Twig/Node/Expression/Test/Constant.php +++ b/lib/Twig/Node/Expression/Test/Constant.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; use Twig\Compiler; +use Twig\Node\Expression\TestExpression; /** * Checks if a variable is the exact same value as a constant. diff --git a/lib/Twig/Node/Expression/Test/Defined.php b/lib/Twig/Node/Expression/Test/Defined.php index 6e505243f..d51fe8c83 100644 --- a/lib/Twig/Node/Expression/Test/Defined.php +++ b/lib/Twig/Node/Expression/Test/Defined.php @@ -9,15 +9,15 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; -use Twig\Node\Expression\NameExpression; -use Twig\Node\Expression\GetAttrExpression; -use Twig\Node\Expression\BlockReferenceExpression; -use Twig\Node\Expression\FunctionExpression; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\ArrayExpression; -use Twig\Error\SyntaxError; use Twig\Compiler; +use Twig\Error\SyntaxError; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FunctionExpression; +use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\TestExpression; /** * Checks if a variable is defined in the current context. diff --git a/lib/Twig/Node/Expression/Test/Divisibleby.php b/lib/Twig/Node/Expression/Test/Divisibleby.php index 2c901f0df..4b1d7bdc2 100644 --- a/lib/Twig/Node/Expression/Test/Divisibleby.php +++ b/lib/Twig/Node/Expression/Test/Divisibleby.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; use Twig\Compiler; +use Twig\Node\Expression\TestExpression; /** * Checks if a variable is divisible by a number. diff --git a/lib/Twig/Node/Expression/Test/Even.php b/lib/Twig/Node/Expression/Test/Even.php index e40578396..614ffd8d4 100644 --- a/lib/Twig/Node/Expression/Test/Even.php +++ b/lib/Twig/Node/Expression/Test/Even.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; use Twig\Compiler; +use Twig\Node\Expression\TestExpression; /** * Checks if a number is even. diff --git a/lib/Twig/Node/Expression/Test/Null.php b/lib/Twig/Node/Expression/Test/Null.php index 0be47dc6d..8f94b0d6b 100644 --- a/lib/Twig/Node/Expression/Test/Null.php +++ b/lib/Twig/Node/Expression/Test/Null.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; use Twig\Compiler; +use Twig\Node\Expression\TestExpression; /** * Checks that a variable is null. diff --git a/lib/Twig/Node/Expression/Test/Odd.php b/lib/Twig/Node/Expression/Test/Odd.php index 55e6e4d05..0f80dff33 100644 --- a/lib/Twig/Node/Expression/Test/Odd.php +++ b/lib/Twig/Node/Expression/Test/Odd.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; use Twig\Compiler; +use Twig\Node\Expression\TestExpression; /** * Checks if a number is odd. diff --git a/lib/Twig/Node/Expression/Test/Sameas.php b/lib/Twig/Node/Expression/Test/Sameas.php index 5cd339ccd..75aeb8cb9 100644 --- a/lib/Twig/Node/Expression/Test/Sameas.php +++ b/lib/Twig/Node/Expression/Test/Sameas.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\TestExpression; use Twig\Compiler; +use Twig\Node\Expression\TestExpression; /** * Checks if a variable is the same as another one (=== in PHP). diff --git a/lib/Twig/Node/Expression/Unary.php b/lib/Twig/Node/Expression/Unary.php index 8fff798f8..e45672e1f 100644 --- a/lib/Twig/Node/Expression/Unary.php +++ b/lib/Twig/Node/Expression/Unary.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; + abstract class Twig_Node_Expression_Unary extends AbstractExpression { public function __construct(Twig_NodeInterface $node, $lineno) diff --git a/lib/Twig/Node/Expression/Unary/Neg.php b/lib/Twig/Node/Expression/Unary/Neg.php index fa7b4f4b2..fc9ce434f 100644 --- a/lib/Twig/Node/Expression/Unary/Neg.php +++ b/lib/Twig/Node/Expression/Unary/Neg.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Unary\AbstractUnary; use Twig\Compiler; +use Twig\Node\Expression\Unary\AbstractUnary; + class Twig_Node_Expression_Unary_Neg extends AbstractUnary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Unary/Not.php b/lib/Twig/Node/Expression/Unary/Not.php index 8004c842a..951978dfa 100644 --- a/lib/Twig/Node/Expression/Unary/Not.php +++ b/lib/Twig/Node/Expression/Unary/Not.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Unary\AbstractUnary; use Twig\Compiler; +use Twig\Node\Expression\Unary\AbstractUnary; + class Twig_Node_Expression_Unary_Not extends AbstractUnary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Expression/Unary/Pos.php b/lib/Twig/Node/Expression/Unary/Pos.php index 6624925dc..bd07ba8cb 100644 --- a/lib/Twig/Node/Expression/Unary/Pos.php +++ b/lib/Twig/Node/Expression/Unary/Pos.php @@ -10,8 +10,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Expression\Unary\AbstractUnary; use Twig\Compiler; +use Twig\Node\Expression\Unary\AbstractUnary; + class Twig_Node_Expression_Unary_Pos extends AbstractUnary { public function operator(Compiler $compiler) diff --git a/lib/Twig/Node/Flush.php b/lib/Twig/Node/Flush.php index 2d680f3b0..442fc968c 100644 --- a/lib/Twig/Node/Flush.php +++ b/lib/Twig/Node/Flush.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a flush node. diff --git a/lib/Twig/Node/For.php b/lib/Twig/Node/For.php index 111eeddf1..f13224c68 100644 --- a/lib/Twig/Node/For.php +++ b/lib/Twig/Node/For.php @@ -10,12 +10,12 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Node\ForLoopNode; -use Twig\Node\IfNode; -use Twig\Node\Expression\AssignNameExpression; use Twig\Compiler; use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\ForLoopNode; +use Twig\Node\IfNode; +use Twig\Node\Node; /** * Represents a for node. diff --git a/lib/Twig/Node/ForLoop.php b/lib/Twig/Node/ForLoop.php index b67cb54c6..e2abe6535 100644 --- a/lib/Twig/Node/ForLoop.php +++ b/lib/Twig/Node/ForLoop.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Internal node used by the for node. diff --git a/lib/Twig/Node/If.php b/lib/Twig/Node/If.php index 6bb8fc6df..1a682d38c 100644 --- a/lib/Twig/Node/If.php +++ b/lib/Twig/Node/If.php @@ -10,8 +10,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents an if node. diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php index 4fae3314b..6e35ba00e 100644 --- a/lib/Twig/Node/Import.php +++ b/lib/Twig/Node/Import.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Node\Expression\NameExpression; -use Twig\Node\Expression\AbstractExpression; use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; /** * Represents an import node. diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php index 0ed783750..60a1082f8 100644 --- a/lib/Twig/Node/Include.php +++ b/lib/Twig/Node/Include.php @@ -10,11 +10,10 @@ * file that was distributed with this source code. */ +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; use Twig\Node\Node; use Twig\Node\NodeOutputInterface; -use Twig\Node\Expression\AbstractExpression; -use Twig\Compiler; -use Twig\Error\LoaderError; /** * Represents an include node. diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 248cd75d5..47fa4acda 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Error\SyntaxError; -use Twig\Markup; use Twig\Compiler; +use Twig\Error\SyntaxError; +use Twig\Node\Node; /** * Represents a macro node. diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index d131ae67a..f792893ef 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -10,16 +10,14 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Source; -use Twig\Node\Expression\ConstantExpression; -use Twig\Error\RuntimeError; -use Twig\Node\BodyNode; -use Twig\Node\TextNode; -use Twig\Node\BlockReferenceNode; use Twig\Compiler; -use Twig\Environment; +use Twig\Node\BlockReferenceNode; +use Twig\Node\BodyNode; use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Source; /** * Represents a module node. diff --git a/lib/Twig/Node/Print.php b/lib/Twig/Node/Print.php index 7c326603f..854ffad81 100644 --- a/lib/Twig/Node/Print.php +++ b/lib/Twig/Node/Print.php @@ -10,10 +10,10 @@ * file that was distributed with this source code. */ +use Twig\Compiler; +use Twig\Node\Expression\AbstractExpression; use Twig\Node\Node; use Twig\Node\NodeOutputInterface; -use Twig\Node\Expression\AbstractExpression; -use Twig\Compiler; /** * Represents a node that outputs an expression. diff --git a/lib/Twig/Node/Sandbox.php b/lib/Twig/Node/Sandbox.php index 99c03bec4..9181f89c8 100644 --- a/lib/Twig/Node/Sandbox.php +++ b/lib/Twig/Node/Sandbox.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a sandbox node. diff --git a/lib/Twig/Node/SandboxedPrint.php b/lib/Twig/Node/SandboxedPrint.php index 0fdfd3eb1..b55681259 100644 --- a/lib/Twig/Node/SandboxedPrint.php +++ b/lib/Twig/Node/SandboxedPrint.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Node\PrintNode; -use Twig\Node\Node; -use Twig\Node\Expression\FilterExpression; use Twig\Compiler; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Node; +use Twig\Node\PrintNode; /** * Twig_Node_SandboxedPrint adds a check for the __toString() method diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index 5f7fb8d96..b9f348355 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -9,12 +9,11 @@ * file that was distributed with this source code. */ +use Twig\Compiler; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Node; use Twig\Node\NodeCaptureInterface; use Twig\Node\TextNode; -use Twig\Node\Expression\ConstantExpression; -use Twig\Markup; -use Twig\Compiler; /** * Represents a set node. diff --git a/lib/Twig/Node/SetTemp.php b/lib/Twig/Node/SetTemp.php index 8ce128b72..cf4a57593 100644 --- a/lib/Twig/Node/SetTemp.php +++ b/lib/Twig/Node/SetTemp.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * @internal diff --git a/lib/Twig/Node/Spaceless.php b/lib/Twig/Node/Spaceless.php index e7e3711ba..cb23e1207 100644 --- a/lib/Twig/Node/Spaceless.php +++ b/lib/Twig/Node/Spaceless.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a spaceless node. diff --git a/lib/Twig/Node/Text.php b/lib/Twig/Node/Text.php index 81ca31d02..b2c8a8b7c 100644 --- a/lib/Twig/Node/Text.php +++ b/lib/Twig/Node/Text.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Node; use Twig\Node\NodeOutputInterface; -use Twig\Compiler; /** * Represents a text node. diff --git a/lib/Twig/Node/With.php b/lib/Twig/Node/With.php index fde8eb66e..5c94b217e 100644 --- a/lib/Twig/Node/With.php +++ b/lib/Twig/Node/With.php @@ -9,9 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; -use Twig\Error\RuntimeError; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a nested "with" scope. diff --git a/lib/Twig/NodeTraverser.php b/lib/Twig/NodeTraverser.php index f7edca44a..b65a0413b 100644 --- a/lib/Twig/NodeTraverser.php +++ b/lib/Twig/NodeTraverser.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\NodeVisitorInterface; use Twig\Environment; +use Twig\NodeVisitor\NodeVisitorInterface; /** * Twig_NodeTraverser is a node traverser. diff --git a/lib/Twig/NodeVisitor/Escaper.php b/lib/Twig/NodeVisitor/Escaper.php index 7a05d039e..61234d8ea 100644 --- a/lib/Twig/NodeVisitor/Escaper.php +++ b/lib/Twig/NodeVisitor/Escaper.php @@ -9,19 +9,19 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\AbstractNodeVisitor; -use Twig\NodeVisitor\SafeAnalysisNodeVisitor; -use Twig\Node\ModuleNode; +use Twig\Environment; use Twig\Node\AutoEscapeNode; use Twig\Node\BlockNode; -use Twig\Node\ImportNode; -use Twig\Node\Expression\FilterExpression; -use Twig\Node\PrintNode; use Twig\Node\BlockReferenceNode; -use Twig\NodeTraverser; use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\ImportNode; +use Twig\Node\ModuleNode; use Twig\Node\Node; -use Twig\Environment; +use Twig\Node\PrintNode; +use Twig\NodeTraverser; +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\NodeVisitor\SafeAnalysisNodeVisitor; /** * Twig_NodeVisitor_Escaper implements output escaping. diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index 77f2a2cf7..2a763fe1c 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -9,24 +9,24 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\AbstractNodeVisitor; -use Twig\Node\Expression\AbstractExpression; -use Twig\Node\BodyNode; -use Twig\Node\SetTempNode; -use Twig\Node\Node; -use Twig\Node\Expression\TempNameExpression; -use Twig\Node\PrintNode; -use Twig\Node\Expression\BlockReferenceExpression; -use Twig\Node\Expression\ParentExpression; -use Twig\Node\Expression\FilterExpression; -use Twig\Node\ForNode; -use Twig\Node\Expression\NameExpression; +use Twig\Environment; use Twig\Node\BlockReferenceNode; -use Twig\Node\IncludeNode; +use Twig\Node\BodyNode; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\Expression\BlockReferenceExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\FunctionExpression; use Twig\Node\Expression\GetAttrExpression; -use Twig\Node\Expression\ConstantExpression; -use Twig\Environment; +use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\ParentExpression; +use Twig\Node\Expression\TempNameExpression; +use Twig\Node\ForNode; +use Twig\Node\IncludeNode; +use Twig\Node\Node; +use Twig\Node\PrintNode; +use Twig\Node\SetTempNode; +use Twig\NodeVisitor\AbstractNodeVisitor; /** * Twig_NodeVisitor_Optimizer tries to optimizes the AST. diff --git a/lib/Twig/NodeVisitor/SafeAnalysis.php b/lib/Twig/NodeVisitor/SafeAnalysis.php index e0ce7c75b..21c4f9d96 100644 --- a/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -9,18 +9,18 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\AbstractNodeVisitor; -use Twig\Node\Expression\ConstantExpression; +use Twig\Environment; use Twig\Node\Expression\BlockReferenceExpression; -use Twig\Node\Expression\ParentExpression; use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\FunctionExpression; -use Twig\Node\Expression\MethodCallExpression; use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\MethodCallExpression; use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\ParentExpression; use Twig\Node\Node; -use Twig\Environment; +use Twig\NodeVisitor\AbstractNodeVisitor; /** * @final diff --git a/lib/Twig/NodeVisitor/Sandbox.php b/lib/Twig/NodeVisitor/Sandbox.php index ece1cbad9..c5b44e7ad 100644 --- a/lib/Twig/NodeVisitor/Sandbox.php +++ b/lib/Twig/NodeVisitor/Sandbox.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\AbstractNodeVisitor; -use Twig\Node\ModuleNode; +use Twig\Environment; +use Twig\Node\CheckSecurityNode; +use Twig\Node\Expression\Binary\RangeBinary; use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\FunctionExpression; -use Twig\Node\Expression\Binary\RangeBinary; +use Twig\Node\ModuleNode; +use Twig\Node\Node; use Twig\Node\PrintNode; use Twig\Node\SandboxedPrintNode; -use Twig\Node\Node; -use Twig\Node\CheckSecurityNode; -use Twig\Environment; +use Twig\NodeVisitor\AbstractNodeVisitor; /** * Twig_NodeVisitor_Sandbox implements sandboxing. diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index abe443d3b..1b178484e 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -10,25 +10,25 @@ * file that was distributed with this source code. */ -use Twig\ExpressionParser; -use Twig\Node\Node; -use Twig\Node\ModuleNode; -use Twig\Node\BodyNode; -use Twig\NodeTraverser; -use Twig\Node\TextNode; -use Twig\Node\PrintNode; +use Twig\Environment; use Twig\Error\SyntaxError; +use Twig\ExpressionParser; +use Twig\Node\BlockNode; +use Twig\Node\BlockReferenceNode; +use Twig\Node\BodyNode; +use Twig\Node\Expression\AbstractExpression; +use Twig\Node\MacroNode; +use Twig\Node\ModuleNode; +use Twig\Node\Node; +use Twig\Node\NodeCaptureInterface; +use Twig\Node\NodeOutputInterface; +use Twig\Node\PrintNode; +use Twig\Node\TextNode; +use Twig\NodeTraverser; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Token; use Twig\TokenParser\TokenParserInterface; use Twig\TokenStream; -use Twig\Token; -use Twig\Node\BlockReferenceNode; -use Twig\Node\NodeOutputInterface; -use Twig\Node\NodeCaptureInterface; -use Twig\Environment; -use Twig\NodeVisitor\NodeVisitorInterface; -use Twig\Node\BlockNode; -use Twig\Node\MacroNode; -use Twig\Node\Expression\AbstractExpression; /** * Default parser implementation. diff --git a/lib/Twig/ParserInterface.php b/lib/Twig/ParserInterface.php index 438db65d4..96e9aaa94 100644 --- a/lib/Twig/ParserInterface.php +++ b/lib/Twig/ParserInterface.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\ModuleNode; use Twig\Error\SyntaxError; +use Twig\Node\ModuleNode; use Twig\TokenStream; /** diff --git a/lib/Twig/Profiler/Node/EnterProfile.php b/lib/Twig/Profiler/Node/EnterProfile.php index c1451c211..30f385f41 100644 --- a/lib/Twig/Profiler/Node/EnterProfile.php +++ b/lib/Twig/Profiler/Node/EnterProfile.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ +use Twig\Compiler; use Twig\Node\Node; use Twig\Profiler\Profile; -use Twig\Compiler; /** * Represents a profile enter node. diff --git a/lib/Twig/Profiler/Node/LeaveProfile.php b/lib/Twig/Profiler/Node/LeaveProfile.php index abe668fd9..cad2d90ed 100644 --- a/lib/Twig/Profiler/Node/LeaveProfile.php +++ b/lib/Twig/Profiler/Node/LeaveProfile.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Node\Node; use Twig\Compiler; +use Twig\Node\Node; /** * Represents a profile leave node. diff --git a/lib/Twig/Profiler/NodeVisitor/Profiler.php b/lib/Twig/Profiler/NodeVisitor/Profiler.php index fe7ac5c23..b6f458b31 100644 --- a/lib/Twig/Profiler/NodeVisitor/Profiler.php +++ b/lib/Twig/Profiler/NodeVisitor/Profiler.php @@ -9,16 +9,16 @@ * file that was distributed with this source code. */ -use Twig\NodeVisitor\AbstractNodeVisitor; -use Twig\Node\ModuleNode; -use Twig\Node\Node; -use Twig\Profiler\Node\EnterProfileNode; -use Twig\Profiler\Node\LeaveProfileNode; +use Twig\Environment; use Twig\Node\BlockNode; use Twig\Node\BodyNode; use Twig\Node\MacroNode; +use Twig\Node\ModuleNode; +use Twig\Node\Node; +use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\Profiler\Node\EnterProfileNode; +use Twig\Profiler\Node\LeaveProfileNode; use Twig\Profiler\Profile; -use Twig\Environment; /** * @author Fabien Potencier diff --git a/lib/Twig/Sandbox/SecurityPolicy.php b/lib/Twig/Sandbox/SecurityPolicy.php index ae42f6698..325b46c65 100644 --- a/lib/Twig/Sandbox/SecurityPolicy.php +++ b/lib/Twig/Sandbox/SecurityPolicy.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -use Twig\Sandbox\SecurityPolicyInterface; -use Twig\Sandbox\SecurityNotAllowedTagError; +use Twig\Markup; use Twig\Sandbox\SecurityNotAllowedFilterError; use Twig\Sandbox\SecurityNotAllowedFunctionError; -use Twig\Markup; use Twig\Sandbox\SecurityNotAllowedMethodError; use Twig\Sandbox\SecurityNotAllowedPropertyError; +use Twig\Sandbox\SecurityNotAllowedTagError; +use Twig\Sandbox\SecurityPolicyInterface; /** * Represents a security policy which need to be enforced when sandbox mode is enabled. diff --git a/lib/Twig/SourceContextLoaderInterface.php b/lib/Twig/SourceContextLoaderInterface.php index ce0dce14f..2319e8e1a 100644 --- a/lib/Twig/SourceContextLoaderInterface.php +++ b/lib/Twig/SourceContextLoaderInterface.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Source; use Twig\Error\LoaderError; +use Twig\Source; /** * Adds a getSourceContext() method for loaders. diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 916b50334..b8783ba3e 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -10,13 +10,13 @@ * file that was distributed with this source code. */ -use Twig\Source; -use Twig\TemplateWrapper; +use Twig\Environment; +use Twig\Error\Error; +use Twig\Error\LoaderError; use Twig\Error\RuntimeError; use Twig\Markup; -use Twig\Environment; -use Twig\Error\LoaderError; -use Twig\Error\Error; +use Twig\Source; +use Twig\TemplateWrapper; /** * Default base class for compiled templates. diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php index f696ce580..815c4f9f2 100644 --- a/lib/Twig/TemplateWrapper.php +++ b/lib/Twig/TemplateWrapper.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Source; use Twig\Environment; +use Twig\Source; use Twig\Template; /** diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index 574f583fb..4c2591f49 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -9,18 +9,17 @@ * file that was distributed with this source code. */ -use Twig\RuntimeLoader\RuntimeLoaderInterface; +use PHPUnit\Framework\TestCase; +use Twig\Environment; +use Twig\Error\Error; use Twig\Extension\ExtensionInterface; +use Twig\Loader\ArrayLoader; +use Twig\Loader\SourceContextLoaderInterface; +use Twig\RuntimeLoader\RuntimeLoaderInterface; +use Twig\Source; use Twig\TwigFilter; use Twig\TwigFunction; use Twig\TwigTest; -use Twig\Loader\ArrayLoader; -use Twig\Environment; -use Twig\Error\Error; -use Twig\Loader\SourceContextLoaderInterface; -use Twig\Source; - -use PHPUnit\Framework\TestCase; /** * Integration test helper. diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php index 43ee43872..e17b5526c 100644 --- a/lib/Twig/Test/NodeTestCase.php +++ b/lib/Twig/Test/NodeTestCase.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ +use PHPUnit\Framework\TestCase; use Twig\Compiler; use Twig\Environment; use Twig\Loader\ArrayLoader; use Twig\Node\Node; -use PHPUnit\Framework\TestCase; - abstract class Twig_Test_NodeTestCase extends TestCase { abstract public function getTests(); diff --git a/lib/Twig/TokenParser.php b/lib/Twig/TokenParser.php index 3634e1b75..22933ef72 100644 --- a/lib/Twig/TokenParser.php +++ b/lib/Twig/TokenParser.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\TokenParserInterface; use Twig\Parser; +use Twig\TokenParser\TokenParserInterface; /** * Base class for all token parsers. diff --git a/lib/Twig/TokenParser/AutoEscape.php b/lib/Twig/TokenParser/AutoEscape.php index 8b7f72185..e4ab10cde 100644 --- a/lib/Twig/TokenParser/AutoEscape.php +++ b/lib/Twig/TokenParser/AutoEscape.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; -use Twig\Node\Expression\ConstantExpression; use Twig\Error\SyntaxError; use Twig\Node\AutoEscapeNode; +use Twig\Node\Expression\ConstantExpression; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Marks a section of a template to be escaped or not. diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index 9a0b57836..d160bd09b 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -10,13 +10,13 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Error\SyntaxError; use Twig\Node\BlockNode; +use Twig\Node\BlockReferenceNode; use Twig\Node\Node; use Twig\Node\PrintNode; -use Twig\Node\BlockReferenceNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Marks a section of a template as being reusable. diff --git a/lib/Twig/TokenParser/Deprecated.php b/lib/Twig/TokenParser/Deprecated.php index dca8a0efd..6ed71f94d 100644 --- a/lib/Twig/TokenParser/Deprecated.php +++ b/lib/Twig/TokenParser/Deprecated.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\DeprecatedNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Deprecates a section of a template. diff --git a/lib/Twig/TokenParser/Do.php b/lib/Twig/TokenParser/Do.php index 4aa963a95..acedb5900 100644 --- a/lib/Twig/TokenParser/Do.php +++ b/lib/Twig/TokenParser/Do.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\DoNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Evaluates an expression, discarding the returned value. diff --git a/lib/Twig/TokenParser/Embed.php b/lib/Twig/TokenParser/Embed.php index e1a98e655..bf986fd4b 100644 --- a/lib/Twig/TokenParser/Embed.php +++ b/lib/Twig/TokenParser/Embed.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\IncludeTokenParser; -use Twig\Token; +use Twig\Node\EmbedNode; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\NameExpression; -use Twig\Node\EmbedNode; +use Twig\Token; +use Twig\TokenParser\IncludeTokenParser; /** * Embeds a template. diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php index ced7c08b6..4487524d3 100644 --- a/lib/Twig/TokenParser/Extends.php +++ b/lib/Twig/TokenParser/Extends.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Error\SyntaxError; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Extends a template by another one. diff --git a/lib/Twig/TokenParser/Filter.php b/lib/Twig/TokenParser/Filter.php index e25bdd21e..46c52b661 100644 --- a/lib/Twig/TokenParser/Filter.php +++ b/lib/Twig/TokenParser/Filter.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; +use Twig\Node\BlockNode; use Twig\Node\Expression\BlockReferenceExpression; use Twig\Node\Expression\ConstantExpression; -use Twig\Node\BlockNode; use Twig\Node\PrintNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Filters a section of a template by applying filters. diff --git a/lib/Twig/TokenParser/Flush.php b/lib/Twig/TokenParser/Flush.php index c43142b59..970ae1742 100644 --- a/lib/Twig/TokenParser/Flush.php +++ b/lib/Twig/TokenParser/Flush.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\FlushNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Flushes the output to the client. diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 212b16f7c..91dae7a69 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -10,14 +10,14 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; +use Twig\Error\SyntaxError; use Twig\Node\Expression\AssignNameExpression; -use Twig\Node\ForNode; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\GetAttrExpression; use Twig\Node\Expression\NameExpression; -use Twig\Error\SyntaxError; -use Twig\Node\Expression\ConstantExpression; +use Twig\Node\ForNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; use Twig\TokenStream; /** diff --git a/lib/Twig/TokenParser/From.php b/lib/Twig/TokenParser/From.php index bb453cb52..1adafb7aa 100644 --- a/lib/Twig/TokenParser/From.php +++ b/lib/Twig/TokenParser/From.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; -use Twig\Node\ImportNode; -use Twig\Node\Expression\AssignNameExpression; use Twig\Error\SyntaxError; +use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\ImportNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Imports macros. diff --git a/lib/Twig/TokenParser/If.php b/lib/Twig/TokenParser/If.php index be49393bd..40f63a5da 100644 --- a/lib/Twig/TokenParser/If.php +++ b/lib/Twig/TokenParser/If.php @@ -10,11 +10,11 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Error\SyntaxError; use Twig\Node\IfNode; use Twig\Node\Node; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Tests a condition. diff --git a/lib/Twig/TokenParser/Import.php b/lib/Twig/TokenParser/Import.php index f9dfbf13f..326fd8d6c 100644 --- a/lib/Twig/TokenParser/Import.php +++ b/lib/Twig/TokenParser/Import.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\Expression\AssignNameExpression; use Twig\Node\ImportNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Imports macros. diff --git a/lib/Twig/TokenParser/Include.php b/lib/Twig/TokenParser/Include.php index 49d88e79e..3c2a7e06f 100644 --- a/lib/Twig/TokenParser/Include.php +++ b/lib/Twig/TokenParser/Include.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\IncludeNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Includes a template. diff --git a/lib/Twig/TokenParser/Macro.php b/lib/Twig/TokenParser/Macro.php index 946e94543..d228b63a4 100644 --- a/lib/Twig/TokenParser/Macro.php +++ b/lib/Twig/TokenParser/Macro.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Error\SyntaxError; -use Twig\Node\MacroNode; use Twig\Node\BodyNode; +use Twig\Node\MacroNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Defines a macro. diff --git a/lib/Twig/TokenParser/Sandbox.php b/lib/Twig/TokenParser/Sandbox.php index 06da84224..08cb9b98a 100644 --- a/lib/Twig/TokenParser/Sandbox.php +++ b/lib/Twig/TokenParser/Sandbox.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; -use Twig\Node\IncludeNode; -use Twig\Node\TextNode; use Twig\Error\SyntaxError; +use Twig\Node\IncludeNode; use Twig\Node\SandboxNode; +use Twig\Node\TextNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Marks a section of a template as untrusted code that must be evaluated in the sandbox mode. diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php index 4006bd6f9..60ec71108 100644 --- a/lib/Twig/TokenParser/Set.php +++ b/lib/Twig/TokenParser/Set.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Error\SyntaxError; use Twig\Node\SetNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Defines a variable. diff --git a/lib/Twig/TokenParser/Spaceless.php b/lib/Twig/TokenParser/Spaceless.php index e6a2a0fec..90ae88783 100644 --- a/lib/Twig/TokenParser/Spaceless.php +++ b/lib/Twig/TokenParser/Spaceless.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\SpacelessNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Remove whitespaces between HTML tags. diff --git a/lib/Twig/TokenParser/Use.php b/lib/Twig/TokenParser/Use.php index 4e27f3783..53bb5bf3c 100644 --- a/lib/Twig/TokenParser/Use.php +++ b/lib/Twig/TokenParser/Use.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; -use Twig\Node\Expression\ConstantExpression; use Twig\Error\SyntaxError; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Node; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Imports blocks defined in another template into the current template. diff --git a/lib/Twig/TokenParser/With.php b/lib/Twig/TokenParser/With.php index b8f8478fb..a647acb9f 100644 --- a/lib/Twig/TokenParser/With.php +++ b/lib/Twig/TokenParser/With.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\TokenParser\AbstractTokenParser; use Twig\Node\WithNode; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; /** * Creates a nested scope. diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index 7bafc0d4f..edc57bd4c 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ +use Twig\Error\SyntaxError; use Twig\Source; use Twig\Token; -use Twig\Error\SyntaxError; /** * Represents a token stream. diff --git a/lib/Twig/Util/DeprecationCollector.php b/lib/Twig/Util/DeprecationCollector.php index 2729f91a5..45589ccf2 100644 --- a/lib/Twig/Util/DeprecationCollector.php +++ b/lib/Twig/Util/DeprecationCollector.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Util\TemplateDirIterator; -use Twig\Source; use Twig\Environment; use Twig\Error\SyntaxError; +use Twig\Source; +use Twig\Util\TemplateDirIterator; /** * @author Fabien Potencier diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index 5387300ff..5ade8eb06 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -9,20 +9,20 @@ * file that was distributed with this source code. */ -use Twig\Environment; -use Twig\Loader\ArrayLoader; -use Twig\Source; use Twig\Cache\FilesystemCache; +use Twig\Environment; use Twig\Extension\AbstractExtension; use Twig\Extension\GlobalsInterface; -use Twig\TwigFilter; -use Twig\TwigTest; -use Twig\TwigFunction; -use Twig\TokenParser\AbstractTokenParser; -use Twig\NodeVisitor\NodeVisitorInterface; use Twig\Extension\InitRuntimeInterface; +use Twig\Loader\ArrayLoader; use Twig\Loader\LoaderInterface; +use Twig\NodeVisitor\NodeVisitorInterface; +use Twig\Source; use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; +use Twig\TwigFilter; +use Twig\TwigFunction; +use Twig\TwigTest; require_once __DIR__.'/FilesystemHelper.php'; diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php index 4170eb7bd..c20a3c638 100644 --- a/test/Twig/Tests/ErrorTest.php +++ b/test/Twig/Tests/ErrorTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\Error\Error; -use Twig\Source; -use Twig\Loader\ArrayLoader; use Twig\Environment; -use Twig\Loader\FilesystemLoader; +use Twig\Error\Error; use Twig\Error\RuntimeError; +use Twig\Loader\ArrayLoader; +use Twig\Loader\FilesystemLoader; +use Twig\Source; class Twig_Tests_ErrorTest extends \PHPUnit\Framework\TestCase { diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php index e70716afb..169693807 100644 --- a/test/Twig/Tests/ExpressionParserTest.php +++ b/test/Twig/Tests/ExpressionParserTest.php @@ -10,12 +10,12 @@ */ use Twig\Environment; +use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\Binary\ConcatBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; use Twig\Parser; use Twig\Source; -use Twig\Node\Expression\ArrayExpression; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\Binary\ConcatBinary; -use Twig\Node\Expression\NameExpression; class Twig_Tests_ExpressionParserTest extends \PHPUnit\Framework\TestCase { diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php index 49da23574..b686ad72d 100644 --- a/test/Twig/Tests/Extension/SandboxTest.php +++ b/test/Twig/Tests/Extension/SandboxTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\Loader\ArrayLoader; use Twig\Environment; -use Twig\Sandbox\SecurityPolicy; use Twig\Extension\SandboxExtension; +use Twig\Loader\ArrayLoader; use Twig\Sandbox\SecurityError; +use Twig\Sandbox\SecurityPolicy; class Twig_Tests_Extension_SandboxTest extends \PHPUnit\Framework\TestCase { diff --git a/test/Twig/Tests/IntegrationTest.php b/test/Twig/Tests/IntegrationTest.php index acec89bf6..be25047c8 100644 --- a/test/Twig/Tests/IntegrationTest.php +++ b/test/Twig/Tests/IntegrationTest.php @@ -9,19 +9,19 @@ * file that was distributed with this source code. */ -use Twig\Test\IntegrationTestCase; -use Twig\Sandbox\SecurityPolicy; +use Twig\Extension\AbstractExtension; use Twig\Extension\DebugExtension; use Twig\Extension\SandboxExtension; use Twig\Extension\StringLoaderExtension; -use Twig\TokenParser\AbstractTokenParser; -use Twig\Node\PrintNode; use Twig\Node\Expression\ConstantExpression; -use Twig\Extension\AbstractExtension; +use Twig\Node\PrintNode; +use Twig\Sandbox\SecurityPolicy; +use Twig\Test\IntegrationTestCase; +use Twig\Token; +use Twig\TokenParser\AbstractTokenParser; use Twig\TwigFilter; use Twig\TwigFunction; use Twig\TwigTest; -use Twig\Token; // This function is defined to check that escaping strategies // like html works even if a function with the same name is defined. diff --git a/test/Twig/Tests/LegacyIntegrationTest.php b/test/Twig/Tests/LegacyIntegrationTest.php index c840f3e77..92cac3f8a 100644 --- a/test/Twig/Tests/LegacyIntegrationTest.php +++ b/test/Twig/Tests/LegacyIntegrationTest.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Test\IntegrationTestCase; use Twig\Extension\AbstractExtension; +use Twig\Test\IntegrationTestCase; class Twig_Tests_LegacyIntegrationTest extends IntegrationTestCase { diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php index b67cda6ee..4055719d9 100644 --- a/test/Twig/Tests/LexerTest.php +++ b/test/Twig/Tests/LexerTest.php @@ -9,10 +9,11 @@ * file that was distributed with this source code. */ -use Twig\Lexer; use Twig\Environment; +use Twig\Lexer; use Twig\Source; use Twig\Token; + class Twig_Tests_LexerTest extends \PHPUnit\Framework\TestCase { /** diff --git a/test/Twig/Tests/Loader/ChainTest.php b/test/Twig/Tests/Loader/ChainTest.php index a2173a637..8d52e806c 100644 --- a/test/Twig/Tests/Loader/ChainTest.php +++ b/test/Twig/Tests/Loader/ChainTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\Loader\ChainLoader; use Twig\Loader\ArrayLoader; +use Twig\Loader\ChainLoader; use Twig\Loader\FilesystemLoader; -use Twig\Source; use Twig\Loader\LoaderInterface; +use Twig\Source; class Twig_Tests_Loader_ChainTest extends \PHPUnit\Framework\TestCase { diff --git a/test/Twig/Tests/Loader/FilesystemTest.php b/test/Twig/Tests/Loader/FilesystemTest.php index 2c8db82e2..f03fead99 100644 --- a/test/Twig/Tests/Loader/FilesystemTest.php +++ b/test/Twig/Tests/Loader/FilesystemTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Loader\FilesystemLoader; use Twig\Environment; use Twig\Error\LoaderError; +use Twig\Loader\FilesystemLoader; class Twig_Tests_Loader_FilesystemTest extends \PHPUnit\Framework\TestCase { diff --git a/test/Twig/Tests/Node/AutoEscapeTest.php b/test/Twig/Tests/Node/AutoEscapeTest.php index 6a50d69cd..1633e0604 100644 --- a/test/Twig/Tests/Node/AutoEscapeTest.php +++ b/test/Twig/Tests/Node/AutoEscapeTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; +use Twig\Node\AutoEscapeNode; use Twig\Node\Node; use Twig\Node\TextNode; -use Twig\Node\AutoEscapeNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_AutoEscapeTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/BlockReferenceTest.php b/test/Twig/Tests/Node/BlockReferenceTest.php index b20fd0a51..ff021ff76 100644 --- a/test/Twig/Tests/Node/BlockReferenceTest.php +++ b/test/Twig/Tests/Node/BlockReferenceTest.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\BlockReferenceNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_BlockReferenceTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/BlockTest.php b/test/Twig/Tests/Node/BlockTest.php index d6ba624c5..8b4a1eca4 100644 --- a/test/Twig/Tests/Node/BlockTest.php +++ b/test/Twig/Tests/Node/BlockTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\TextNode; use Twig\Node\BlockNode; +use Twig\Node\TextNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_BlockTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/DeprecatedTest.php b/test/Twig/Tests/Node/DeprecatedTest.php index df6a051e5..2fb6f9621 100644 --- a/test/Twig/Tests/Node/DeprecatedTest.php +++ b/test/Twig/Tests/Node/DeprecatedTest.php @@ -9,14 +9,14 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\DeprecatedNode; -use Twig\Node\Node; -use Twig\Node\IfNode; use Twig\Environment; -use Twig\TwigFunction; +use Twig\Node\DeprecatedNode; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FunctionExpression; +use Twig\Node\IfNode; +use Twig\Node\Node; +use Twig\Test\NodeTestCase; +use Twig\TwigFunction; class Twig_Tests_Node_DeprecatedTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/DoTest.php b/test/Twig/Tests/Node/DoTest.php index 8cac0cb1f..ffddda488 100644 --- a/test/Twig/Tests/Node/DoTest.php +++ b/test/Twig/Tests/Node/DoTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\DoNode; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_DoTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/ArrayTest.php b/test/Twig/Tests/Node/Expression/ArrayTest.php index 6c3ce1c0b..842dac40c 100644 --- a/test/Twig/Tests/Node/Expression/ArrayTest.php +++ b/test/Twig/Tests/Node/Expression/ArrayTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_ArrayTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/AssignNameTest.php b/test/Twig/Tests/Node/Expression/AssignNameTest.php index 8e398bb58..47fddcae1 100644 --- a/test/Twig/Tests/Node/Expression/AssignNameTest.php +++ b/test/Twig/Tests/Node/Expression/AssignNameTest.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\AssignNameExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_AssignNameTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/AddTest.php b/test/Twig/Tests/Node/Expression/Binary/AddTest.php index 0df68285c..d91ee8e5c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AddTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AddTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\AddBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_AddTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/AndTest.php b/test/Twig/Tests/Node/Expression/Binary/AndTest.php index e7aea1d52..61cc1c935 100644 --- a/test/Twig/Tests/Node/Expression/Binary/AndTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/AndTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\AndBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_AndTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php index 993082515..f8d4c6e6f 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ConcatTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\ConcatBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_ConcatTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/DivTest.php b/test/Twig/Tests/Node/Expression/Binary/DivTest.php index 830e9c996..b6054239c 100644 --- a/test/Twig/Tests/Node/Expression/Binary/DivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/DivTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\DivBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_DivTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php index f94fca736..cb27e007d 100644 --- a/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/FloorDivTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\FloorDivBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_FloorDivTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/ModTest.php b/test/Twig/Tests/Node/Expression/Binary/ModTest.php index 5697c02d2..c5497cd6f 100644 --- a/test/Twig/Tests/Node/Expression/Binary/ModTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/ModTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\ModBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_ModTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/MulTest.php b/test/Twig/Tests/Node/Expression/Binary/MulTest.php index 8027926a9..3b19b0585 100644 --- a/test/Twig/Tests/Node/Expression/Binary/MulTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/MulTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\MulBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_MulTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/OrTest.php b/test/Twig/Tests/Node/Expression/Binary/OrTest.php index a1159ad5c..0f1c3bf43 100644 --- a/test/Twig/Tests/Node/Expression/Binary/OrTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/OrTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\OrBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_OrTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Binary/SubTest.php b/test/Twig/Tests/Node/Expression/Binary/SubTest.php index e039c1609..9955c4be4 100644 --- a/test/Twig/Tests/Node/Expression/Binary/SubTest.php +++ b/test/Twig/Tests/Node/Expression/Binary/SubTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Binary\SubBinary; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Binary_SubTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/ConditionalTest.php b/test/Twig/Tests/Node/Expression/ConditionalTest.php index 7d2ac5433..32be4d0e5 100644 --- a/test/Twig/Tests/Node/Expression/ConditionalTest.php +++ b/test/Twig/Tests/Node/Expression/ConditionalTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_ConditionalTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/ConstantTest.php b/test/Twig/Tests/Node/Expression/ConstantTest.php index 850b8ca59..ae38101b5 100644 --- a/test/Twig/Tests/Node/Expression/ConstantTest.php +++ b/test/Twig/Tests/Node/Expression/ConstantTest.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\ConstantExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_ConstantTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 727cb3db4..1cca1a57a 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -9,11 +9,11 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Node; -use Twig\Node\Expression\FilterExpression; use Twig\Environment; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FilterExpression; +use Twig\Node\Node; +use Twig\Test\NodeTestCase; use Twig\TwigFilter; class Twig_Tests_Node_Expression_FilterTest extends NodeTestCase diff --git a/test/Twig/Tests/Node/Expression/FunctionTest.php b/test/Twig/Tests/Node/Expression/FunctionTest.php index 8ca3eec48..51001a63f 100644 --- a/test/Twig/Tests/Node/Expression/FunctionTest.php +++ b/test/Twig/Tests/Node/Expression/FunctionTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Node; -use Twig\Node\Expression\FunctionExpression; use Twig\Environment; -use Twig\TwigFunction; use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\FunctionExpression; +use Twig\Node\Node; +use Twig\Test\NodeTestCase; +use Twig\TwigFunction; class Twig_Tests_Node_Expression_FunctionTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/GetAttrTest.php b/test/Twig/Tests/Node/Expression/GetAttrTest.php index 048e82089..036b42194 100644 --- a/test/Twig/Tests/Node/Expression/GetAttrTest.php +++ b/test/Twig/Tests/Node/Expression/GetAttrTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\NameExpression; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\ArrayExpression; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\GetAttrExpression; +use Twig\Node\Expression\NameExpression; use Twig\Template; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_GetAttrTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/NameTest.php b/test/Twig/Tests/Node/Expression/NameTest.php index f9611d5a9..269c04b4c 100644 --- a/test/Twig/Tests/Node/Expression/NameTest.php +++ b/test/Twig/Tests/Node/Expression/NameTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\NameExpression; use Twig\Environment; +use Twig\Node\Expression\NameExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_NameTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php index 57a7bd490..eb7c33573 100644 --- a/test/Twig/Tests/Node/Expression/NullCoalesceTest.php +++ b/test/Twig/Tests/Node/Expression/NullCoalesceTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\NameExpression; use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; use Twig\Node\Expression\NullCoalesceExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_NullCoalesceTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/ParentTest.php b/test/Twig/Tests/Node/Expression/ParentTest.php index 988ad34ac..0c3a9aafb 100644 --- a/test/Twig/Tests/Node/Expression/ParentTest.php +++ b/test/Twig/Tests/Node/Expression/ParentTest.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\ParentExpression; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_ParentTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/TestTest.php b/test/Twig/Tests/Node/Expression/TestTest.php index 712568785..ef7fb66ef 100644 --- a/test/Twig/Tests/Node/Expression/TestTest.php +++ b/test/Twig/Tests/Node/Expression/TestTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Node; -use Twig\Node\Expression\TestExpression; use Twig\Environment; -use Twig\TwigTest; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Test\NullTest; +use Twig\Node\Expression\TestExpression; +use Twig\Node\Node; +use Twig\Test\NodeTestCase; +use Twig\TwigTest; class Twig_Tests_Node_Expression_TestTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Unary/NegTest.php b/test/Twig/Tests/Node/Expression/Unary/NegTest.php index d2b72a79b..6c976ad4c 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NegTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NegTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Unary\NegUnary; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Unary_NegTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Unary/NotTest.php b/test/Twig/Tests/Node/Expression/Unary/NotTest.php index 05ea3ffce..493a37e55 100644 --- a/test/Twig/Tests/Node/Expression/Unary/NotTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/NotTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Unary\NotUnary; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Unary_NotTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/Expression/Unary/PosTest.php b/test/Twig/Tests/Node/Expression/Unary/PosTest.php index 294b2ff92..015446d43 100644 --- a/test/Twig/Tests/Node/Expression/Unary/PosTest.php +++ b/test/Twig/Tests/Node/Expression/Unary/PosTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Unary\PosUnary; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_Expression_Unary_PosTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php index 60265a0d3..44b986e46 100644 --- a/test/Twig/Tests/Node/ForTest.php +++ b/test/Twig/Tests/Node/ForTest.php @@ -9,13 +9,13 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\AssignNameExpression; -use Twig\Node\Expression\NameExpression; use Twig\Node\Expression\ConstantExpression; +use Twig\Node\Expression\NameExpression; +use Twig\Node\ForNode; use Twig\Node\Node; use Twig\Node\PrintNode; -use Twig\Node\ForNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_ForTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/IfTest.php b/test/Twig/Tests/Node/IfTest.php index bf41e12c1..82a695931 100644 --- a/test/Twig/Tests/Node/IfTest.php +++ b/test/Twig/Tests/Node/IfTest.php @@ -9,12 +9,12 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Node; use Twig\Node\Expression\ConstantExpression; -use Twig\Node\PrintNode; use Twig\Node\Expression\NameExpression; use Twig\Node\IfNode; +use Twig\Node\Node; +use Twig\Node\PrintNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_IfTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/ImportTest.php b/test/Twig/Tests/Node/ImportTest.php index 6b214a8d7..56e56e688 100644 --- a/test/Twig/Tests/Node/ImportTest.php +++ b/test/Twig/Tests/Node/ImportTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\AssignNameExpression; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\ImportNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_ImportTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/IncludeTest.php b/test/Twig/Tests/Node/IncludeTest.php index 1ace5e061..bdb9d0a99 100644 --- a/test/Twig/Tests/Node/IncludeTest.php +++ b/test/Twig/Tests/Node/IncludeTest.php @@ -9,12 +9,11 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\IncludeNode; use Twig\Node\Expression\ArrayExpression; use Twig\Node\Expression\ConditionalExpression; -use Twig\Error\LoaderError; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\IncludeNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_IncludeTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 838337687..429fa6e11 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -9,13 +9,12 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\TextNode; -use Twig\Node\Node; +use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\NameExpression; use Twig\Node\MacroNode; -use Twig\Node\Expression\ConstantExpression; -use Twig\Markup; +use Twig\Node\Node; +use Twig\Node\TextNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_MacroTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 8c7b2b059..d27743976 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -9,17 +9,17 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\TextNode; -use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Node; -use Twig\Source; -use Twig\Node\ModuleNode; use Twig\Environment; -use Twig\Node\ImportNode; use Twig\Node\Expression\AssignNameExpression; -use Twig\Node\SetNode; use Twig\Node\Expression\ConditionalExpression; +use Twig\Node\Expression\ConstantExpression; +use Twig\Node\ImportNode; +use Twig\Node\ModuleNode; +use Twig\Node\Node; +use Twig\Node\SetNode; +use Twig\Node\TextNode; +use Twig\Source; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_ModuleTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/PrintTest.php b/test/Twig/Tests/Node/PrintTest.php index f7ddd3353..efb5ebafc 100644 --- a/test/Twig/Tests/Node/PrintTest.php +++ b/test/Twig/Tests/Node/PrintTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Expression\ConstantExpression; use Twig\Node\PrintNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_PrintTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/SandboxTest.php b/test/Twig/Tests/Node/SandboxTest.php index 2d8e1778b..9b9f7cc76 100644 --- a/test/Twig/Tests/Node/SandboxTest.php +++ b/test/Twig/Tests/Node/SandboxTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\TextNode; use Twig\Node\SandboxNode; +use Twig\Node\TextNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_SandboxTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/SandboxedPrintTest.php b/test/Twig/Tests/Node/SandboxedPrintTest.php index 99c236371..7a06d97d9 100644 --- a/test/Twig/Tests/Node/SandboxedPrintTest.php +++ b/test/Twig/Tests/Node/SandboxedPrintTest.php @@ -9,9 +9,9 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\SandboxedPrintNode; use Twig\Node\Expression\ConstantExpression; +use Twig\Node\SandboxedPrintNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_SandboxedPrintTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/SetTest.php b/test/Twig/Tests/Node/SetTest.php index 5e6a7ff08..4f6b94271 100644 --- a/test/Twig/Tests/Node/SetTest.php +++ b/test/Twig/Tests/Node/SetTest.php @@ -9,15 +9,14 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; -use Twig\Node\Node; use Twig\Node\Expression\AssignNameExpression; use Twig\Node\Expression\ConstantExpression; -use Twig\Node\SetNode; -use Twig\Node\PrintNode; -use Twig\Markup; -use Twig\Node\TextNode; use Twig\Node\Expression\NameExpression; +use Twig\Node\Node; +use Twig\Node\PrintNode; +use Twig\Node\SetNode; +use Twig\Node\TextNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_SetTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/SpacelessTest.php b/test/Twig/Tests/Node/SpacelessTest.php index 22e59e476..c0b7d526a 100644 --- a/test/Twig/Tests/Node/SpacelessTest.php +++ b/test/Twig/Tests/Node/SpacelessTest.php @@ -9,10 +9,10 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\Node; -use Twig\Node\TextNode; use Twig\Node\SpacelessNode; +use Twig\Node\TextNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_SpacelessTest extends NodeTestCase { diff --git a/test/Twig/Tests/Node/TextTest.php b/test/Twig/Tests/Node/TextTest.php index f2d7eb2af..6735083ce 100644 --- a/test/Twig/Tests/Node/TextTest.php +++ b/test/Twig/Tests/Node/TextTest.php @@ -9,8 +9,8 @@ * file that was distributed with this source code. */ -use Twig\Test\NodeTestCase; use Twig\Node\TextNode; +use Twig\Test\NodeTestCase; class Twig_Tests_Node_TextTest extends NodeTestCase { diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 83969d703..9afdbc603 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -10,8 +10,9 @@ */ use Twig\Environment; -use Twig\Source; use Twig\Node\ForNode; +use Twig\Source; + class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase { public function testRenderBlockOptimizer() diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 2a07e7341..bb39dc9b9 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -9,15 +9,16 @@ * file that was distributed with this source code. */ -use Twig\TokenStream; -use Twig\Token; -use Twig\Parser; use Twig\Environment; use Twig\Node\Node; -use Twig\Node\TextNode; use Twig\Node\SetNode; +use Twig\Node\TextNode; +use Twig\Parser; use Twig\Source; +use Twig\Token; use Twig\TokenParser\AbstractTokenParser; +use Twig\TokenStream; + class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase { /** diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 56808cbc6..d8f6a180e 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -10,15 +10,16 @@ */ use Twig\Environment; -use Twig\Loader\ArrayLoader; -use Twig\Sandbox\SecurityPolicy; -use Twig\Extension\SandboxExtension; -use Twig\Template; -use Twig\NodeVisitor\NodeVisitorInterface; -use Twig\Node\Expression\GetAttrExpression; -use Twig\Loader\LoaderInterface; use Twig\Error\RuntimeError; +use Twig\Extension\SandboxExtension; +use Twig\Loader\ArrayLoader; +use Twig\Loader\LoaderInterface; +use Twig\Node\Expression\GetAttrExpression; +use Twig\NodeVisitor\NodeVisitorInterface; use Twig\Sandbox\SecurityError; +use Twig\Sandbox\SecurityPolicy; +use Twig\Template; + class Twig_Tests_TemplateTest extends \PHPUnit\Framework\TestCase { /** diff --git a/test/Twig/Tests/TemplateWrapperTest.php b/test/Twig/Tests/TemplateWrapperTest.php index 3242dd024..0522895ce 100644 --- a/test/Twig/Tests/TemplateWrapperTest.php +++ b/test/Twig/Tests/TemplateWrapperTest.php @@ -12,6 +12,7 @@ use Twig\Environment; use Twig\Loader\ArrayLoader; use Twig\TemplateWrapper; + class Twig_Tests_TemplateWrapperTest extends \PHPUnit\Framework\TestCase { public function testHasGetBlocks()