From 59f3e8e5dc3045f9e2191dd07d7d30b91f013eb9 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 12 May 2021 09:19:37 +0200 Subject: [PATCH] Fix CS --- lib/Twig/Autoloader.php | 4 +- lib/Twig/Filter.php | 2 +- lib/Twig/Filter/Function.php | 2 +- lib/Twig/Filter/Method.php | 2 +- lib/Twig/Filter/Node.php | 2 +- lib/Twig/Function.php | 2 +- lib/Twig/Function/Function.php | 2 +- lib/Twig/Function/Method.php | 2 +- lib/Twig/Function/Node.php | 2 +- lib/Twig/Loader/String.php | 4 +- .../Node/Expression/ExtensionReference.php | 2 +- lib/Twig/TemplateInterface.php | 6 +- lib/Twig/Test.php | 2 +- lib/Twig/Test/Function.php | 2 +- lib/Twig/Test/Method.php | 2 +- lib/Twig/Test/Node.php | 2 +- lib/Twig/TokenParserBroker.php | 2 +- src/Cache/FilesystemCache.php | 4 +- src/Compiler.php | 12 +-- src/Environment.php | 78 +++++++++---------- src/Error/Error.php | 10 +-- src/ExpressionParser.php | 14 ++-- src/Extension/CoreExtension.php | 13 ++-- src/Extension/EscaperExtension.php | 4 +- src/Extension/StagingExtension.php | 8 +- src/FileExtensionEscapingStrategy.php | 2 +- src/Lexer.php | 36 ++++----- src/Loader/ArrayLoader.php | 2 +- src/Loader/ChainLoader.php | 2 +- src/Loader/FilesystemLoader.php | 10 +-- .../Expression/BlockReferenceExpression.php | 2 +- src/Node/Expression/GetAttrExpression.php | 2 +- src/Node/MacroNode.php | 2 +- src/Node/ModuleNode.php | 2 +- src/Node/Node.php | 12 +-- src/NodeVisitor/OptimizerNodeVisitor.php | 10 +-- src/Parser.php | 8 +- src/Profiler/Profile.php | 8 +- src/Template.php | 12 +-- src/Test/IntegrationTestCase.php | 4 +- src/Token.php | 28 +++---- src/TokenParser/AutoEscapeTokenParser.php | 2 +- src/TokenStream.php | 6 +- src/Util/DeprecationCollector.php | 2 +- tests/CompilerTest.php | 8 +- tests/EnvironmentTest.php | 2 +- tests/ErrorTest.php | 4 +- tests/Extension/StringLoaderExtensionTest.php | 4 +- tests/IntegrationTest.php | 2 +- 49 files changed, 179 insertions(+), 178 deletions(-) diff --git a/lib/Twig/Autoloader.php b/lib/Twig/Autoloader.php index e34e2144f..4b4d856ed 100644 --- a/lib/Twig/Autoloader.php +++ b/lib/Twig/Autoloader.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Autoloader class is deprecated since version 1.21 and will be removed in 2.0. Use Composer instead.', \E_USER_DEPRECATED); /** * Autoloads Twig classes. @@ -27,7 +27,7 @@ class Twig_Autoloader */ public static function register($prepend = false) { - @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', E_USER_DEPRECATED); + @trigger_error('Using Twig_Autoloader is deprecated since version 1.21. Use Composer instead.', \E_USER_DEPRECATED); spl_autoload_register([__CLASS__, 'autoload'], true, $prepend); } diff --git a/lib/Twig/Filter.php b/lib/Twig/Filter.php index da4191e31..3a1ff3db9 100644 --- a/lib/Twig/Filter.php +++ b/lib/Twig/Filter.php @@ -11,7 +11,7 @@ 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\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a template filter. diff --git a/lib/Twig/Filter/Function.php b/lib/Twig/Filter/Function.php index 011d4ccf4..5648b3a8f 100644 --- a/lib/Twig/Filter/Function.php +++ b/lib/Twig/Filter/Function.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Filter_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a function template filter. diff --git a/lib/Twig/Filter/Method.php b/lib/Twig/Filter/Method.php index 5cd062822..1d505f48a 100644 --- a/lib/Twig/Filter/Method.php +++ b/lib/Twig/Filter/Method.php @@ -11,7 +11,7 @@ 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\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a method template filter. diff --git a/lib/Twig/Filter/Node.php b/lib/Twig/Filter/Node.php index 8bb2899c5..31c50210f 100644 --- a/lib/Twig/Filter/Node.php +++ b/lib/Twig/Filter/Node.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Filter_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Filter_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFilter instead.', \E_USER_DEPRECATED); /** * Represents a template filter as a node. diff --git a/lib/Twig/Function.php b/lib/Twig/Function.php index 6646e746f..d47bbc55f 100644 --- a/lib/Twig/Function.php +++ b/lib/Twig/Function.php @@ -11,7 +11,7 @@ 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\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a template function. diff --git a/lib/Twig/Function/Function.php b/lib/Twig/Function/Function.php index 605d8d335..2e2498e4a 100644 --- a/lib/Twig/Function/Function.php +++ b/lib/Twig/Function/Function.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Function_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a function template function. diff --git a/lib/Twig/Function/Method.php b/lib/Twig/Function/Method.php index 9e472c5d1..dd798cfdf 100644 --- a/lib/Twig/Function/Method.php +++ b/lib/Twig/Function/Method.php @@ -12,7 +12,7 @@ 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\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a method template function. diff --git a/lib/Twig/Function/Node.php b/lib/Twig/Function/Node.php index 8148ec32d..8b906caae 100644 --- a/lib/Twig/Function/Node.php +++ b/lib/Twig/Function/Node.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Function_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Function_Node class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigFunction instead.', \E_USER_DEPRECATED); /** * Represents a template function as a node. diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index cb3b2a004..0beaed894 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -14,7 +14,7 @@ use Twig\Loader\LoaderInterface; use Twig\Loader\SourceContextLoaderInterface; 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); +@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. @@ -36,7 +36,7 @@ class Twig_Loader_String implements LoaderInterface, ExistsLoaderInterface, Sour { public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); return $name; } diff --git a/lib/Twig/Node/Expression/ExtensionReference.php b/lib/Twig/Node/Expression/ExtensionReference.php index 9b8927a31..298067f45 100644 --- a/lib/Twig/Node/Expression/ExtensionReference.php +++ b/lib/Twig/Node/Expression/ExtensionReference.php @@ -12,7 +12,7 @@ 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); +@trigger_error('The Twig_Node_Expression_ExtensionReference class is deprecated since version 1.23 and will be removed in 2.0.', \E_USER_DEPRECATED); /** * Represents an extension call node. diff --git a/lib/Twig/TemplateInterface.php b/lib/Twig/TemplateInterface.php index 0f767b8fc..966bf2e20 100644 --- a/lib/Twig/TemplateInterface.php +++ b/lib/Twig/TemplateInterface.php @@ -20,9 +20,9 @@ use Twig\Environment; */ interface Twig_TemplateInterface { - const ANY_CALL = 'any'; - const ARRAY_CALL = 'array'; - const METHOD_CALL = 'method'; + public const ANY_CALL = 'any'; + public const ARRAY_CALL = 'array'; + public const METHOD_CALL = 'method'; /** * Renders the template with the given context and returns it as string. diff --git a/lib/Twig/Test.php b/lib/Twig/Test.php index d032284ea..1613284d2 100644 --- a/lib/Twig/Test.php +++ b/lib/Twig/Test.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Test class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', \E_USER_DEPRECATED); /** * Represents a template test. diff --git a/lib/Twig/Test/Function.php b/lib/Twig/Test/Function.php index a789c4025..4f125dfd5 100644 --- a/lib/Twig/Test/Function.php +++ b/lib/Twig/Test/Function.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Test_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test_Function class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', \E_USER_DEPRECATED); /** * Represents a function template test. diff --git a/lib/Twig/Test/Method.php b/lib/Twig/Test/Method.php index 4f16142b0..16185665d 100644 --- a/lib/Twig/Test/Method.php +++ b/lib/Twig/Test/Method.php @@ -11,7 +11,7 @@ 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\TwigTest instead.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test_Method class is deprecated since version 1.12 and will be removed in 2.0. Use \Twig\TwigTest instead.', \E_USER_DEPRECATED); /** * Represents a method template test. diff --git a/lib/Twig/Test/Node.php b/lib/Twig/Test/Node.php index 6b5de1597..96f207635 100644 --- a/lib/Twig/Test/Node.php +++ b/lib/Twig/Test/Node.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -@trigger_error('The Twig_Test_Node class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); +@trigger_error('The Twig_Test_Node class is deprecated since version 1.12 and will be removed in 2.0.', \E_USER_DEPRECATED); /** * Represents a template test as a Node. diff --git a/lib/Twig/TokenParserBroker.php b/lib/Twig/TokenParserBroker.php index 8cca809b8..5f30ff0b7 100644 --- a/lib/Twig/TokenParserBroker.php +++ b/lib/Twig/TokenParserBroker.php @@ -33,7 +33,7 @@ class Twig_TokenParserBroker implements Twig_TokenParserBrokerInterface public function __construct($parsers = [], $brokers = [], $triggerDeprecationError = true) { if ($triggerDeprecationError) { - @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__CLASS__.' class is deprecated since version 1.12 and will be removed in 2.0.', \E_USER_DEPRECATED); } foreach ($parsers as $parser) { diff --git a/src/Cache/FilesystemCache.php b/src/Cache/FilesystemCache.php index b7c1e438e..cd6b663b1 100644 --- a/src/Cache/FilesystemCache.php +++ b/src/Cache/FilesystemCache.php @@ -18,7 +18,7 @@ namespace Twig\Cache; */ class FilesystemCache implements CacheInterface { - const FORCE_BYTECODE_INVALIDATION = 1; + public const FORCE_BYTECODE_INVALIDATION = 1; private $directory; private $options; @@ -67,7 +67,7 @@ class FilesystemCache implements CacheInterface if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { // Compile cached file into bytecode cache - if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) { + if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) { @opcache_invalidate($key, true); } elseif (\function_exists('apc_compile_file')) { apc_compile_file($key); diff --git a/src/Compiler.php b/src/Compiler.php index e47003ae1..e8ddf7b7c 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -41,7 +41,7 @@ class Compiler implements \Twig_CompilerInterface */ public function getFilename() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), \E_USER_DEPRECATED); return $this->filename; } @@ -143,7 +143,7 @@ class Compiler implements \Twig_CompilerInterface */ public function addIndentation() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use write(\'\') instead.', \E_USER_DEPRECATED); $this->source .= str_repeat(' ', $this->indentation * 4); @@ -174,14 +174,14 @@ class Compiler implements \Twig_CompilerInterface public function repr($value) { if (\is_int($value) || \is_float($value)) { - if (false !== $locale = setlocale(LC_NUMERIC, '0')) { - setlocale(LC_NUMERIC, 'C'); + if (false !== $locale = setlocale(\LC_NUMERIC, '0')) { + setlocale(\LC_NUMERIC, 'C'); } $this->raw(var_export($value, true)); if (false !== $locale) { - setlocale(LC_NUMERIC, $locale); + setlocale(\LC_NUMERIC, $locale); } } elseif (null === $value) { $this->raw('null'); @@ -221,7 +221,7 @@ class Compiler implements \Twig_CompilerInterface // mb_substr_count() replaces substr_count() // but they have different signatures! if (((int) ini_get('mbstring.func_overload')) & 2) { - @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', \E_USER_DEPRECATED); // this is much slower than the "right" version $this->sourceLine += mb_substr_count(mb_substr($this->source, $this->sourceOffset), "\n"); diff --git a/src/Environment.php b/src/Environment.php index 694678a80..ab813f700 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -41,12 +41,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - const VERSION = '1.44.3-DEV'; - const VERSION_ID = 14403; - const MAJOR_VERSION = 1; - const MINOR_VERSION = 44; - const RELEASE_VERSION = 3; - const EXTRA_VERSION = 'DEV'; + public const VERSION = '1.44.3-DEV'; + public const VERSION_ID = 14403; + public const MAJOR_VERSION = 1; + public const MINOR_VERSION = 44; + public const RELEASE_VERSION = 3; + public const EXTRA_VERSION = 'DEV'; protected $charset; protected $loader; @@ -124,7 +124,7 @@ class Environment if (null !== $loader) { $this->setLoader($loader); } else { - @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); + @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([ @@ -154,14 +154,14 @@ class 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; } @@ -301,13 +301,13 @@ class Environment $this->originalCache = $cache; $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); + @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 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\Cache\CacheInterface implementation.')); + throw new \LogicException('Cache can only be a string, false, or a \Twig\Cache\CacheInterface implementation.'); } } @@ -322,7 +322,7 @@ class Environment */ public function getCacheFilename($name) { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); $key = $this->cache->generateKey($name, $this->getTemplateClass($name)); @@ -362,7 +362,7 @@ class Environment */ public function getTemplateClassPrefix() { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); return $this->templateClassPrefix; } @@ -626,7 +626,7 @@ class Environment */ public function clearTemplateCache() { - @trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.18.3 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); $this->loadedTemplates = []; } @@ -638,7 +638,7 @@ class Environment */ public function clearCacheFiles() { - @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.22 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); if (\is_string($this->originalCache)) { foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { @@ -658,7 +658,7 @@ class Environment */ public function getLexer() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @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 Lexer($this); @@ -685,7 +685,7 @@ class Environment public function tokenize($source, $name = null) { 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); + @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 Source($source, $name); } @@ -705,7 +705,7 @@ class Environment */ public function getParser() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @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 Parser($this); @@ -744,7 +744,7 @@ class Environment */ public function getCompiler() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.25 and will be removed in 2.0.', __FUNCTION__), E_USER_DEPRECATED); + @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 Compiler($this); @@ -785,7 +785,7 @@ class Environment public function compileSource($source, $name = null) { 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); + @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 Source($source, $name); } @@ -802,7 +802,7 @@ class Environment public function setLoader(LoaderInterface $loader) { if (!$loader instanceof SourceContextLoaderInterface && 0 !== strpos(\get_class($loader), 'Mock_')) { - @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), E_USER_DEPRECATED); + @trigger_error(sprintf('Twig loader "%s" should implement Twig\Loader\SourceContextLoaderInterface since version 1.27.', \get_class($loader)), \E_USER_DEPRECATED); } $this->loader = $loader; @@ -857,7 +857,7 @@ class Environment $parentClass = $m->getDeclaringClass()->getName(); if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) { - @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); } } @@ -883,7 +883,7 @@ class Environment if (isset($this->extensions[$class])) { if ($class !== \get_class($this->extensions[$class])) { - @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED); + @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), \E_USER_DEPRECATED); } return true; @@ -918,7 +918,7 @@ class Environment if (isset($this->extensions[$class])) { if ($class !== \get_class($this->extensions[$class])) { - @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED); + @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), \E_USER_DEPRECATED); } return $this->extensions[$class]; @@ -965,7 +965,7 @@ class Environment if ($class !== $extension->getName()) { if (isset($this->extensions[$extension->getName()])) { unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]); - @trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), E_USER_DEPRECATED); + @trigger_error(sprintf('The possibility to register the same extension twice ("%s") is deprecated since version 1.23 and will be removed in Twig 2.0. Use proper PHP inheritance instead.', $extension->getName()), \E_USER_DEPRECATED); } } @@ -986,7 +986,7 @@ class Environment */ public function removeExtension($name) { - @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method is deprecated since version 1.12 and will be removed in Twig 2.0.', __METHOD__), \E_USER_DEPRECATED); if ($this->extensionInitialized) { throw new \LogicException(sprintf('Unable to remove extension "%s" as extensions have already been initialized.', $name)); @@ -1001,7 +1001,7 @@ class Environment if (isset($this->extensions[$class])) { if ($class !== \get_class($this->extensions[$class])) { - @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), E_USER_DEPRECATED); + @trigger_error(sprintf('Referencing the "%s" extension by its name (defined by getName()) is deprecated since 1.26 and will be removed in Twig 2.0. Use the Fully Qualified Extension Class Name instead.', $class), \E_USER_DEPRECATED); } unset($this->extensions[$class]); @@ -1120,7 +1120,7 @@ class Environment $filter = $name; $name = $filter->getName(); } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFilter" instead when defining filter "%s".', __METHOD__, $name), \E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1215,7 +1215,7 @@ class Environment $test = $name; $name = $test->getName(); } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleTest" instead when defining test "%s".', __METHOD__, $name), \E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1292,7 +1292,7 @@ class Environment $function = $name; $name = $function->getName(); } else { - @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Passing a name as a first argument to the %s method is deprecated since version 1.21. Pass an instance of "Twig_SimpleFunction" instead when defining function "%s".', __METHOD__, $name), \E_USER_DEPRECATED); } if ($this->extensionInitialized) { @@ -1389,7 +1389,7 @@ class Environment if (!\array_key_exists($name, $this->globals)) { // The deprecation notice must be turned into the following exception in Twig 2.0 - @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Registering global variable "%s" at runtime or when the extensions have already been initialized is deprecated since version 1.21.', $name), \E_USER_DEPRECATED); //throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); } } @@ -1479,7 +1479,7 @@ class Environment */ public function computeAlternatives($name, $items) { - @trigger_error(sprintf('The %s method is deprecated since version 1.23 and will be removed in Twig 2.0.', __METHOD__), E_USER_DEPRECATED); + @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 SyntaxError::computeAlternatives($name, $items); } @@ -1496,7 +1496,7 @@ class Environment $parentClass = $m->getDeclaringClass()->getName(); if ('Twig_Extension' !== $parentClass && 'Twig\Extension\AbstractExtension' !== $parentClass) { - @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); } } @@ -1548,7 +1548,7 @@ class Environment 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); + @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); } $this->filters[$name] = $filter; @@ -1559,7 +1559,7 @@ class Environment 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); + @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); } $this->functions[$name] = $function; @@ -1570,7 +1570,7 @@ class Environment 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); + @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); } $this->tests[$name] = $test; @@ -1581,7 +1581,7 @@ class Environment 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); + @trigger_error('Registering a \Twig_TokenParserBrokerInterface instance is deprecated since version 1.21.', \E_USER_DEPRECATED); $this->parsers->addTokenParserBroker($parser); } else { @@ -1623,8 +1623,8 @@ class Environment array_keys($this->extensions), [ (int) \function_exists('twig_template_get_attributes'), - PHP_MAJOR_VERSION, - PHP_MINOR_VERSION, + \PHP_MAJOR_VERSION, + \PHP_MINOR_VERSION, self::VERSION, (int) $this->debug, $this->baseTemplateClass, diff --git a/src/Error/Error.php b/src/Error/Error.php index 9b7bb0b9f..3b781ffc1 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -96,7 +96,7 @@ class Error extends \Exception */ public function getTemplateFile() { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->filename; } @@ -110,7 +110,7 @@ class Error extends \Exception */ public function setTemplateFile($name) { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); $this->filename = $name; @@ -126,7 +126,7 @@ class Error extends \Exception */ public function getTemplateName() { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->filename; } @@ -140,7 +140,7 @@ class Error extends \Exception */ public function setTemplateName($name) { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.29 and will be removed in 2.0. Use setSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); $this->filename = $name; $this->sourceCode = $this->sourcePath = null; @@ -264,7 +264,7 @@ class Error extends \Exception $template = null; $templateClass = null; - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); + $backtrace = debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS | \DEBUG_BACKTRACE_PROVIDE_OBJECT); foreach ($backtrace as $trace) { if (isset($trace['object']) && $trace['object'] instanceof Template && 'Twig_Template' !== \get_class($trace['object'])) { $currentClass = \get_class($trace['object']); diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index fa480a07c..83d88020a 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -43,8 +43,8 @@ use Twig\Node\Node; */ class ExpressionParser { - const OPERATOR_LEFT = 1; - const OPERATOR_RIGHT = 2; + public const OPERATOR_LEFT = 1; + public const OPERATOR_RIGHT = 2; protected $parser; protected $unaryOperators; @@ -61,7 +61,7 @@ class ExpressionParser $this->unaryOperators = $env->getUnaryOperators(); $this->binaryOperators = $env->getBinaryOperators(); } else { - @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', E_USER_DEPRECATED); + @trigger_error('Passing the operators as constructor arguments to '.__METHOD__.' is deprecated since version 1.27. Pass the environment instead.', \E_USER_DEPRECATED); $this->env = $parser->getEnvironment(); $this->unaryOperators = func_get_arg(1); @@ -632,7 +632,7 @@ class ExpressionParser $value = $this->parsePrimaryExpression(); if (!$this->checkConstantExpression($value)) { - 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()); + throw new SyntaxError('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(0, $allowArrow); @@ -758,7 +758,7 @@ class ExpressionParser $src = $stream->getSourceContext(); $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $stream->getCurrent()->getLine()); - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } if ($test instanceof TwigTest) { @@ -788,7 +788,7 @@ class ExpressionParser $src = $this->parser->getStream()->getSourceContext(); $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } if ($function instanceof TwigFunction) { @@ -818,7 +818,7 @@ class ExpressionParser $src = $this->parser->getStream()->getSourceContext(); $message .= sprintf(' in %s at line %d.', $src->getPath() ?: $src->getName(), $line); - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); } if ($filter instanceof TwigFilter) { diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 577e98460..08ddf261b 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -492,6 +492,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null) if (null === $date) { $date = 'now'; } + return new \DateTime($date, false !== $timezone ? $timezone : $env->getExtension('\Twig\Extension\CoreExtension')->getTimezone()); } @@ -521,7 +522,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null) function twig_replace_filter($str, $from, $to = null) { if (\is_string($from) && \is_string($to)) { - @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', E_USER_DEPRECATED); + @trigger_error('Using "replace" with character by character replacement is deprecated since version 1.22 and will be removed in Twig 2.0', \E_USER_DEPRECATED); return strtr($str, $from, $to); } @@ -598,7 +599,7 @@ function twig_urlencode_filter($url) { if (\is_array($url)) { if (\defined('PHP_QUERY_RFC3986')) { - return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + return http_build_query($url, '', '&', \PHP_QUERY_RFC3986); } return http_build_query($url, '', '&'); @@ -1069,18 +1070,18 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char ]; if (isset($htmlspecialcharsCharsets[$charset])) { - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + return htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, $charset); } if (isset($htmlspecialcharsCharsets[strtoupper($charset)])) { // cache the lowercase variant for future iterations $htmlspecialcharsCharsets[$charset] = true; - return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, $charset); + return htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, $charset); } $string = twig_convert_encoding($string, 'UTF-8', $charset); - $string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); + $string = htmlspecialchars($string, \ENT_QUOTES | \ENT_SUBSTITUTE, 'UTF-8'); return twig_convert_encoding($string, $charset, 'UTF-8'); @@ -1384,7 +1385,7 @@ if (\function_exists('mb_get_info')) { function twig_title_string_filter(Environment $env, $string) { if (null !== $charset = $env->getCharset()) { - return mb_convert_case($string, MB_CASE_TITLE, $charset); + return mb_convert_case($string, \MB_CASE_TITLE, $charset); } return ucwords(strtolower($string)); diff --git a/src/Extension/EscaperExtension.php b/src/Extension/EscaperExtension.php index fc7f6dfee..fc3e30b59 100644 --- a/src/Extension/EscaperExtension.php +++ b/src/Extension/EscaperExtension.php @@ -60,13 +60,13 @@ class EscaperExtension extends AbstractExtension { // for BC if (true === $defaultStrategy) { - @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', E_USER_DEPRECATED); + @trigger_error('Using "true" as the default strategy is deprecated since version 1.21. Use "html" instead.', \E_USER_DEPRECATED); $defaultStrategy = 'html'; } if ('filename' === $defaultStrategy) { - @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', E_USER_DEPRECATED); + @trigger_error('Using "filename" as the default strategy is deprecated since version 1.27. Use "name" instead.', \E_USER_DEPRECATED); $defaultStrategy = 'name'; } diff --git a/src/Extension/StagingExtension.php b/src/Extension/StagingExtension.php index 049c5c797..a60ea2174 100644 --- a/src/Extension/StagingExtension.php +++ b/src/Extension/StagingExtension.php @@ -35,7 +35,7 @@ class StagingExtension extends AbstractExtension public function addFunction($name, $function) { if (isset($this->functions[$name])) { - @trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding function "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), \E_USER_DEPRECATED); } $this->functions[$name] = $function; @@ -49,7 +49,7 @@ class StagingExtension extends AbstractExtension public function addFilter($name, $filter) { if (isset($this->filters[$name])) { - @trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding filter "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), \E_USER_DEPRECATED); } $this->filters[$name] = $filter; @@ -73,7 +73,7 @@ class StagingExtension extends AbstractExtension 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); + @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); } $this->tokenParsers[$parser->getTag()] = $parser; @@ -97,7 +97,7 @@ class StagingExtension extends AbstractExtension public function addTest($name, $test) { if (isset($this->tests[$name])) { - @trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Overriding test "%s" that is already registered is deprecated since version 1.30 and won\'t be possible anymore in 2.0.', $name), \E_USER_DEPRECATED); } $this->tests[$name] = $test; diff --git a/src/FileExtensionEscapingStrategy.php b/src/FileExtensionEscapingStrategy.php index bc95f3343..d79106c31 100644 --- a/src/FileExtensionEscapingStrategy.php +++ b/src/FileExtensionEscapingStrategy.php @@ -41,7 +41,7 @@ class FileExtensionEscapingStrategy $name = substr($name, 0, -5); } - $extension = pathinfo($name, PATHINFO_EXTENSION); + $extension = pathinfo($name, \PATHINFO_EXTENSION); switch ($extension) { case 'js': diff --git a/src/Lexer.php b/src/Lexer.php index 67d94ab92..cf13d4991 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -40,18 +40,18 @@ class Lexer implements \Twig_LexerInterface private $source; - const STATE_DATA = 0; - const STATE_BLOCK = 1; - const STATE_VAR = 2; - const STATE_STRING = 3; - const STATE_INTERPOLATION = 4; + public const STATE_DATA = 0; + public const STATE_BLOCK = 1; + public const STATE_VAR = 2; + public const STATE_STRING = 3; + public const STATE_INTERPOLATION = 4; - const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; - const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; - const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; - const REGEX_DQ_STRING_DELIM = '/"/A'; - const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; - const PUNCTUATION = '()[]{}?:.,|'; + public const REGEX_NAME = '/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/A'; + public const REGEX_NUMBER = '/[0-9]+(?:\.[0-9]+)?([Ee][\+\-][0-9]+)?/A'; + public const REGEX_STRING = '/"([^#"\\\\]*(?:\\\\.[^#"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\'/As'; + public const REGEX_DQ_STRING_DELIM = '/"/A'; + public const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; + public const PUNCTUATION = '()[]{}?:.,|'; public function __construct(Environment $env, array $options = []) { @@ -163,14 +163,14 @@ class Lexer implements \Twig_LexerInterface public function tokenize($code, $name = null) { 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); + @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 Source($code, $name); } else { $this->source = $code; } if (((int) ini_get('mbstring.func_overload')) & 2) { - @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('Support for having "mbstring.func_overload" different from 0 is deprecated version 1.29 and will be removed in 2.0.', \E_USER_DEPRECATED); } if (\function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { @@ -192,7 +192,7 @@ class Lexer implements \Twig_LexerInterface $this->position = -1; // find all token starts in one go - preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, PREG_OFFSET_CAPTURE); + preg_match_all($this->regexes['lex_tokens_start'], $this->code, $matches, \PREG_OFFSET_CAPTURE); $this->positions = $matches; while ($this->cursor < $this->end) { @@ -351,7 +351,7 @@ class Lexer implements \Twig_LexerInterface // numbers elseif (preg_match(self::REGEX_NUMBER, $this->code, $match, 0, $this->cursor)) { $number = (float) $match[0]; // floats - if (ctype_digit($match[0]) && $number <= PHP_INT_MAX) { + if (ctype_digit($match[0]) && $number <= \PHP_INT_MAX) { $number = (int) $match[0]; // integers lower than the maximum } $this->pushToken(Token::NUMBER_TYPE, $number); @@ -398,10 +398,10 @@ class Lexer implements \Twig_LexerInterface protected function lexRawData($tag) { if ('raw' === $tag) { - @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), E_USER_DEPRECATED); + @trigger_error(sprintf('Twig Tag "raw" is deprecated since version 1.21. Use "verbatim" instead in %s at line %d.', $this->filename, $this->lineno), \E_USER_DEPRECATED); } - if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + if (!preg_match(str_replace('%s', $tag, $this->regexes['lex_raw_data']), $this->code, $match, \PREG_OFFSET_CAPTURE, $this->cursor)) { throw new SyntaxError(sprintf('Unexpected end of file: Unclosed "%s" block.', $tag), $this->lineno, $this->source); } @@ -425,7 +425,7 @@ class Lexer implements \Twig_LexerInterface protected function lexComment() { - if (!preg_match($this->regexes['lex_comment'], $this->code, $match, PREG_OFFSET_CAPTURE, $this->cursor)) { + if (!preg_match($this->regexes['lex_comment'], $this->code, $match, \PREG_OFFSET_CAPTURE, $this->cursor)) { throw new SyntaxError('Unclosed comment.', $this->lineno, $this->source); } diff --git a/src/Loader/ArrayLoader.php b/src/Loader/ArrayLoader.php index e2c7b33c2..5f2a1afa8 100644 --- a/src/Loader/ArrayLoader.php +++ b/src/Loader/ArrayLoader.php @@ -53,7 +53,7 @@ class ArrayLoader implements LoaderInterface, ExistsLoaderInterface, SourceConte public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); $name = (string) $name; if (!isset($this->templates[$name])) { diff --git a/src/Loader/ChainLoader.php b/src/Loader/ChainLoader.php index d1c086700..1df226c6d 100644 --- a/src/Loader/ChainLoader.php +++ b/src/Loader/ChainLoader.php @@ -52,7 +52,7 @@ class ChainLoader implements LoaderInterface, ExistsLoaderInterface, SourceConte public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); $exceptions = []; foreach ($this->loaders as $loader) { diff --git a/src/Loader/FilesystemLoader.php b/src/Loader/FilesystemLoader.php index a27a133c0..18115d885 100644 --- a/src/Loader/FilesystemLoader.php +++ b/src/Loader/FilesystemLoader.php @@ -22,7 +22,7 @@ use Twig\Source; class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, SourceContextLoaderInterface { /** Identifier of the main namespace. */ - const MAIN_NAMESPACE = '__main__'; + public const MAIN_NAMESPACE = '__main__'; protected $paths = []; protected $cache = []; @@ -37,7 +37,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source public function __construct($paths = [], $rootPath = null) { $this->rootPath = (null === $rootPath ? getcwd() : $rootPath).\DIRECTORY_SEPARATOR; - if ($rootPath !== null && false !== ($realPath = realpath($rootPath))) { + if (null !== $rootPath && false !== ($realPath = realpath($rootPath))) { $this->rootPath = $realPath.\DIRECTORY_SEPARATOR; } @@ -138,7 +138,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', static::class), \E_USER_DEPRECATED); if (null === ($path = $this->findTemplate($name)) || false === $path) { return ''; @@ -180,7 +180,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source try { return null !== ($path = $this->findTemplate($name, false)) && false !== $path; } catch (LoaderError $e) { - @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.', static::class), E_USER_DEPRECATED); + @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.', static::class), \E_USER_DEPRECATED); return false; } @@ -319,7 +319,7 @@ class FilesystemLoader implements LoaderInterface, ExistsLoaderInterface, Source && ':' === substr($file, 1, 1) && strspn($file, '/\\', 2, 1) ) - || null !== parse_url($file, PHP_URL_SCHEME) + || null !== parse_url($file, \PHP_URL_SCHEME) ; } } diff --git a/src/Node/Expression/BlockReferenceExpression.php b/src/Node/Expression/BlockReferenceExpression.php index 7e3c3e484..309da5894 100644 --- a/src/Node/Expression/BlockReferenceExpression.php +++ b/src/Node/Expression/BlockReferenceExpression.php @@ -28,7 +28,7 @@ class BlockReferenceExpression extends AbstractExpression public function __construct(\Twig_NodeInterface $name, $template, $lineno, $tag = null) { if (\is_bool($template)) { - @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s method "$asString" argument is deprecated since version 1.28 and will be removed in 2.0.', __METHOD__), \E_USER_DEPRECATED); $template = null; } diff --git a/src/Node/Expression/GetAttrExpression.php b/src/Node/Expression/GetAttrExpression.php index 06511c773..b8855f48a 100644 --- a/src/Node/Expression/GetAttrExpression.php +++ b/src/Node/Expression/GetAttrExpression.php @@ -30,7 +30,7 @@ class GetAttrExpression extends AbstractExpression 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); + @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); } if (\function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { diff --git a/src/Node/MacroNode.php b/src/Node/MacroNode.php index 6eb67955f..50b0a8d9f 100644 --- a/src/Node/MacroNode.php +++ b/src/Node/MacroNode.php @@ -21,7 +21,7 @@ use Twig\Error\SyntaxError; */ class MacroNode extends Node { - const VARARGS_NAME = 'varargs'; + public const VARARGS_NAME = 'varargs'; public function __construct($name, \Twig_NodeInterface $body, \Twig_NodeInterface $arguments, $lineno, $tag = null) { diff --git a/src/Node/ModuleNode.php b/src/Node/ModuleNode.php index 89d602b97..325b92569 100644 --- a/src/Node/ModuleNode.php +++ b/src/Node/ModuleNode.php @@ -31,7 +31,7 @@ class ModuleNode extends Node public function __construct(\Twig_NodeInterface $body, ?AbstractExpression $parent, \Twig_NodeInterface $blocks, \Twig_NodeInterface $macros, \Twig_NodeInterface $traits, $embeddedTemplates, $name, $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); + @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); $source = new Source($source, $name); } else { $source = $name; diff --git a/src/Node/Node.php b/src/Node/Node.php index 7ad3d6890..68e0fd3e6 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -40,7 +40,7 @@ class Node implements \Twig_NodeInterface { foreach ($nodes as $name => $node) { if (!$node instanceof \Twig_NodeInterface) { - @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), \E_USER_DEPRECATED); } } $this->nodes = $nodes; @@ -82,7 +82,7 @@ class Node implements \Twig_NodeInterface */ public function toXml($asDom = false) { - @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('%s is deprecated since version 1.16.1 and will be removed in 2.0.', __METHOD__), \E_USER_DEPRECATED); $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; @@ -129,7 +129,7 @@ class Node implements \Twig_NodeInterface */ public function getLine() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateLine() instead.', \E_USER_DEPRECATED); return $this->lineno; } @@ -196,7 +196,7 @@ class Node implements \Twig_NodeInterface public function setNode($name, $node = null) { if (!$node instanceof \Twig_NodeInterface) { - @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), E_USER_DEPRECATED); + @trigger_error(sprintf('Using "%s" for the value of node "%s" of "%s" is deprecated since version 1.25 and will be removed in 2.0.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class), \E_USER_DEPRECATED); } $this->nodes[$name] = $node; @@ -258,7 +258,7 @@ class Node implements \Twig_NodeInterface */ public function setFilename($name) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use setTemplateName() instead.', \E_USER_DEPRECATED); $this->setTemplateName($name); } @@ -268,7 +268,7 @@ class Node implements \Twig_NodeInterface */ public function getFilename() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getTemplateName() instead.', \E_USER_DEPRECATED); return $this->name; } diff --git a/src/NodeVisitor/OptimizerNodeVisitor.php b/src/NodeVisitor/OptimizerNodeVisitor.php index e5ea9b7cc..2af5d454d 100644 --- a/src/NodeVisitor/OptimizerNodeVisitor.php +++ b/src/NodeVisitor/OptimizerNodeVisitor.php @@ -43,11 +43,11 @@ use Twig\Node\SetTempNode; */ class OptimizerNodeVisitor extends AbstractNodeVisitor { - const OPTIMIZE_ALL = -1; - const OPTIMIZE_NONE = 0; - const OPTIMIZE_FOR = 2; - const OPTIMIZE_RAW_FILTER = 4; - const OPTIMIZE_VAR_ACCESS = 8; + public const OPTIMIZE_ALL = -1; + public const OPTIMIZE_NONE = 0; + public const OPTIMIZE_FOR = 2; + public const OPTIMIZE_RAW_FILTER = 4; + public const OPTIMIZE_VAR_ACCESS = 8; protected $loops = []; protected $loopsTargets = []; diff --git a/src/Parser.php b/src/Parser.php index 9fb6a83a4..8763a4eb3 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -60,7 +60,7 @@ class Parser implements \Twig_ParserInterface */ public function getEnvironment() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', \E_USER_DEPRECATED); return $this->env; } @@ -75,7 +75,7 @@ class Parser implements \Twig_ParserInterface */ public function getFilename() { - @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The "%s" method is deprecated since version 1.27 and will be removed in 2.0. Use $parser->getStream()->getSourceContext()->getPath() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->stream->getSourceContext()->getName(); } @@ -229,7 +229,7 @@ class Parser implements \Twig_ParserInterface */ public function addHandler($name, $class) { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', \E_USER_DEPRECATED); $this->handlers[$name] = $class; } @@ -239,7 +239,7 @@ class Parser implements \Twig_ParserInterface */ 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); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0.', \E_USER_DEPRECATED); $this->visitors[] = $visitor; } diff --git a/src/Profiler/Profile.php b/src/Profiler/Profile.php index 48f62950e..60ae02eef 100644 --- a/src/Profiler/Profile.php +++ b/src/Profiler/Profile.php @@ -18,10 +18,10 @@ namespace Twig\Profiler; */ class Profile implements \IteratorAggregate, \Serializable { - const ROOT = 'ROOT'; - const BLOCK = 'block'; - const TEMPLATE = 'template'; - const MACRO = 'macro'; + public const ROOT = 'ROOT'; + public const BLOCK = 'block'; + public const TEMPLATE = 'template'; + public const MACRO = 'macro'; private $template; private $name; diff --git a/src/Template.php b/src/Template.php index 032efe326..876d1ca61 100644 --- a/src/Template.php +++ b/src/Template.php @@ -80,7 +80,7 @@ abstract class Template implements \Twig_TemplateInterface */ public function getSource() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', \E_USER_DEPRECATED); return ''; } @@ -100,7 +100,7 @@ abstract class Template implements \Twig_TemplateInterface */ public function getEnvironment() { - @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is deprecated since version 1.20 and will be removed in 2.0.', \E_USER_DEPRECATED); return $this->env; } @@ -233,7 +233,7 @@ abstract class Template implements \Twig_TemplateInterface } elseif (false !== $parent = $this->getParent($context)) { $parent->displayBlock($name, $context, array_merge($this->blocks, $blocks), false); } else { - @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), E_USER_DEPRECATED); + @trigger_error(sprintf('Silent display of undefined block "%s" in template "%s" is deprecated since version 1.29 and will throw an exception in 2.0. Use the "block(\'%s\') is defined" expression to test for block existence.', $name, $this->getTemplateName(), $name), \E_USER_DEPRECATED); } } @@ -301,7 +301,7 @@ abstract class Template implements \Twig_TemplateInterface public function hasBlock($name, array $context = null, array $blocks = []) { if (null === $context) { - @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', \E_USER_DEPRECATED); return isset($this->blocks[(string) $name]); } @@ -335,7 +335,7 @@ abstract class Template implements \Twig_TemplateInterface public function getBlockNames(array $context = null, array $blocks = []) { if (null === $context) { - @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', E_USER_DEPRECATED); + @trigger_error('The '.__METHOD__.' method is internal and should never be called; calling it directly is deprecated since version 1.28 and won\'t be possible anymore in 2.0.', \E_USER_DEPRECATED); return array_keys($this->blocks); } @@ -719,7 +719,7 @@ abstract class Template implements \Twig_TemplateInterface } elseif ('render' === $method || 'display' === $method) { $message .= sprintf(' Use include("%s") instead).', $object->getTemplateName()); } - @trigger_error($message, E_USER_DEPRECATED); + @trigger_error($message, \E_USER_DEPRECATED); return '' === $ret ? '' : new Markup($ret, $this->env->getCharset()); } diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index 905f9725e..c968364fe 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -120,7 +120,7 @@ abstract class IntegrationTestCase extends TestCase $condition = $match[2]; $templates = self::parseTemplates($match[3]); $exception = false; - preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, PREG_SET_ORDER); + preg_match_all('/--DATA--(.*?)(?:--CONFIG--(.*?))?--EXPECT--(.*?)(?=\-\-DATA\-\-|$)/s', $test, $outputs, \PREG_SET_ORDER); } else { throw new \InvalidArgumentException(sprintf('Test "%s" is not valid.', str_replace($fixturesDir.'/', '', $file))); } @@ -245,7 +245,7 @@ abstract class IntegrationTestCase extends TestCase protected static function parseTemplates($test) { $templates = []; - preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, PREG_SET_ORDER); + preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER); foreach ($matches as $match) { $templates[($match[1] ?: 'index.twig')] = $match[2]; } diff --git a/src/Token.php b/src/Token.php index a0bb11af1..4c49a1de6 100644 --- a/src/Token.php +++ b/src/Token.php @@ -25,20 +25,20 @@ class Token protected $type; protected $lineno; - const EOF_TYPE = -1; - const TEXT_TYPE = 0; - const BLOCK_START_TYPE = 1; - const VAR_START_TYPE = 2; - const BLOCK_END_TYPE = 3; - const VAR_END_TYPE = 4; - const NAME_TYPE = 5; - const NUMBER_TYPE = 6; - const STRING_TYPE = 7; - const OPERATOR_TYPE = 8; - const PUNCTUATION_TYPE = 9; - const INTERPOLATION_START_TYPE = 10; - const INTERPOLATION_END_TYPE = 11; - const ARROW_TYPE = 12; + public const EOF_TYPE = -1; + public const TEXT_TYPE = 0; + public const BLOCK_START_TYPE = 1; + public const VAR_START_TYPE = 2; + public const BLOCK_END_TYPE = 3; + public const VAR_END_TYPE = 4; + public const NAME_TYPE = 5; + public const NUMBER_TYPE = 6; + public const STRING_TYPE = 7; + public const OPERATOR_TYPE = 8; + public const PUNCTUATION_TYPE = 9; + public const INTERPOLATION_START_TYPE = 10; + public const INTERPOLATION_END_TYPE = 11; + public const ARROW_TYPE = 12; /** * @param int $type The type of the token diff --git a/src/TokenParser/AutoEscapeTokenParser.php b/src/TokenParser/AutoEscapeTokenParser.php index 2cd0cc69d..6dda37b54 100644 --- a/src/TokenParser/AutoEscapeTokenParser.php +++ b/src/TokenParser/AutoEscapeTokenParser.php @@ -57,7 +57,7 @@ class AutoEscapeTokenParser extends AbstractTokenParser } 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); + @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 SyntaxError('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); diff --git a/src/TokenStream.php b/src/TokenStream.php index 459781695..d4a4846a4 100644 --- a/src/TokenStream.php +++ b/src/TokenStream.php @@ -38,7 +38,7 @@ class TokenStream { 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); + @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 Source($source, $name); } else { @@ -164,7 +164,7 @@ class TokenStream */ public function getFilename() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->source->getName(); } @@ -180,7 +180,7 @@ class TokenStream */ public function getSource() { - @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), E_USER_DEPRECATED); + @trigger_error(sprintf('The %s() method is deprecated since version 1.27 and will be removed in 2.0. Use getSourceContext() instead.', __METHOD__), \E_USER_DEPRECATED); return $this->source->getCode(); } diff --git a/src/Util/DeprecationCollector.php b/src/Util/DeprecationCollector.php index 09917e927..4a8ff53e1 100644 --- a/src/Util/DeprecationCollector.php +++ b/src/Util/DeprecationCollector.php @@ -83,7 +83,7 @@ class DeprecationCollector */ public function errorHandler($type, $msg) { - if (E_USER_DEPRECATED === $type) { + if (\E_USER_DEPRECATED === $type) { $this->deprecations[] = $msg; } } diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index cc462c251..28bde27d2 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -20,19 +20,19 @@ class CompilerTest extends \PHPUnit\Framework\TestCase { $compiler = new Compiler(new Environment($this->createMock('\Twig\Loader\LoaderInterface'))); - $locale = setlocale(LC_NUMERIC, 0); + $locale = setlocale(\LC_NUMERIC, 0); if (false === $locale) { $this->markTestSkipped('Your platform does not support locales.'); } $required_locales = ['fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252']; - if (false === setlocale(LC_NUMERIC, $required_locales)) { + if (false === setlocale(\LC_NUMERIC, $required_locales)) { $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $required_locales)); } $this->assertEquals('1.2', $compiler->repr(1.2)->getSource()); - $this->assertStringContainsString('fr', strtolower(setlocale(LC_NUMERIC, 0))); + $this->assertStringContainsString('fr', strtolower(setlocale(\LC_NUMERIC, 0))); - setlocale(LC_NUMERIC, $locale); + setlocale(\LC_NUMERIC, $locale); } } diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index 54a894506..161ab3d1d 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -448,7 +448,7 @@ EOF public function handleError($type, $msg) { - if (E_USER_DEPRECATED === $type) { + if (\E_USER_DEPRECATED === $type) { $this->deprecations[] = $msg; } } diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index 8019f053b..b0f1ce529 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -291,14 +291,14 @@ EOHTML public function testTwigLeakOutputInDebugMode() { - $output = exec(sprintf('%s %s debug', PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php'))); + $output = exec(sprintf('%s %s debug', \PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php'))); $this->assertSame('Hello OOPS', $output); } public function testDoesNotTwigLeakOutput() { - $output = exec(sprintf('%s %s', PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php'))); + $output = exec(sprintf('%s %s', \PHP_BINARY, escapeshellarg(__DIR__.'/Fixtures/errors/leak-output.php'))); $this->assertSame('', $output); } diff --git a/tests/Extension/StringLoaderExtensionTest.php b/tests/Extension/StringLoaderExtensionTest.php index c4b28591c..363a0825e 100644 --- a/tests/Extension/StringLoaderExtensionTest.php +++ b/tests/Extension/StringLoaderExtensionTest.php @@ -11,8 +11,8 @@ namespace Twig\Tests\Extension; -use Twig\Environment; use PHPUnit\Framework\TestCase; +use Twig\Environment; use Twig\Extension\StringLoaderExtension; class StringLoaderExtensionTest extends TestCase @@ -21,6 +21,6 @@ class StringLoaderExtensionTest extends TestCase { $twig = new Environment($this->createMock('\Twig\Loader\LoaderInterface')); $twig->addExtension(new StringLoaderExtension()); - $this->assertSame('something', twig_include($twig, [], twig_template_from_string($twig, "something"))); + $this->assertSame('something', twig_include($twig, [], twig_template_from_string($twig, 'something'))); } } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index a8d716c04..525cbfeb1 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -59,7 +59,7 @@ function test_foo($value = 'foo') class TwigTestFoo implements \Iterator { - const BAR_NAME = 'bar'; + public const BAR_NAME = 'bar'; public $position = 0; public $array = [1, 2];