diff --git a/extra/cache-extra/Node/CacheNode.php b/extra/cache-extra/Node/CacheNode.php index 4600fa657..f79873aa9 100644 --- a/extra/cache-extra/Node/CacheNode.php +++ b/extra/cache-extra/Node/CacheNode.php @@ -42,7 +42,7 @@ class CacheNode extends Node if ($this->hasNode('tags')) { $compiler - ->write("\$item->tag(") + ->write('$item->tag(') ->subcompile($this->getNode('tags')) ->raw(");\n") ; diff --git a/extra/cache-extra/Tests/FunctionalTest.php b/extra/cache-extra/Tests/FunctionalTest.php index 13730c07b..ae8bd71f0 100644 --- a/extra/cache-extra/Tests/FunctionalTest.php +++ b/extra/cache-extra/Tests/FunctionalTest.php @@ -78,7 +78,8 @@ class FunctionalTest extends TestCase $this->cache = $cache; } - public function load($class) { + public function load($class) + { if (CacheRuntime::class === $class) { return new CacheRuntime($this->cache); } diff --git a/extra/cache-extra/Tests/IntegrationTest.php b/extra/cache-extra/Tests/IntegrationTest.php index 86e847f59..8e216aaa5 100644 --- a/extra/cache-extra/Tests/IntegrationTest.php +++ b/extra/cache-extra/Tests/IntegrationTest.php @@ -29,8 +29,9 @@ class IntegrationTest extends IntegrationTestCase protected function getRuntimeLoaders() { return [ - new class implements RuntimeLoaderInterface { - public function load($class) { + new class() implements RuntimeLoaderInterface { + public function load($class) + { if (CacheRuntime::class === $class) { return new CacheRuntime(new ArrayAdapter()); } diff --git a/extra/cache-extra/TokenParser/CacheTokenParser.php b/extra/cache-extra/TokenParser/CacheTokenParser.php index b986f91fa..953e44241 100644 --- a/extra/cache-extra/TokenParser/CacheTokenParser.php +++ b/extra/cache-extra/TokenParser/CacheTokenParser.php @@ -34,14 +34,14 @@ class CacheTokenParser extends AbstractTokenParser switch ($k) { case 'ttl': - if (1 !== count($args)) { - throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + if (1 !== \count($args)) { + throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $ttl = $args->getNode(0); break; case 'tags': - if (1 !== count($args)) { - throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext()); + if (1 !== \count($args)) { + throw new SyntaxError(sprintf('The "ttl" modifier takes exactly one argument (%d given).', \count($args)), $stream->getCurrent()->getLine(), $stream->getSourceContext()); } $tags = $args->getNode(0); break; diff --git a/extra/twig-extra-bundle/Resources/config/cache.php b/extra/twig-extra-bundle/Resources/config/cache.php index 6ea0cc11a..c6ed9d393 100644 --- a/extra/twig-extra-bundle/Resources/config/cache.php +++ b/extra/twig-extra-bundle/Resources/config/cache.php @@ -19,7 +19,7 @@ use Twig\Extra\Cache\CacheExtension; use Twig\Extra\Cache\CacheRuntime; return static function (ContainerConfigurator $container) { - $service = function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service') ? 'Symfony\Component\DependencyInjection\Loader\Configurator\service' : 'Symfony\Component\DependencyInjection\Loader\Configurator\ref'; + $service = \function_exists('Symfony\Component\DependencyInjection\Loader\Configurator\service') ? 'Symfony\Component\DependencyInjection\Loader\Configurator\service' : 'Symfony\Component\DependencyInjection\Loader\Configurator\ref'; $container->services() ->set('twig.extension.cache', CacheExtension::class) ->tag('twig.extension') @@ -32,7 +32,7 @@ return static function (ContainerConfigurator $container) { ->set('twig.cache', TagAwareAdapter::class) ->args([ - $service('.twig.cache.inner') + $service('.twig.cache.inner'), ]) ->set('.twig.cache.inner') diff --git a/src/Environment.php b/src/Environment.php index 86da03abf..abeabe320 100644 --- a/src/Environment.php +++ b/src/Environment.php @@ -38,12 +38,12 @@ use Twig\TokenParser\TokenParserInterface; */ class Environment { - const VERSION = '3.3.1-DEV'; - const VERSION_ID = 30301; - const MAJOR_VERSION = 3; - const MINOR_VERSION = 3; - const RELEASE_VERSION = 1; - const EXTRA_VERSION = 'DEV'; + public const VERSION = '3.3.1-DEV'; + public const VERSION_ID = 30301; + public const MAJOR_VERSION = 3; + public const MINOR_VERSION = 3; + public const RELEASE_VERSION = 1; + public const EXTRA_VERSION = 'DEV'; private $charset; private $loader; @@ -235,7 +235,7 @@ class Environment } 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.'); } } @@ -804,8 +804,8 @@ class Environment { $this->optionsHash = implode(':', [ $this->extensionSet->getSignature(), - PHP_MAJOR_VERSION, - PHP_MINOR_VERSION, + \PHP_MAJOR_VERSION, + \PHP_MINOR_VERSION, self::VERSION, (int) $this->debug, (int) $this->strictVariables, diff --git a/src/Error/Error.php b/src/Error/Error.php index 87b8e855c..a68be65f2 100644 --- a/src/Error/Error.php +++ b/src/Error/Error.php @@ -168,7 +168,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) { $currentClass = \get_class($trace['object']); diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 7e9fd7659..f6933d080 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -484,6 +484,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(CoreExtension::class)->getTimezone()); } @@ -582,7 +583,7 @@ function twig_number_format_filter(Environment $env, $number, $decimal = null, $ function twig_urlencode_filter($url) { if (\is_array($url)) { - return http_build_query($url, '', '&', PHP_QUERY_RFC3986); + return http_build_query($url, '', '&', \PHP_QUERY_RFC3986); } return rawurlencode($url); @@ -1108,7 +1109,7 @@ function twig_lower_filter(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); + return mb_convert_case($string, \MB_CASE_TITLE, $charset); } return ucwords(strtolower($string)); diff --git a/src/NodeVisitor/OptimizerNodeVisitor.php b/src/NodeVisitor/OptimizerNodeVisitor.php index c167d2633..7ac75e41a 100644 --- a/src/NodeVisitor/OptimizerNodeVisitor.php +++ b/src/NodeVisitor/OptimizerNodeVisitor.php @@ -39,10 +39,10 @@ use Twig\Node\PrintNode; */ final class OptimizerNodeVisitor implements NodeVisitorInterface { - const OPTIMIZE_ALL = -1; - const OPTIMIZE_NONE = 0; - const OPTIMIZE_FOR = 2; - const OPTIMIZE_RAW_FILTER = 4; + public const OPTIMIZE_ALL = -1; + public const OPTIMIZE_NONE = 0; + public const OPTIMIZE_FOR = 2; + public const OPTIMIZE_RAW_FILTER = 4; private $loops = []; private $loopsTargets = []; diff --git a/src/Profiler/Profile.php b/src/Profiler/Profile.php index ffbe74f69..252ca9b0c 100644 --- a/src/Profiler/Profile.php +++ b/src/Profiler/Profile.php @@ -16,10 +16,10 @@ namespace Twig\Profiler; */ final 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/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index aae0f0f52..438b5d9b2 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -263,10 +263,10 @@ class CoreTest extends TestCase public function testCompareNAN() { - $this->assertSame(1, twig_compare(NAN, 'NAN')); - $this->assertSame(1, twig_compare('NAN', NAN)); - $this->assertSame(1, twig_compare(NAN, 'foo')); - $this->assertSame(1, twig_compare('foo', NAN)); + $this->assertSame(1, twig_compare(\NAN, 'NAN')); + $this->assertSame(1, twig_compare('NAN', \NAN)); + $this->assertSame(1, twig_compare(\NAN, 'foo')); + $this->assertSame(1, twig_compare('foo', \NAN)); } public function provideCompareCases() @@ -312,10 +312,10 @@ class CoreTest extends TestCase [-1, 42.0, 'abc42.0'], [-1, 0.0, 'abc42.0'], - [0, INF, 'INF'], - [0, -INF, '-INF'], - [0, INF, '1e1000'], - [0, -INF, '-1e1000'], + [0, \INF, 'INF'], + [0, -\INF, '-INF'], + [0, \INF, '1e1000'], + [0, -\INF, '-1e1000'], [-1, 10, 20], [-1, '10', 20],