From 98a15a89734ac29a6d6943bfdf3307afbda31bdc Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 15 Feb 2019 06:17:13 +0100 Subject: [PATCH] tweaked PHP-CS-Fixer config --- .php_cs.dist | 1 + lib/Twig/Cache/Filesystem.php | 6 +- lib/Twig/Compiler.php | 10 +- lib/Twig/Environment.php | 52 +++---- lib/Twig/Error.php | 8 +- lib/Twig/Error/Syntax.php | 2 +- lib/Twig/ExpressionParser.php | 24 +-- lib/Twig/Extension.php | 2 +- lib/Twig/Extension/Core.php | 138 +++++++++--------- lib/Twig/Extension/Debug.php | 4 +- lib/Twig/Extension/Escaper.php | 4 +- lib/Twig/Extension/Profiler.php | 4 +- lib/Twig/Extension/Sandbox.php | 2 +- lib/Twig/FileExtensionEscapingStrategy.php | 2 +- lib/Twig/Filter.php | 2 +- lib/Twig/Filter/Method.php | 2 +- lib/Twig/Function.php | 2 +- lib/Twig/Function/Method.php | 2 +- lib/Twig/Lexer.php | 14 +- lib/Twig/Loader/Array.php | 2 +- lib/Twig/Loader/Chain.php | 6 +- lib/Twig/Loader/Filesystem.php | 12 +- lib/Twig/Loader/String.php | 2 +- lib/Twig/Markup.php | 2 +- lib/Twig/Node.php | 26 ++-- lib/Twig/Node/Expression/BlockReference.php | 2 +- lib/Twig/Node/Expression/Call.php | 28 ++-- lib/Twig/Node/Expression/Filter/Default.php | 2 +- lib/Twig/Node/Expression/GetAttr.php | 2 +- lib/Twig/Node/If.php | 2 +- lib/Twig/Node/Macro.php | 2 +- lib/Twig/Node/Module.php | 16 +- lib/Twig/Node/Set.php | 4 +- lib/Twig/NodeVisitor/Escaper.php | 8 +- lib/Twig/NodeVisitor/Optimizer.php | 10 +- lib/Twig/NodeVisitor/SafeAnalysis.php | 8 +- lib/Twig/Parser.php | 18 +-- lib/Twig/Profiler/Dumper/Base.php | 2 +- lib/Twig/Sandbox/SecurityPolicy.php | 16 +- lib/Twig/SimpleFilter.php | 2 +- lib/Twig/SimpleFunction.php | 2 +- lib/Twig/Template.php | 34 ++--- lib/Twig/TemplateWrapper.php | 4 +- lib/Twig/Test/IntegrationTestCase.php | 12 +- lib/Twig/Test/Method.php | 2 +- lib/Twig/Test/NodeTestCase.php | 2 +- lib/Twig/Token.php | 4 +- lib/Twig/TokenParser/For.php | 4 +- lib/Twig/TokenParser/Set.php | 4 +- lib/Twig/TokenStream.php | 2 +- test/Twig/Tests/Cache/FilesystemTest.php | 12 +- test/Twig/Tests/EnvironmentTest.php | 2 +- test/Twig/Tests/Extension/CoreTest.php | 16 +- .../Twig/Tests/Node/Expression/FilterTest.php | 2 +- test/Twig/Tests/Node/ForTest.php | 2 +- test/Twig/Tests/NodeVisitor/OptimizerTest.php | 6 +- test/Twig/Tests/ParserTest.php | 2 +- test/Twig/Tests/TemplateTest.php | 14 +- test/Twig/Tests/escapingTest.php | 24 +-- 59 files changed, 302 insertions(+), 301 deletions(-) diff --git a/.php_cs.dist b/.php_cs.dist index ff8a55dbb..1b31c0a3d 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -11,6 +11,7 @@ return PhpCsFixer\Config::create() 'heredoc_to_nowdoc' => false, 'ordered_imports' => true, 'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'], + 'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'all'], ]) ->setRiskyAllowed(true) ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)) diff --git a/lib/Twig/Cache/Filesystem.php b/lib/Twig/Cache/Filesystem.php index b2704dd6b..73b0220eb 100644 --- a/lib/Twig/Cache/Filesystem.php +++ b/lib/Twig/Cache/Filesystem.php @@ -47,7 +47,7 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface public function write($key, $content) { - $dir = dirname($key); + $dir = \dirname($key); if (!is_dir($dir)) { if (false === @mkdir($dir, 0777, true)) { clearstatcache(true, $dir); @@ -65,9 +65,9 @@ class Twig_Cache_Filesystem implements Twig_CacheInterface if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { // Compile cached file into bytecode cache - if (function_exists('opcache_invalidate')) { + if (\function_exists('opcache_invalidate')) { opcache_invalidate($key, true); - } elseif (function_exists('apc_compile_file')) { + } elseif (\function_exists('apc_compile_file')) { apc_compile_file($key); } } diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index f1f3fab0e..fe4983e3f 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -122,7 +122,7 @@ class Twig_Compiler implements Twig_CompilerInterface */ public function write() { - $strings = func_get_args(); + $strings = \func_get_args(); foreach ($strings as $string) { $this->source .= str_repeat(' ', $this->indentation * 4).$string; } @@ -169,7 +169,7 @@ class Twig_Compiler implements Twig_CompilerInterface */ public function repr($value) { - if (is_int($value) || is_float($value)) { + if (\is_int($value) || \is_float($value)) { if (false !== $locale = setlocale(LC_NUMERIC, '0')) { setlocale(LC_NUMERIC, 'C'); } @@ -181,9 +181,9 @@ class Twig_Compiler implements Twig_CompilerInterface } } elseif (null === $value) { $this->raw('null'); - } elseif (is_bool($value)) { + } elseif (\is_bool($value)) { $this->raw($value ? 'true' : 'false'); - } elseif (is_array($value)) { + } elseif (\is_array($value)) { $this->raw('['); $first = true; foreach ($value as $key => $v) { @@ -224,7 +224,7 @@ class Twig_Compiler implements Twig_CompilerInterface } else { $this->sourceLine += substr_count($this->source, "\n", $this->sourceOffset); } - $this->sourceOffset = strlen($this->source); + $this->sourceOffset = \strlen($this->source); $this->debugInfo[$this->sourceLine] = $node->getTemplateLine(); $this->lastLine = $node->getTemplateLine(); diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 71ac4c106..1730a730d 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -127,7 +127,7 @@ class Twig_Environment $this->staging = new Twig_Extension_Staging(); // For BC - if (is_string($this->originalCache)) { + 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); @@ -270,7 +270,7 @@ class Twig_Environment */ public function setCache($cache) { - if (is_string($cache)) { + if (\is_string($cache)) { $this->originalCache = $cache; $this->cache = new Twig_Cache_Filesystem($cache); } elseif (false === $cache) { @@ -571,7 +571,7 @@ class Twig_Environment */ public function resolveTemplate($names) { - if (!is_array($names)) { + if (!\is_array($names)) { $names = [$names]; } @@ -590,7 +590,7 @@ class Twig_Environment } } - if (1 === count($names)) { + if (1 === \count($names)) { throw $e; } @@ -618,7 +618,7 @@ class Twig_Environment { @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)) { + if (\is_string($this->originalCache)) { foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->originalCache), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) { if ($file->isFile()) { @unlink($file->getPathname()); @@ -779,8 +779,8 @@ class Twig_Environment public function setLoader(Twig_LoaderInterface $loader) { - if (!$loader instanceof Twig_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); + if (!$loader instanceof Twig_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); } $this->loader = $loader; @@ -859,7 +859,7 @@ class Twig_Environment } if (isset($this->extensions[$class])) { - if ($class !== get_class($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); } @@ -894,7 +894,7 @@ class Twig_Environment } if (isset($this->extensions[$class])) { - if ($class !== get_class($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); } @@ -938,7 +938,7 @@ class Twig_Environment throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $extension->getName())); } - $class = get_class($extension); + $class = \get_class($extension); if ($class !== $extension->getName()) { if (isset($this->extensions[$extension->getName()])) { unset($this->extensions[$extension->getName()], $this->extensionsByClass[$class]); @@ -977,7 +977,7 @@ class Twig_Environment } if (isset($this->extensions[$class])) { - if ($class !== get_class($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); } @@ -1143,7 +1143,7 @@ class Twig_Environment } foreach ($this->filterCallbacks as $callback) { - if (false !== $filter = call_user_func($callback, $name)) { + if (false !== $filter = \call_user_func($callback, $name)) { return $filter; } } @@ -1315,7 +1315,7 @@ class Twig_Environment } foreach ($this->functionCallbacks as $callback) { - if (false !== $function = call_user_func($callback, $name)) { + if (false !== $function = \call_user_func($callback, $name)) { return $function; } } @@ -1364,7 +1364,7 @@ class Twig_Environment $this->globals = $this->initGlobals(); } - if (!array_key_exists($name, $this->globals)) { + 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); //throw new \LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name)); @@ -1411,7 +1411,7 @@ class Twig_Environment // we don't use array_merge as the context being generally // bigger than globals, this code is faster. foreach ($this->getGlobals() as $key => $value) { - if (!array_key_exists($key, $context)) { + if (!\array_key_exists($key, $context)) { $context[$key] = $value; } } @@ -1477,8 +1477,8 @@ class Twig_Environment } $extGlob = $extension->getGlobals(); - if (!is_array($extGlob)) { - throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', get_class($extension))); + if (!\is_array($extGlob)) { + throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension))); } $globals[] = $extGlob; @@ -1486,7 +1486,7 @@ class Twig_Environment $globals[] = $this->staging->getGlobals(); - return call_user_func_array('array_merge', $globals); + return \call_user_func_array('array_merge', $globals); } /** @@ -1524,7 +1524,7 @@ class Twig_Environment if ($filter instanceof Twig_SimpleFilter) { $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; @@ -1535,7 +1535,7 @@ class Twig_Environment if ($function instanceof Twig_SimpleFunction) { $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; @@ -1546,7 +1546,7 @@ class Twig_Environment if ($test instanceof Twig_SimpleTest) { $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; @@ -1572,12 +1572,12 @@ class Twig_Environment // operators if ($operators = $extension->getOperators()) { - if (!is_array($operators)) { - throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', get_class($extension), is_object($operators) ? get_class($operators) : gettype($operators).(is_resource($operators) ? '' : '#'.$operators))); + if (!\is_array($operators)) { + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', \get_class($extension), \is_object($operators) ? \get_class($operators) : \gettype($operators).(\is_resource($operators) ? '' : '#'.$operators))); } - if (2 !== count($operators)) { - throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', get_class($extension), count($operators))); + if (2 !== \count($operators)) { + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', \get_class($extension), \count($operators))); } $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); @@ -1598,7 +1598,7 @@ class Twig_Environment $hashParts = array_merge( array_keys($this->extensions), [ - (int) function_exists('twig_template_get_attributes'), + (int) \function_exists('twig_template_get_attributes'), PHP_MAJOR_VERSION, PHP_MINOR_VERSION, self::VERSION, diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index b6a1c6152..467e01948 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -242,7 +242,7 @@ class Twig_Error extends \Exception } if ($this->filename) { - if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) { + if (\is_string($this->filename) || (\is_object($this->filename) && method_exists($this->filename, '__toString'))) { $name = sprintf('"%s"', $this->filename); } else { $name = json_encode($this->filename); @@ -273,12 +273,12 @@ 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'])) { - $currentClass = get_class($trace['object']); + if (isset($trace['object']) && $trace['object'] instanceof Twig_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)) { $template = $trace['object']; - $templateClass = get_class($trace['object']); + $templateClass = \get_class($trace['object']); } } } diff --git a/lib/Twig/Error/Syntax.php b/lib/Twig/Error/Syntax.php index ec06ab61e..3534851c4 100644 --- a/lib/Twig/Error/Syntax.php +++ b/lib/Twig/Error/Syntax.php @@ -42,7 +42,7 @@ class Twig_Error_Syntax extends Twig_Error $alternatives = []; foreach ($items as $item) { $lev = levenshtein($name, $item); - if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) { + if ($lev <= \strlen($name) / 3 || false !== strpos($item, $name)) { $alternatives[$item] = $lev; } } diff --git a/lib/Twig/ExpressionParser.php b/lib/Twig/ExpressionParser.php index df24fc979..cab642156 100644 --- a/lib/Twig/ExpressionParser.php +++ b/lib/Twig/ExpressionParser.php @@ -63,7 +63,7 @@ class Twig_ExpressionParser } elseif ('is' === $token->getValue()) { $expr = $this->parseTestExpression($expr); } elseif (isset($op['callable'])) { - $expr = call_user_func($op['callable'], $this->parser, $expr); + $expr = \call_user_func($op['callable'], $this->parser, $expr); } else { $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']); $class = $op['class']; @@ -188,7 +188,7 @@ class Twig_ExpressionParser $ref = new \ReflectionClass($class); $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))) { + if (!(\in_array($ref->getName(), [$negClass, $posClass]) || $ref->isSubclassOf($negClass) || $ref->isSubclassOf($posClass))) { throw new Twig_Error_Syntax(sprintf('Unexpected unary operator "%s".', $token->getValue()), $token->getLine(), $this->parser->getStream()->getSourceContext()); } @@ -337,7 +337,7 @@ class Twig_ExpressionParser switch ($name) { case 'parent': $this->parseArguments(); - if (!count($this->parser->getBlockStack())) { + if (!\count($this->parser->getBlockStack())) { throw new Twig_Error_Syntax('Calling "parent" outside a block is forbidden.', $line, $this->parser->getStream()->getSourceContext()); } @@ -348,18 +348,18 @@ class Twig_ExpressionParser return new Twig_Node_Expression_Parent($this->parser->peekBlockStack(), $line); case 'block': $args = $this->parseArguments(); - if (count($args) < 1) { + if (\count($args) < 1) { throw new Twig_Error_Syntax('The "block" function takes one argument (the block name).', $line, $this->parser->getStream()->getSourceContext()); } - return new Twig_Node_Expression_BlockReference($args->getNode(0), count($args) > 1 ? $args->getNode(1) : null, $line); + return new Twig_Node_Expression_BlockReference($args->getNode(0), \count($args) > 1 ? $args->getNode(1) : null, $line); case 'attribute': $args = $this->parseArguments(); - if (count($args) < 2) { + if (\count($args) < 2) { throw new Twig_Error_Syntax('The "attribute" function takes at least two arguments (the variable and the attributes).', $line, $this->parser->getStream()->getSourceContext()); } - return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line); + return new Twig_Node_Expression_GetAttr($args->getNode(0), $args->getNode(1), \count($args) > 2 ? $args->getNode(2) : null, Twig_Template::ANY_CALL, $line); default: if (null !== $alias = $this->parser->getImportedSymbol('function', $name)) { $arguments = new Twig_Node_Expression_Array([], $line); @@ -526,7 +526,7 @@ class Twig_ExpressionParser $name = null; if ($namedArguments && $token = $stream->nextIf(Twig_Token::OPERATOR_TYPE, '=')) { if (!$value instanceof Twig_Node_Expression_Name) { - throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', get_class($value)), $token->getLine(), $stream->getSourceContext()); + throw new Twig_Error_Syntax(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); } $name = $value->getAttribute('name'); @@ -567,7 +567,7 @@ class Twig_ExpressionParser while (true) { $token = $stream->expect(Twig_Token::NAME_TYPE, null, 'Only variables can be assigned to'); $value = $token->getValue(); - if (in_array(strtolower($value), ['true', 'false', 'none', 'null'])) { + if (\in_array(strtolower($value), ['true', 'false', 'none', 'null'])) { throw new Twig_Error_Syntax(sprintf('You cannot assign a value to "%s".', $value), $token->getLine(), $stream->getSourceContext()); } $targets[] = new Twig_Node_Expression_AssignName($value, $token->getLine()); @@ -643,7 +643,7 @@ class Twig_ExpressionParser if ($test instanceof Twig_SimpleTest && $test->isDeprecated()) { $stream = $this->parser->getStream(); $message = sprintf('Twig Test "%s" is deprecated', $test->getName()); - if (!is_bool($test->getDeprecatedVersion())) { + if (!\is_bool($test->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $test->getDeprecatedVersion()); } if ($test->getAlternative()) { @@ -673,7 +673,7 @@ class Twig_ExpressionParser if ($function instanceof Twig_SimpleFunction && $function->isDeprecated()) { $message = sprintf('Twig Function "%s" is deprecated', $function->getName()); - if (!is_bool($function->getDeprecatedVersion())) { + if (!\is_bool($function->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $function->getDeprecatedVersion()); } if ($function->getAlternative()) { @@ -703,7 +703,7 @@ class Twig_ExpressionParser if ($filter instanceof Twig_SimpleFilter && $filter->isDeprecated()) { $message = sprintf('Twig Filter "%s" is deprecated', $filter->getName()); - if (!is_bool($filter->getDeprecatedVersion())) { + if (!\is_bool($filter->getDeprecatedVersion())) { $message .= sprintf(' since version %s', $filter->getDeprecatedVersion()); } if ($filter->getAlternative()) { diff --git a/lib/Twig/Extension.php b/lib/Twig/Extension.php index de93ca610..1dffaeb46 100644 --- a/lib/Twig/Extension.php +++ b/lib/Twig/Extension.php @@ -61,7 +61,7 @@ abstract class Twig_Extension implements Twig_ExtensionInterface */ public function getName() { - return get_class($this); + return \get_class($this); } } diff --git a/lib/Twig/Extension/Core.php b/lib/Twig/Extension/Core.php index fcd4c405d..c2bfbafe3 100644 --- a/lib/Twig/Extension/Core.php +++ b/lib/Twig/Extension/Core.php @@ -1,7 +1,7 @@ true, 'is_safe_callback' => 'twig_escape_filter_is_safe']), ]; - if (function_exists('mb_get_info')) { + if (\function_exists('mb_get_info')) { $filters[] = new Twig_SimpleFilter('upper', 'twig_upper_filter', ['needs_environment' => true]); $filters[] = new Twig_SimpleFilter('lower', 'twig_lower_filter', ['needs_environment' => true]); } @@ -287,11 +287,11 @@ class Twig_Extension_Core extends Twig_Extension */ function twig_cycle($values, $position) { - if (!is_array($values) && !$values instanceof ArrayAccess) { + if (!\is_array($values) && !$values instanceof ArrayAccess) { return $values; } - return $values[$position % count($values)]; + return $values[$position % \count($values)]; } /** @@ -312,13 +312,13 @@ function twig_random(Twig_Environment $env, $values = null) return mt_rand(); } - if (is_int($values) || is_float($values)) { + if (\is_int($values) || \is_float($values)) { return $values < 0 ? mt_rand($values, 0) : mt_rand(0, $values); } if ($values instanceof \Traversable) { $values = iterator_to_array($values); - } elseif (is_string($values)) { + } elseif (\is_string($values)) { if ('' === $values) { return ''; } @@ -337,15 +337,15 @@ function twig_random(Twig_Environment $env, $values = null) } } } else { - return $values[mt_rand(0, strlen($values) - 1)]; + return $values[mt_rand(0, \strlen($values) - 1)]; } } - if (!is_array($values)) { + if (!\is_array($values)) { return $values; } - if (0 === count($values)) { + if (0 === \count($values)) { throw new Twig_Error_Runtime('The random function cannot pick from an empty array.'); } @@ -466,12 +466,12 @@ function twig_replace_filter($str, $from, $to = null) { if ($from instanceof \Traversable) { $from = iterator_to_array($from); - } elseif (is_string($from) && is_string($to)) { + } elseif (\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); return strtr($str, $from, $to); - } elseif (!is_array($from)) { - throw new Twig_Error_Runtime(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', is_object($from) ? get_class($from) : gettype($from))); + } elseif (!\is_array($from)) { + throw new Twig_Error_Runtime(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); @@ -540,8 +540,8 @@ function twig_number_format_filter(Twig_Environment $env, $number, $decimal = nu */ function twig_urlencode_filter($url) { - if (is_array($url)) { - if (defined('PHP_QUERY_RFC3986')) { + if (\is_array($url)) { + if (\defined('PHP_QUERY_RFC3986')) { return http_build_query($url, '', '&', PHP_QUERY_RFC3986); } @@ -563,7 +563,7 @@ function twig_jsonencode_filter($value, $options = 0) { if ($value instanceof Twig_Markup) { $value = (string) $value; - } elseif (is_array($value)) { + } elseif (\is_array($value)) { array_walk_recursive($value, '_twig_markup2string'); } @@ -595,14 +595,14 @@ function twig_array_merge($arr1, $arr2) { if ($arr1 instanceof \Traversable) { $arr1 = iterator_to_array($arr1); - } elseif (!is_array($arr1)) { - throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', gettype($arr1))); + } elseif (!\is_array($arr1)) { + throw new Twig_Error_Runtime(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_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', gettype($arr2))); + } elseif (!\is_array($arr2)) { + throw new Twig_Error_Runtime(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2))); } return array_merge($arr1, $arr2); @@ -636,13 +636,13 @@ function twig_slice(Twig_Environment $env, $item, $start, $length = null, $prese $item = iterator_to_array($item, $preserveKeys); } - if (is_array($item)) { - return array_slice($item, $start, $length, $preserveKeys); + if (\is_array($item)) { + return \array_slice($item, $start, $length, $preserveKeys); } $item = (string) $item; - if (function_exists('mb_get_info') && null !== $charset = $env->getCharset()) { + if (\function_exists('mb_get_info') && null !== $charset = $env->getCharset()) { return (string) mb_substr($item, $start, null === $length ? mb_strlen($item, $charset) - $start : $length, $charset); } @@ -660,7 +660,7 @@ function twig_first(Twig_Environment $env, $item) { $elements = twig_slice($env, $item, 0, 1, false); - return is_string($elements) ? $elements : current($elements); + return \is_string($elements) ? $elements : current($elements); } /** @@ -674,7 +674,7 @@ function twig_last(Twig_Environment $env, $item) { $elements = twig_slice($env, $item, -1, 1, false); - return is_string($elements) ? $elements : current($elements); + return \is_string($elements) ? $elements : current($elements); } /** @@ -705,7 +705,7 @@ function twig_join_filter($value, $glue = '', $and = null) $value = (array) $value; } - if (0 === count($value)) { + if (0 === \count($value)) { return ''; } @@ -714,11 +714,11 @@ function twig_join_filter($value, $glue = '', $and = null) } $v = array_values($value); - if (1 === count($v)) { + if (1 === \count($v)) { return $v[0]; } - return implode($glue, array_slice($value, 0, -1)).$and.$v[count($v) - 1]; + return implode($glue, \array_slice($value, 0, -1)).$and.$v[\count($v) - 1]; } /** @@ -748,7 +748,7 @@ function twig_split_filter(Twig_Environment $env, $value, $delimiter, $limit = n return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); } - if (!function_exists('mb_get_info') || null === $charset = $env->getCharset()) { + if (!\function_exists('mb_get_info') || null === $charset = $env->getCharset()) { return str_split($value, null === $limit ? 1 : $limit); } @@ -823,7 +823,7 @@ function twig_get_array_keys_filter($array) return $keys; } - if (!is_array($array)) { + if (!\is_array($array)) { return []; } @@ -844,7 +844,7 @@ function twig_reverse_filter(Twig_Environment $env, $item, $preserveKeys = false return array_reverse(iterator_to_array($item), $preserveKeys); } - if (is_array($item)) { + if (\is_array($item)) { return array_reverse($item, $preserveKeys); } @@ -880,8 +880,8 @@ function twig_sort_filter($array) { if ($array instanceof \Traversable) { $array = iterator_to_array($array); - } elseif (!is_array($array)) { - throw new Twig_Error_Runtime(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', gettype($array))); + } elseif (!\is_array($array)) { + throw new Twig_Error_Runtime(sprintf('The sort filter only works with arrays or "Traversable", got "%s".', \gettype($array))); } asort($array); @@ -894,12 +894,12 @@ function twig_sort_filter($array) */ function twig_in_filter($value, $compare) { - if (is_array($compare)) { - return in_array($value, $compare, is_object($value) || is_resource($value)); - } elseif (is_string($compare) && (is_string($value) || is_int($value) || is_float($value))) { + if (\is_array($compare)) { + return \in_array($value, $compare, \is_object($value) || \is_resource($value)); + } elseif (\is_string($compare) && (\is_string($value) || \is_int($value) || \is_float($value))) { return '' === $value || false !== strpos($compare, (string) $value); } elseif ($compare instanceof \Traversable) { - if (is_object($value) || is_resource($value)) { + if (\is_object($value) || \is_resource($value)) { foreach ($compare as $item) { if ($item === $value) { return true; @@ -960,10 +960,10 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', return $string; } - if (!is_string($string)) { - if (is_object($string) && method_exists($string, '__toString')) { + if (!\is_string($string)) { + if (\is_object($string) && method_exists($string, '__toString')) { $string = (string) $string; - } elseif (in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { + } elseif (\in_array($strategy, ['html', 'js', 'css', 'html_attr', 'url'])) { return $string; } } @@ -1080,7 +1080,7 @@ function twig_escape_filter(Twig_Environment $env, $string, $strategy = 'html', } if (isset($escapers[$strategy])) { - return call_user_func($escapers[$strategy], $env, $string, $charset); + return \call_user_func($escapers[$strategy], $env, $string, $charset); } $validStrategies = implode(', ', array_merge(['html', 'js', 'url', 'css', 'html_attr'], array_keys($escapers))); @@ -1105,12 +1105,12 @@ function twig_escape_filter_is_safe(Twig_Node $filterArgs) return ['html']; } -if (function_exists('mb_convert_encoding')) { +if (\function_exists('mb_convert_encoding')) { function twig_convert_encoding($string, $to, $from) { return mb_convert_encoding($string, $to, $from); } -} elseif (function_exists('iconv')) { +} elseif (\function_exists('iconv')) { function twig_convert_encoding($string, $to, $from) { return iconv($from, $to, $string); @@ -1122,7 +1122,7 @@ if (function_exists('mb_convert_encoding')) { } } -if (function_exists('mb_ord')) { +if (\function_exists('mb_ord')) { function twig_ord($string) { return mb_ord($string, 'UTF-8'); @@ -1172,7 +1172,7 @@ function _twig_escape_js_callback($matches) $char = twig_convert_encoding($char, 'UTF-16BE', 'UTF-8'); $char = strtoupper(bin2hex($char)); - if (4 >= strlen($char)) { + if (4 >= \strlen($char)) { return sprintf('\u%04s', $char); } @@ -1183,7 +1183,7 @@ function _twig_escape_css_callback($matches) { $char = $matches[0]; - return sprintf('\\%X ', 1 === strlen($char) ? ord($char) : twig_ord($char)); + return sprintf('\\%X ', 1 === \strlen($char) ? \ord($char) : twig_ord($char)); } /** @@ -1195,7 +1195,7 @@ function _twig_escape_css_callback($matches) function _twig_escape_html_attr_callback($matches) { $chr = $matches[0]; - $ord = ord($chr); + $ord = \ord($chr); /* * The following replaces characters undefined in HTML with the @@ -1209,7 +1209,7 @@ function _twig_escape_html_attr_callback($matches) * Check if the current character to escape has a name entity we should * replace it with while grabbing the hex value of the character. */ - if (1 == strlen($chr)) { + if (1 == \strlen($chr)) { /* * While HTML supports far more named entities, the lowest common denominator * has become HTML5's XML Serialisation which is restricted to the those named @@ -1238,7 +1238,7 @@ function _twig_escape_html_attr_callback($matches) } // add multibyte extensions if possible -if (function_exists('mb_get_info')) { +if (\function_exists('mb_get_info')) { /** * Returns the length of a variable. * @@ -1257,15 +1257,15 @@ if (function_exists('mb_get_info')) { } if ($thing instanceof \SimpleXMLElement) { - return count($thing); + return \count($thing); } - if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { + if (\is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { return mb_strlen((string) $thing, $env->getCharset()); } - if ($thing instanceof \Countable || is_array($thing)) { - return count($thing); + if ($thing instanceof \Countable || \is_array($thing)) { + return \count($thing); } if ($thing instanceof \IteratorAggregate) { @@ -1355,19 +1355,19 @@ else { } if (is_scalar($thing)) { - return strlen($thing); + return \strlen($thing); } if ($thing instanceof \SimpleXMLElement) { - return count($thing); + return \count($thing); } - if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { - return strlen((string) $thing); + if (\is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) { + return \strlen((string) $thing); } - if ($thing instanceof \Countable || is_array($thing)) { - return count($thing); + if ($thing instanceof \Countable || \is_array($thing)) { + return \count($thing); } if ($thing instanceof \IteratorAggregate) { @@ -1407,7 +1407,7 @@ else { */ function twig_ensure_traversable($seq) { - if ($seq instanceof \Traversable || is_array($seq)) { + if ($seq instanceof \Traversable || \is_array($seq)) { return $seq; } @@ -1429,10 +1429,10 @@ function twig_ensure_traversable($seq) function twig_test_empty($value) { if ($value instanceof \Countable) { - return 0 == count($value); + return 0 == \count($value); } - if (is_object($value) && method_exists($value, '__toString')) { + if (\is_object($value) && method_exists($value, '__toString')) { return '' === (string) $value; } @@ -1453,7 +1453,7 @@ function twig_test_empty($value) */ function twig_test_iterable($value) { - return $value instanceof \Traversable || is_array($value); + return $value instanceof \Traversable || \is_array($value); } /** @@ -1550,10 +1550,10 @@ function twig_source(Twig_Environment $env, $name, $ignoreMissing = false) function twig_constant($constant, $object = null) { if (null !== $object) { - $constant = get_class($object).'::'.$constant; + $constant = \get_class($object).'::'.$constant; } - return constant($constant); + return \constant($constant); } /** @@ -1567,10 +1567,10 @@ function twig_constant($constant, $object = null) function twig_constant_is_defined($constant, $object = null) { if (null !== $object) { - $constant = get_class($object).'::'.$constant; + $constant = \get_class($object).'::'.$constant; } - return defined($constant); + return \defined($constant); } /** @@ -1593,8 +1593,8 @@ function twig_array_batch($items, $size, $fill = null) $result = array_chunk($items, $size, true); if (null !== $fill && !empty($result)) { - $last = count($result) - 1; - if ($fillCount = $size - count($result[$last])) { + $last = \count($result) - 1; + if ($fillCount = $size - \count($result[$last])) { $result[$last] = array_merge( $result[$last], array_fill(0, $fillCount, $fill) diff --git a/lib/Twig/Extension/Debug.php b/lib/Twig/Extension/Debug.php index 87f47d65b..c3c64a575 100644 --- a/lib/Twig/Extension/Debug.php +++ b/lib/Twig/Extension/Debug.php @@ -17,7 +17,7 @@ class Twig_Extension_Debug extends Twig_Extension public function getFunctions() { // dump is safe if var_dump is overridden by xdebug - $isDumpOutputHtmlSafe = extension_loaded('xdebug') + $isDumpOutputHtmlSafe = \extension_loaded('xdebug') // false means that it was not set (and the default is on) or it explicitly enabled && (false === ini_get('xdebug.overload_var_dump') || ini_get('xdebug.overload_var_dump')) // false means that it was not set (and the default is on) or it explicitly enabled @@ -45,7 +45,7 @@ function twig_var_dump(Twig_Environment $env, $context) ob_start(); - $count = func_num_args(); + $count = \func_num_args(); if (2 === $count) { $vars = []; foreach ($context as $key => $value) { diff --git a/lib/Twig/Extension/Escaper.php b/lib/Twig/Extension/Escaper.php index 74f0e997c..a4bf84488 100644 --- a/lib/Twig/Extension/Escaper.php +++ b/lib/Twig/Extension/Escaper.php @@ -84,8 +84,8 @@ class Twig_Extension_Escaper extends Twig_Extension { // disable string callables to avoid calling a function named html or js, // or any other upcoming escaping strategy - if (!is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { - return call_user_func($this->defaultStrategy, $name); + if (!\is_string($this->defaultStrategy) && false !== $this->defaultStrategy) { + return \call_user_func($this->defaultStrategy, $name); } return $this->defaultStrategy; diff --git a/lib/Twig/Extension/Profiler.php b/lib/Twig/Extension/Profiler.php index d7faef863..0f991dca3 100644 --- a/lib/Twig/Extension/Profiler.php +++ b/lib/Twig/Extension/Profiler.php @@ -29,14 +29,14 @@ class Twig_Extension_Profiler extends Twig_Extension $profile->leave(); array_shift($this->actives); - if (1 === count($this->actives)) { + if (1 === \count($this->actives)) { $this->actives[0]->leave(); } } public function getNodeVisitors() { - return [new Twig_Profiler_NodeVisitor_Profiler(get_class($this))]; + return [new Twig_Profiler_NodeVisitor_Profiler(\get_class($this))]; } public function getName() diff --git a/lib/Twig/Extension/Sandbox.php b/lib/Twig/Extension/Sandbox.php index cacde630d..915020257 100644 --- a/lib/Twig/Extension/Sandbox.php +++ b/lib/Twig/Extension/Sandbox.php @@ -87,7 +87,7 @@ class Twig_Extension_Sandbox extends Twig_Extension public function ensureToStringAllowed($obj) { - if ($this->isSandboxed() && is_object($obj)) { + if ($this->isSandboxed() && \is_object($obj)) { $this->policy->checkMethodAllowed($obj, '__toString'); } diff --git a/lib/Twig/FileExtensionEscapingStrategy.php b/lib/Twig/FileExtensionEscapingStrategy.php index 6b13c7213..7854f7691 100644 --- a/lib/Twig/FileExtensionEscapingStrategy.php +++ b/lib/Twig/FileExtensionEscapingStrategy.php @@ -31,7 +31,7 @@ class Twig_FileExtensionEscapingStrategy */ public static function guess($name) { - if (in_array(substr($name, -1), ['/', '\\'])) { + if (\in_array(substr($name, -1), ['/', '\\'])) { return 'html'; // return html for directories } diff --git a/lib/Twig/Filter.php b/lib/Twig/Filter.php index 9191c5473..d04322896 100644 --- a/lib/Twig/Filter.php +++ b/lib/Twig/Filter.php @@ -63,7 +63,7 @@ abstract class Twig_Filter implements Twig_FilterInterface, Twig_FilterCallableI } if (isset($this->options['is_safe_callback'])) { - return call_user_func($this->options['is_safe_callback'], $filterArgs); + return \call_user_func($this->options['is_safe_callback'], $filterArgs); } } diff --git a/lib/Twig/Filter/Method.php b/lib/Twig/Filter/Method.php index 2dc39b613..088306cc8 100644 --- a/lib/Twig/Filter/Method.php +++ b/lib/Twig/Filter/Method.php @@ -37,6 +37,6 @@ class Twig_Filter_Method extends Twig_Filter public function compile() { - return sprintf('$this->env->getExtension(\'%s\')->%s', get_class($this->extension), $this->method); + return sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($this->extension), $this->method); } } diff --git a/lib/Twig/Function.php b/lib/Twig/Function.php index a829eeeab..58da0433c 100644 --- a/lib/Twig/Function.php +++ b/lib/Twig/Function.php @@ -61,7 +61,7 @@ abstract class Twig_Function implements Twig_FunctionInterface, Twig_FunctionCal } if (isset($this->options['is_safe_callback'])) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); + return \call_user_func($this->options['is_safe_callback'], $functionArgs); } return []; diff --git a/lib/Twig/Function/Method.php b/lib/Twig/Function/Method.php index 4806a4306..c8d210fcb 100644 --- a/lib/Twig/Function/Method.php +++ b/lib/Twig/Function/Method.php @@ -38,6 +38,6 @@ class Twig_Function_Method extends Twig_Function public function compile() { - return sprintf('$this->env->getExtension(\'%s\')->%s', get_class($this->extension), $this->method); + return sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($this->extension), $this->method); } } diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 6e270d1d8..dac1c8bbe 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -88,7 +88,7 @@ class Twig_Lexer implements Twig_LexerInterface @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) { + if (\function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) { $mbEncoding = mb_internal_encoding(); mb_internal_encoding('ASCII'); } else { @@ -99,7 +99,7 @@ class Twig_Lexer implements Twig_LexerInterface $this->filename = $this->source->getName(); $this->cursor = 0; $this->lineno = 1; - $this->end = strlen($this->code); + $this->end = \strlen($this->code); $this->tokens = []; $this->state = self::STATE_DATA; $this->states = []; @@ -153,7 +153,7 @@ class Twig_Lexer implements Twig_LexerInterface 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) { + if ($this->position == \count($this->positions[0]) - 1) { $this->pushToken(Twig_Token::TEXT_TYPE, substr($this->code, $this->cursor)); $this->cursor = $this->end; @@ -163,7 +163,7 @@ class Twig_Lexer implements Twig_LexerInterface // Find the first token after the current cursor $position = $this->positions[0][++$this->position]; while ($position[1] < $this->cursor) { - if ($this->position == count($this->positions[0]) - 1) { + if ($this->position == \count($this->positions[0]) - 1) { return; } $position = $this->positions[0][++$this->position]; @@ -332,7 +332,7 @@ class Twig_Lexer implements Twig_LexerInterface $this->pushToken(Twig_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) { + } 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->moveCursor($match[0]); } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, null, $this->cursor)) { @@ -374,7 +374,7 @@ class Twig_Lexer implements Twig_LexerInterface protected function moveCursor($text) { - $this->cursor += strlen($text); + $this->cursor += \strlen($text); $this->lineno += substr_count($text, "\n"); } @@ -416,7 +416,7 @@ class Twig_Lexer implements Twig_LexerInterface protected function popState() { - if (0 === count($this->states)) { + if (0 === \count($this->states)) { throw new \LogicException('Cannot pop state without a previous state.'); } diff --git a/lib/Twig/Loader/Array.php b/lib/Twig/Loader/Array.php index 7c5131790..ca2efa833 100644 --- a/lib/Twig/Loader/Array.php +++ b/lib/Twig/Loader/Array.php @@ -48,7 +48,7 @@ class Twig_Loader_Array implements Twig_LoaderInterface, Twig_ExistsLoaderInterf public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); $name = (string) $name; if (!isset($this->templates[$name])) { diff --git a/lib/Twig/Loader/Chain.php b/lib/Twig/Loader/Chain.php index 8ccf8c9cf..ae6c0333e 100644 --- a/lib/Twig/Loader/Chain.php +++ b/lib/Twig/Loader/Chain.php @@ -39,7 +39,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); $exceptions = []; foreach ($this->loaders as $loader) { @@ -122,7 +122,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf try { return $loader->getCacheKey($name); } catch (Twig_Error_Loader $e) { - $exceptions[] = get_class($loader).': '.$e->getMessage(); + $exceptions[] = \get_class($loader).': '.$e->getMessage(); } } @@ -140,7 +140,7 @@ class Twig_Loader_Chain implements Twig_LoaderInterface, Twig_ExistsLoaderInterf try { return $loader->isFresh($name, $time); } catch (Twig_Error_Loader $e) { - $exceptions[] = get_class($loader).': '.$e->getMessage(); + $exceptions[] = \get_class($loader).': '.$e->getMessage(); } } diff --git a/lib/Twig/Loader/Filesystem.php b/lib/Twig/Loader/Filesystem.php index 2a241a9c1..475b9070d 100644 --- a/lib/Twig/Loader/Filesystem.php +++ b/lib/Twig/Loader/Filesystem.php @@ -73,7 +73,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI */ public function setPaths($paths, $namespace = self::MAIN_NAMESPACE) { - if (!is_array($paths)) { + if (!\is_array($paths)) { $paths = [$paths]; } @@ -133,7 +133,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); return file_get_contents($this->findTemplate($name)); } @@ -148,7 +148,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI public function getCacheKey($name) { $path = $this->findTemplate($name); - $len = strlen($this->rootPath); + $len = \strlen($this->rootPath); if (0 === strncmp($this->rootPath, $path, $len)) { return substr($path, $len); } @@ -167,7 +167,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI try { return false !== $this->findTemplate($name, false); } catch (Twig_Error_Loader $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); + @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; } @@ -180,7 +180,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI protected function findTemplate($name) { - $throw = func_num_args() > 1 ? func_get_arg(1) : true; + $throw = \func_num_args() > 1 ? func_get_arg(1) : true; $name = $this->normalizeName($name); if (isset($this->cache[$name])) { @@ -286,7 +286,7 @@ class Twig_Loader_Filesystem implements Twig_LoaderInterface, Twig_ExistsLoaderI private function isAbsolutePath($file) { return strspn($file, '/\\', 0, 1) - || (strlen($file) > 3 && ctype_alpha($file[0]) + || (\strlen($file) > 3 && ctype_alpha($file[0]) && ':' === substr($file, 1, 1) && strspn($file, '/\\', 2, 1) ) diff --git a/lib/Twig/Loader/String.php b/lib/Twig/Loader/String.php index 950bd35b0..1d7544cd1 100644 --- a/lib/Twig/Loader/String.php +++ b/lib/Twig/Loader/String.php @@ -31,7 +31,7 @@ class Twig_Loader_String implements Twig_LoaderInterface, Twig_ExistsLoaderInter { public function getSource($name) { - @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', get_class($this)), E_USER_DEPRECATED); + @trigger_error(sprintf('Calling "getSource" on "%s" is deprecated since 1.27. Use getSourceContext() instead.', \get_class($this)), E_USER_DEPRECATED); return $name; } diff --git a/lib/Twig/Markup.php b/lib/Twig/Markup.php index e55d09c71..ea99d32ed 100644 --- a/lib/Twig/Markup.php +++ b/lib/Twig/Markup.php @@ -32,7 +32,7 @@ class Twig_Markup implements \Countable public function count() { - return function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : strlen($this->content); + return \function_exists('mb_get_info') ? mb_strlen($this->content, $this->charset) : \strlen($this->content); } } diff --git a/lib/Twig/Node.php b/lib/Twig/Node.php index 277622768..67bdaee7c 100644 --- a/lib/Twig/Node.php +++ b/lib/Twig/Node.php @@ -39,7 +39,7 @@ class Twig_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, get_class($this)), 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, \get_class($this)), E_USER_DEPRECATED); } } $this->nodes = $nodes; @@ -55,11 +55,11 @@ class Twig_Node implements Twig_NodeInterface $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true))); } - $repr = [get_class($this).'('.implode(', ', $attributes)]; + $repr = [\get_class($this).'('.implode(', ', $attributes)]; - if (count($this->nodes)) { + if (\count($this->nodes)) { foreach ($this->nodes as $name => $node) { - $len = strlen($name) + 4; + $len = \strlen($name) + 4; $noderepr = []; foreach (explode("\n", (string) $node) as $line) { $noderepr[] = str_repeat(' ', $len).$line; @@ -88,7 +88,7 @@ class Twig_Node implements Twig_NodeInterface $dom->appendChild($xml = $dom->createElement('twig')); $xml->appendChild($node = $dom->createElement('node')); - $node->setAttribute('class', get_class($this)); + $node->setAttribute('class', \get_class($this)); foreach ($this->attributes as $name => $value) { $node->appendChild($attribute = $dom->createElement('attribute')); @@ -143,7 +143,7 @@ class Twig_Node implements Twig_NodeInterface */ public function hasAttribute($name) { - return array_key_exists($name, $this->attributes); + return \array_key_exists($name, $this->attributes); } /** @@ -151,8 +151,8 @@ class Twig_Node implements Twig_NodeInterface */ public function getAttribute($name) { - if (!array_key_exists($name, $this->attributes)) { - throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, get_class($this))); + if (!\array_key_exists($name, $this->attributes)) { + throw new \LogicException(sprintf('Attribute "%s" does not exist for Node "%s".', $name, \get_class($this))); } return $this->attributes[$name]; @@ -177,7 +177,7 @@ class Twig_Node implements Twig_NodeInterface */ public function hasNode($name) { - return array_key_exists($name, $this->nodes); + return \array_key_exists($name, $this->nodes); } /** @@ -185,8 +185,8 @@ class Twig_Node implements Twig_NodeInterface */ public function getNode($name) { - if (!array_key_exists($name, $this->nodes)) { - throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, get_class($this))); + if (!\array_key_exists($name, $this->nodes)) { + throw new \LogicException(sprintf('Node "%s" does not exist for Node "%s".', $name, \get_class($this))); } return $this->nodes[$name]; @@ -195,7 +195,7 @@ class Twig_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, get_class($this)), 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, \get_class($this)), E_USER_DEPRECATED); } $this->nodes[$name] = $node; @@ -208,7 +208,7 @@ class Twig_Node implements Twig_NodeInterface public function count() { - return count($this->nodes); + return \count($this->nodes); } public function getIterator() diff --git a/lib/Twig/Node/Expression/BlockReference.php b/lib/Twig/Node/Expression/BlockReference.php index 4beb13aa4..1fcea68fa 100644 --- a/lib/Twig/Node/Expression/BlockReference.php +++ b/lib/Twig/Node/Expression/BlockReference.php @@ -22,7 +22,7 @@ class Twig_Node_Expression_BlockReference extends Twig_Node_Expression */ public function __construct(Twig_NodeInterface $name, $template = null, $lineno, $tag = null) { - if (is_bool($template)) { + 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); $template = null; diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 846399cce..a5a9b5f23 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -17,18 +17,18 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression $closingParenthesis = false; $isArray = false; if ($this->hasAttribute('callable') && $callable = $this->getAttribute('callable')) { - if (is_string($callable) && false === strpos($callable, '::')) { + if (\is_string($callable) && false === strpos($callable, '::')) { $compiler->raw($callable); } else { list($r, $callable) = $this->reflectCallable($callable); - if ($r instanceof \ReflectionMethod && is_string($callable[0])) { + if ($r instanceof \ReflectionMethod && \is_string($callable[0])) { if ($r->isStatic()) { $compiler->raw(sprintf('%s::%s', $callable[0], $callable[1])); } else { $compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1])); } } elseif ($r instanceof \ReflectionMethod && $callable[0] instanceof Twig_ExtensionInterface) { - $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', get_class($callable[0]), $callable[1])); + $compiler->raw(sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($callable[0]), $callable[1])); } else { $type = ucfirst($this->getAttribute('type')); $compiler->raw(sprintf('call_user_func_array($this->env->get%s(\'%s\')->getCallable(), ', $type, $this->getAttribute('name'))); @@ -109,7 +109,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression $parameters = []; $named = false; foreach ($arguments as $name => $node) { - if (!is_int($name)) { + if (!\is_int($name)) { $named = true; $name = $this->normalizeName($name); } elseif ($named) { @@ -143,15 +143,15 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression foreach ($callableParameters as $callableParameter) { $names[] = $name = $this->normalizeName($callableParameter->name); - if (array_key_exists($name, $parameters)) { - if (array_key_exists($pos, $parameters)) { + if (\array_key_exists($name, $parameters)) { + if (\array_key_exists($pos, $parameters)) { throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $callType, $callName), $this->getTemplateLine()); } - if (count($missingArguments)) { + if (\count($missingArguments)) { throw new Twig_Error_Syntax(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) + $name, $callType, $callName, implode(', ', $names), \count($missingArguments) > 1 ? 's' : '', implode('", "', $missingArguments) ), $this->getTemplateLine()); } @@ -159,7 +159,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression $arguments[] = $parameters[$name]; unset($parameters[$name]); $optionalArguments = []; - } elseif (array_key_exists($pos, $parameters)) { + } elseif (\array_key_exists($pos, $parameters)) { $arguments = array_merge($arguments, $optionalArguments); $arguments[] = $parameters[$pos]; unset($parameters[$pos]); @@ -181,7 +181,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression if ($isVariadic) { $arbitraryArguments = new Twig_Node_Expression_Array([], -1); foreach ($parameters as $key => $value) { - if (is_int($key)) { + if (\is_int($key)) { $arbitraryArguments->addElement($value); } else { $arbitraryArguments->addElement($value, new Twig_Node_Expression_Constant($key, -1)); @@ -206,7 +206,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression throw new Twig_Error_Syntax(sprintf( 'Unknown argument%s "%s" for %s "%s(%s)".', - count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) + \count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $callType, $callName, implode(', ', $names) ), $unknownParameter ? $unknownParameter->getTemplateLine() : $this->getTemplateLine()); } @@ -263,17 +263,17 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression return $this->reflector; } - if (is_array($callable)) { + if (\is_array($callable)) { if (!method_exists($callable[0], $callable[1])) { // __call() return [null, []]; } $r = new \ReflectionMethod($callable[0], $callable[1]); - } elseif (is_object($callable) && !$callable instanceof Closure) { + } elseif (\is_object($callable) && !$callable instanceof Closure) { $r = new \ReflectionObject($callable); $r = $r->getMethod('__invoke'); $callable = [$callable, '__invoke']; - } elseif (is_string($callable) && false !== $pos = strpos($callable, '::')) { + } elseif (\is_string($callable) && false !== $pos = strpos($callable, '::')) { $class = substr($callable, 0, $pos); $method = substr($callable, $pos + 2); if (!method_exists($class, $method)) { diff --git a/lib/Twig/Node/Expression/Filter/Default.php b/lib/Twig/Node/Expression/Filter/Default.php index 5b2e6cf9d..3fbbe52eb 100644 --- a/lib/Twig/Node/Expression/Filter/Default.php +++ b/lib/Twig/Node/Expression/Filter/Default.php @@ -24,7 +24,7 @@ class Twig_Node_Expression_Filter_Default extends Twig_Node_Expression_Filter if ('default' === $filterName->getAttribute('value') && ($node instanceof Twig_Node_Expression_Name || $node instanceof Twig_Node_Expression_GetAttr)) { $test = new Twig_Node_Expression_Test_Defined(clone $node, 'defined', new Twig_Node(), $node->getTemplateLine()); - $false = count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine()); + $false = \count($arguments) ? $arguments->getNode(0) : new Twig_Node_Expression_Constant('', $node->getTemplateLine()); $node = new Twig_Node_Expression_Conditional($test, $default, $false, $node->getTemplateLine()); } else { diff --git a/lib/Twig/Node/Expression/GetAttr.php b/lib/Twig/Node/Expression/GetAttr.php index 897691508..b3a01b27f 100644 --- a/lib/Twig/Node/Expression/GetAttr.php +++ b/lib/Twig/Node/Expression/GetAttr.php @@ -27,7 +27,7 @@ class Twig_Node_Expression_GetAttr extends Twig_Node_Expression @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')) { + if (\function_exists('twig_template_get_attributes') && !$this->getAttribute('disable_c_ext')) { $compiler->raw('twig_template_get_attributes($this, '); } else { $compiler->raw('$this->getAttribute('); diff --git a/lib/Twig/Node/If.php b/lib/Twig/Node/If.php index b096cd4e9..3a5af2cdf 100644 --- a/lib/Twig/Node/If.php +++ b/lib/Twig/Node/If.php @@ -30,7 +30,7 @@ class Twig_Node_If extends Twig_Node public function compile(Twig_Compiler $compiler) { $compiler->addDebugInfo($this); - for ($i = 0, $count = count($this->getNode('tests')); $i < $count; $i += 2) { + for ($i = 0, $count = \count($this->getNode('tests')); $i < $count; $i += 2) { if ($i > 0) { $compiler ->outdent() diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index c9ec6f776..592c11e1a 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -36,7 +36,7 @@ class Twig_Node_Macro extends Twig_Node ->write(sprintf('public function get%s(', $this->getAttribute('name'))) ; - $count = count($this->getNode('arguments')); + $count = \count($this->getNode('arguments')); $pos = 0; foreach ($this->getNode('arguments') as $name => $default) { $compiler diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 3305d2f0d..b24a29e4e 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -84,12 +84,12 @@ class Twig_Node_Module extends Twig_Node $this->compileClassHeader($compiler); if ( - count($this->getNode('blocks')) - || count($this->getNode('traits')) + \count($this->getNode('blocks')) + || \count($this->getNode('traits')) || !$this->hasNode('parent') || $this->getNode('parent') instanceof Twig_Node_Expression_Constant - || count($this->getNode('constructor_start')) - || count($this->getNode('constructor_end')) + || \count($this->getNode('constructor_start')) + || \count($this->getNode('constructor_end')) ) { $this->compileConstructor($compiler); } @@ -188,7 +188,7 @@ class Twig_Node_Module extends Twig_Node ; } - $countTraits = count($this->getNode('traits')); + $countTraits = \count($this->getNode('traits')); if ($countTraits) { // traits foreach ($this->getNode('traits') as $i => $trait) { @@ -360,7 +360,7 @@ class Twig_Node_Module extends Twig_Node // // Put another way, a template can be used as a trait if it // only contains blocks and use statements. - $traitable = !$this->hasNode('parent') && 0 === count($this->getNode('macros')); + $traitable = !$this->hasNode('parent') && 0 === \count($this->getNode('macros')); if ($traitable) { if ($this->getNode('body') instanceof Twig_Node_Body) { $nodes = $this->getNode('body')->getNode(0); @@ -368,12 +368,12 @@ class Twig_Node_Module extends Twig_Node $nodes = $this->getNode('body'); } - if (!count($nodes)) { + if (!\count($nodes)) { $nodes = new Twig_Node([$nodes]); } foreach ($nodes as $node) { - if (!count($node)) { + if (!\count($node)) { continue; } diff --git a/lib/Twig/Node/Set.php b/lib/Twig/Node/Set.php index 155cc4843..c1b5e95be 100644 --- a/lib/Twig/Node/Set.php +++ b/lib/Twig/Node/Set.php @@ -40,7 +40,7 @@ class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface { $compiler->addDebugInfo($this); - if (count($this->getNode('names')) > 1) { + if (\count($this->getNode('names')) > 1) { $compiler->write('list('); foreach ($this->getNode('names') as $idx => $node) { if ($idx) { @@ -68,7 +68,7 @@ class Twig_Node_Set extends Twig_Node implements Twig_NodeCaptureInterface if (!$this->getAttribute('capture')) { $compiler->raw(' = '); - if (count($this->getNode('names')) > 1) { + if (\count($this->getNode('names')) > 1) { $compiler->write('['); foreach ($this->getNode('values') as $idx => $value) { if ($idx) { diff --git a/lib/Twig/NodeVisitor/Escaper.php b/lib/Twig/NodeVisitor/Escaper.php index 5eb32ea1e..8c0365762 100644 --- a/lib/Twig/NodeVisitor/Escaper.php +++ b/lib/Twig/NodeVisitor/Escaper.php @@ -82,7 +82,7 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor return $node; } - $class = get_class($node); + $class = \get_class($node); return new $class( $this->getEscaperFilter($type, $expression), @@ -124,13 +124,13 @@ class Twig_NodeVisitor_Escaper extends Twig_BaseNodeVisitor $safe = $this->safeAnalysis->getSafe($expression); } - return in_array($type, $safe) || in_array('all', $safe); + return \in_array($type, $safe) || \in_array('all', $safe); } protected function needEscaping(Twig_Environment $env) { - if (count($this->statusStack)) { - return $this->statusStack[count($this->statusStack) - 1]; + if (\count($this->statusStack)) { + return $this->statusStack[\count($this->statusStack) - 1]; } return $this->defaultStrategy ? $this->defaultStrategy : false; diff --git a/lib/Twig/NodeVisitor/Optimizer.php b/lib/Twig/NodeVisitor/Optimizer.php index 382dfb30e..1950a5a6f 100644 --- a/lib/Twig/NodeVisitor/Optimizer.php +++ b/lib/Twig/NodeVisitor/Optimizer.php @@ -40,7 +40,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor */ public function __construct($optimizers = -1) { - if (!is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) { + if (!\is_int($optimizers) || $optimizers > (self::OPTIMIZE_FOR | self::OPTIMIZE_RAW_FILTER | self::OPTIMIZE_VAR_ACCESS)) { throw new \InvalidArgumentException(sprintf('Optimizer mode "%s" is not valid.', $optimizers)); } @@ -56,7 +56,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor if (PHP_VERSION_ID < 50400 && self::OPTIMIZE_VAR_ACCESS === (self::OPTIMIZE_VAR_ACCESS & $this->optimizers) && !$env->isStrictVariables() && !$env->hasExtension('Twig_Extension_Sandbox')) { if ($this->inABody) { if (!$node instanceof Twig_Node_Expression) { - if ('Twig_Node' !== get_class($node)) { + if ('Twig_Node' !== \get_class($node)) { array_unshift($this->prependedNodes, []); } } else { @@ -88,7 +88,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor if ($node instanceof Twig_Node_Body) { $this->inABody = false; } elseif ($this->inABody) { - if (!$expression && 'Twig_Node' !== get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) { + if (!$expression && 'Twig_Node' !== \get_class($node) && $prependedNodes = array_shift($this->prependedNodes)) { $nodes = []; foreach (array_unique($prependedNodes) as $name) { $nodes[] = new Twig_Node_SetTemp($name, $node->getTemplateLine()); @@ -105,7 +105,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor protected function optimizeVariables(Twig_NodeInterface $node, Twig_Environment $env) { - if ('Twig_Node_Expression_Name' === get_class($node) && $node->isSimple()) { + if ('Twig_Node_Expression_Name' === \get_class($node) && $node->isSimple()) { $this->prependedNodes[0][] = $node->getAttribute('name'); return new Twig_Node_Expression_TempName($node->getAttribute('name'), $node->getTemplateLine()); @@ -181,7 +181,7 @@ class Twig_NodeVisitor_Optimizer extends Twig_BaseNodeVisitor } // optimize access to loop targets - elseif ($node instanceof Twig_Node_Expression_Name && in_array($node->getAttribute('name'), $this->loopsTargets)) { + elseif ($node instanceof Twig_Node_Expression_Name && \in_array($node->getAttribute('name'), $this->loopsTargets)) { $node->setAttribute('always_defined', true); } diff --git a/lib/Twig/NodeVisitor/SafeAnalysis.php b/lib/Twig/NodeVisitor/SafeAnalysis.php index eff855b49..da77c2140 100644 --- a/lib/Twig/NodeVisitor/SafeAnalysis.php +++ b/lib/Twig/NodeVisitor/SafeAnalysis.php @@ -34,7 +34,7 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor continue; } - if (in_array('html_attr', $bucket['value'])) { + if (\in_array('html_attr', $bucket['value'])) { $bucket['value'][] = 'html'; } @@ -112,7 +112,7 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor } elseif ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name) { $name = $node->getNode('node')->getAttribute('name'); // attributes on template instances are safe - if ('_self' == $name || in_array($name, $this->safeVars)) { + if ('_self' == $name || \in_array($name, $this->safeVars)) { $this->setSafe($node, ['all']); } else { $this->setSafe($node, []); @@ -130,11 +130,11 @@ class Twig_NodeVisitor_SafeAnalysis extends Twig_BaseNodeVisitor return []; } - if (in_array('all', $a)) { + if (\in_array('all', $a)) { return $b; } - if (in_array('all', $b)) { + if (\in_array('all', $b)) { return $a; } diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index d182846fc..4aabcab04 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -159,12 +159,12 @@ class Twig_Parser implements Twig_ParserInterface throw new Twig_Error_Syntax('A block must start with a tag name.', $token->getLine(), $this->stream->getSourceContext()); } - if (null !== $test && call_user_func($test, $token)) { + if (null !== $test && \call_user_func($test, $token)) { if ($dropNeedle) { $this->stream->next(); } - if (1 === count($rv)) { + if (1 === \count($rv)) { return $rv[0]; } @@ -176,7 +176,7 @@ class Twig_Parser implements Twig_ParserInterface if (null !== $test) { $e = new Twig_Error_Syntax(sprintf('Unexpected "%s" tag', $token->getValue()), $token->getLine(), $this->stream->getSourceContext()); - if (is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { + if (\is_array($test) && isset($test[0]) && $test[0] instanceof Twig_TokenParserInterface) { $e->appendMessage(sprintf(' (expecting closing tag for the "%s" tag defined near line %s).', $test[0]->getTag(), $lineno)); } } else { @@ -200,7 +200,7 @@ class Twig_Parser implements Twig_ParserInterface } } - if (1 === count($rv)) { + if (1 === \count($rv)) { return $rv[0]; } @@ -234,7 +234,7 @@ class Twig_Parser implements Twig_ParserInterface public function peekBlockStack() { - return $this->blockStack[count($this->blockStack) - 1]; + return $this->blockStack[\count($this->blockStack) - 1]; } public function popBlockStack() @@ -290,7 +290,7 @@ class Twig_Parser implements Twig_ParserInterface } } - return in_array(strtolower($name), $this->reservedMacroNames); + return \in_array(strtolower($name), $this->reservedMacroNames); } public function addTrait($trait) @@ -300,7 +300,7 @@ class Twig_Parser implements Twig_ParserInterface public function hasTraits() { - return count($this->traits) > 0; + return \count($this->traits) > 0; } public function embedTemplate(Twig_Node_Module $template) @@ -326,7 +326,7 @@ class Twig_Parser implements Twig_ParserInterface public function isMainScope() { - return 1 === count($this->importedSymbols); + return 1 === \count($this->importedSymbols); } public function pushLocalScope() @@ -381,7 +381,7 @@ class Twig_Parser implements Twig_ParserInterface || (!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference && $node instanceof Twig_NodeOutputInterface) ) { - if (false !== strpos((string) $node, chr(0xEF).chr(0xBB).chr(0xBF))) { + if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { $t = substr($node->getAttribute('data'), 3); if ('' === $t || ctype_space($t)) { // bypass empty nodes starting with a BOM diff --git a/lib/Twig/Profiler/Dumper/Base.php b/lib/Twig/Profiler/Dumper/Base.php index 913afd4f0..8aeeeb773 100644 --- a/lib/Twig/Profiler/Dumper/Base.php +++ b/lib/Twig/Profiler/Dumper/Base.php @@ -49,7 +49,7 @@ abstract class Twig_Profiler_Dumper_Base $str = sprintf("%s %s\n", $start, $this->formatTime($profile, $percent)); } - $nCount = count($profile->getProfiles()); + $nCount = \count($profile->getProfiles()); foreach ($profile as $i => $p) { $str .= $this->dumpProfile($p, $prefix, $i + 1 !== $nCount); } diff --git a/lib/Twig/Sandbox/SecurityPolicy.php b/lib/Twig/Sandbox/SecurityPolicy.php index cf59117b9..cd24635da 100644 --- a/lib/Twig/Sandbox/SecurityPolicy.php +++ b/lib/Twig/Sandbox/SecurityPolicy.php @@ -47,7 +47,7 @@ class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterfac { $this->allowedMethods = []; foreach ($methods as $class => $m) { - $this->allowedMethods[$class] = array_map('strtolower', is_array($m) ? $m : [$m]); + $this->allowedMethods[$class] = array_map('strtolower', \is_array($m) ? $m : [$m]); } } @@ -64,19 +64,19 @@ class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterfac public function checkSecurity($tags, $filters, $functions) { foreach ($tags as $tag) { - if (!in_array($tag, $this->allowedTags)) { + if (!\in_array($tag, $this->allowedTags)) { throw new Twig_Sandbox_SecurityNotAllowedTagError(sprintf('Tag "%s" is not allowed.', $tag), $tag); } } foreach ($filters as $filter) { - if (!in_array($filter, $this->allowedFilters)) { + if (!\in_array($filter, $this->allowedFilters)) { throw new Twig_Sandbox_SecurityNotAllowedFilterError(sprintf('Filter "%s" is not allowed.', $filter), $filter); } } foreach ($functions as $function) { - if (!in_array($function, $this->allowedFunctions)) { + if (!\in_array($function, $this->allowedFunctions)) { throw new Twig_Sandbox_SecurityNotAllowedFunctionError(sprintf('Function "%s" is not allowed.', $function), $function); } } @@ -92,14 +92,14 @@ class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterfac $method = strtolower($method); foreach ($this->allowedMethods as $class => $methods) { if ($obj instanceof $class) { - $allowed = in_array($method, $methods); + $allowed = \in_array($method, $methods); break; } } if (!$allowed) { - $class = get_class($obj); + $class = \get_class($obj); throw new Twig_Sandbox_SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); } } @@ -109,14 +109,14 @@ class Twig_Sandbox_SecurityPolicy implements Twig_Sandbox_SecurityPolicyInterfac $allowed = false; foreach ($this->allowedProperties as $class => $properties) { if ($obj instanceof $class) { - $allowed = in_array($property, is_array($properties) ? $properties : [$properties]); + $allowed = \in_array($property, \is_array($properties) ? $properties : [$properties]); break; } } if (!$allowed) { - $class = get_class($obj); + $class = \get_class($obj); throw new Twig_Sandbox_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 5c4cfc567..a7787d77f 100644 --- a/lib/Twig/SimpleFilter.php +++ b/lib/Twig/SimpleFilter.php @@ -83,7 +83,7 @@ class Twig_SimpleFilter } if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $filterArgs); + return \call_user_func($this->options['is_safe_callback'], $filterArgs); } } diff --git a/lib/Twig/SimpleFunction.php b/lib/Twig/SimpleFunction.php index fbe06b991..35699e061 100644 --- a/lib/Twig/SimpleFunction.php +++ b/lib/Twig/SimpleFunction.php @@ -81,7 +81,7 @@ class Twig_SimpleFunction } if (null !== $this->options['is_safe_callback']) { - return call_user_func($this->options['is_safe_callback'], $functionArgs); + return \call_user_func($this->options['is_safe_callback'], $functionArgs); } return []; diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index fbc6ac8c3..196876747 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -351,7 +351,7 @@ abstract class Twig_Template implements Twig_TemplateInterface protected function loadTemplate($template, $templateName = null, $line = null, $index = null) { try { - if (is_array($template)) { + if (\is_array($template)) { return $this->env->resolveTemplate($template); } @@ -475,7 +475,7 @@ abstract class Twig_Template implements Twig_TemplateInterface */ final protected function getContext($context, $item, $ignoreStrictCheck = false) { - if (!array_key_exists($item, $context)) { + if (!\array_key_exists($item, $context)) { if ($ignoreStrictCheck || !$this->env->isStrictVariables()) { return; } @@ -506,9 +506,9 @@ abstract class Twig_Template implements Twig_TemplateInterface { // array if (self::METHOD_CALL !== $type) { - $arrayItem = is_bool($item) || is_float($item) ? (int) $item : $item; + $arrayItem = \is_bool($item) || \is_float($item) ? (int) $item : $item; - if (((is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || array_key_exists($arrayItem, $object))) + if (((\is_array($object) || $object instanceof \ArrayObject) && (isset($object[$arrayItem]) || \array_key_exists($arrayItem, $object))) || ($object instanceof ArrayAccess && isset($object[$arrayItem])) ) { if ($isDefinedTest) { @@ -518,7 +518,7 @@ abstract class Twig_Template implements Twig_TemplateInterface return $object[$arrayItem]; } - if (self::ARRAY_CALL === $type || !is_object($object)) { + if (self::ARRAY_CALL === $type || !\is_object($object)) { if ($isDefinedTest) { return false; } @@ -528,10 +528,10 @@ abstract class Twig_Template implements Twig_TemplateInterface } if ($object instanceof ArrayAccess) { - $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, get_class($object)); - } elseif (is_object($object)) { - $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, get_class($object)); - } elseif (is_array($object)) { + $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object)); + } elseif (\is_object($object)) { + $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, \get_class($object)); + } elseif (\is_array($object)) { if (empty($object)) { $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); } else { @@ -541,19 +541,19 @@ abstract class Twig_Template implements Twig_TemplateInterface if (null === $object) { $message = sprintf('Impossible to access a key ("%s") on a null variable.', $item); } else { - $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, gettype($object), $object); + $message = sprintf('Impossible to access a key ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } } elseif (null === $object) { $message = sprintf('Impossible to access an attribute ("%s") on a null variable.', $item); } else { - $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, gettype($object), $object); + $message = sprintf('Impossible to access an attribute ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } throw new Twig_Error_Runtime($message, -1, $this->getSourceContext()); } } - if (!is_object($object)) { + if (!\is_object($object)) { if ($isDefinedTest) { return false; } @@ -564,10 +564,10 @@ abstract class Twig_Template implements Twig_TemplateInterface if (null === $object) { $message = sprintf('Impossible to invoke a method ("%s") on a null variable.', $item); - } elseif (is_array($object)) { + } elseif (\is_array($object)) { $message = sprintf('Impossible to invoke a method ("%s") on an array.', $item); } else { - $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, gettype($object), $object); + $message = sprintf('Impossible to invoke a method ("%s") on a %s variable ("%s").', $item, \gettype($object), $object); } throw new Twig_Error_Runtime($message, -1, $this->getSourceContext()); @@ -575,7 +575,7 @@ abstract class Twig_Template implements Twig_TemplateInterface // object property if (self::METHOD_CALL !== $type && !$object instanceof self) { // Twig_Template does not have public properties, and we don't want to allow access to internal ones - if (isset($object->$item) || array_key_exists((string) $item, $object)) { + if (isset($object->$item) || \array_key_exists((string) $item, $object)) { if ($isDefinedTest) { return true; } @@ -588,7 +588,7 @@ abstract class Twig_Template implements Twig_TemplateInterface } } - $class = get_class($object); + $class = \get_class($object); // object method if (!isset(self::$cache[$class])) { @@ -672,7 +672,7 @@ abstract class Twig_Template implements Twig_TemplateInterface if (!$arguments) { $ret = $object->$method(); } else { - $ret = call_user_func_array([$object, $method], $arguments); + $ret = \call_user_func_array([$object, $method], $arguments); } } catch (\BadMethodCallException $e) { if ($call && ($ignoreStrictCheck || !$this->env->isStrictVariables())) { diff --git a/lib/Twig/TemplateWrapper.php b/lib/Twig/TemplateWrapper.php index 69a27600a..07ed715a3 100644 --- a/lib/Twig/TemplateWrapper.php +++ b/lib/Twig/TemplateWrapper.php @@ -42,7 +42,7 @@ final class Twig_TemplateWrapper { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code - return $this->template->render($context, func_num_args() > 1 ? func_get_arg(1) : []); + return $this->template->render($context, \func_num_args() > 1 ? func_get_arg(1) : []); } /** @@ -54,7 +54,7 @@ final class Twig_TemplateWrapper { // using func_get_args() allows to not expose the blocks argument // as it should only be used by internal code - $this->template->display($context, func_num_args() >= 1 ? func_get_arg(1) : []); + $this->template->display($context, \func_num_args() >= 1 ? func_get_arg(1) : []); } /** diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php index 565698790..a1b6efecf 100644 --- a/lib/Twig/Test/IntegrationTestCase.php +++ b/lib/Twig/Test/IntegrationTestCase.php @@ -180,28 +180,28 @@ abstract class Twig_Test_IntegrationTestCase extends TestCase } catch (\Exception $e) { if (false !== $exception) { $message = $e->getMessage(); - $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $message))); - $last = substr($message, strlen($message) - 1); + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message))); + $last = substr($message, \strlen($message) - 1); $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.'); return; } - throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); + throw new Twig_Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); } try { $output = trim($template->render(eval($match[1].';')), "\n "); } catch (\Exception $e) { if (false !== $exception) { - $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); + $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $e->getMessage()))); return; } - $e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); + $e = new Twig_Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, $file, $e); - $output = trim(sprintf('%s: %s', get_class($e), $e->getMessage())); + $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); } if (false !== $exception) { diff --git a/lib/Twig/Test/Method.php b/lib/Twig/Test/Method.php index 6949bb23b..25d5dfc71 100644 --- a/lib/Twig/Test/Method.php +++ b/lib/Twig/Test/Method.php @@ -35,6 +35,6 @@ class Twig_Test_Method extends Twig_Test public function compile() { - return sprintf('$this->env->getExtension(\'%s\')->%s', get_class($this->extension), $this->method); + return sprintf('$this->env->getExtension(\'%s\')->%s', \get_class($this->extension), $this->method); } } diff --git a/lib/Twig/Test/NodeTestCase.php b/lib/Twig/Test/NodeTestCase.php index a20fbbacd..083b3f2ea 100644 --- a/lib/Twig/Test/NodeTestCase.php +++ b/lib/Twig/Test/NodeTestCase.php @@ -62,7 +62,7 @@ abstract class Twig_Test_NodeTestCase extends TestCase protected function getAttributeGetter() { - if (function_exists('twig_template_get_attributes')) { + if (\function_exists('twig_template_get_attributes')) { return 'twig_template_get_attributes($this, '; } diff --git a/lib/Twig/Token.php b/lib/Twig/Token.php index fc0975f32..4faef4f56 100644 --- a/lib/Twig/Token.php +++ b/lib/Twig/Token.php @@ -69,14 +69,14 @@ class Twig_Token */ public function test($type, $values = null) { - if (null === $values && !is_int($type)) { + if (null === $values && !\is_int($type)) { $values = $type; $type = self::NAME_TYPE; } return ($this->type === $type) && ( null === $values || - (is_array($values) && in_array($this->value, $values)) || + (\is_array($values) && \in_array($this->value, $values)) || $this->value == $values ); } diff --git a/lib/Twig/TokenParser/For.php b/lib/Twig/TokenParser/For.php index 2f6862a06..bbbe24c46 100644 --- a/lib/Twig/TokenParser/For.php +++ b/lib/Twig/TokenParser/For.php @@ -46,7 +46,7 @@ class Twig_TokenParser_For extends Twig_TokenParser } $stream->expect(Twig_Token::BLOCK_END_TYPE); - if (count($targets) > 1) { + if (\count($targets) > 1) { $keyTarget = $targets->getNode(0); $keyTarget = new Twig_Node_Expression_AssignName($keyTarget->getAttribute('name'), $keyTarget->getTemplateLine()); $valueTarget = $targets->getNode(1); @@ -97,7 +97,7 @@ class Twig_TokenParser_For extends Twig_TokenParser { if ($node instanceof Twig_Node_Expression_GetAttr && $node->getNode('node') instanceof Twig_Node_Expression_Name && 'loop' == $node->getNode('node')->getAttribute('name')) { $attribute = $node->getNode('attribute'); - if ($attribute instanceof Twig_Node_Expression_Constant && in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { + if ($attribute instanceof Twig_Node_Expression_Constant && \in_array($attribute->getAttribute('value'), ['length', 'revindex0', 'revindex', 'last'])) { throw new Twig_Error_Syntax(sprintf('The "loop.%s" variable is not defined when looping with a condition.', $attribute->getAttribute('value')), $node->getTemplateLine(), $stream->getSourceContext()); } } diff --git a/lib/Twig/TokenParser/Set.php b/lib/Twig/TokenParser/Set.php index 86ee7877c..e60ee6c89 100644 --- a/lib/Twig/TokenParser/Set.php +++ b/lib/Twig/TokenParser/Set.php @@ -35,13 +35,13 @@ class Twig_TokenParser_Set extends Twig_TokenParser $stream->expect(Twig_Token::BLOCK_END_TYPE); - if (count($names) !== count($values)) { + if (\count($names) !== \count($values)) { throw new Twig_Error_Syntax('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) { + if (\count($names) > 1) { throw new Twig_Error_Syntax('When using set with a block, you cannot have a multi-target.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); } diff --git a/lib/Twig/TokenStream.php b/lib/Twig/TokenStream.php index 81c043ca9..73374908b 100644 --- a/lib/Twig/TokenStream.php +++ b/lib/Twig/TokenStream.php @@ -54,7 +54,7 @@ class Twig_TokenStream public function injectTokens(array $tokens) { - $this->tokens = array_merge(array_slice($this->tokens, 0, $this->current), $tokens, array_slice($this->tokens, $this->current)); + $this->tokens = array_merge(\array_slice($this->tokens, 0, $this->current), $tokens, \array_slice($this->tokens, $this->current)); } /** diff --git a/test/Twig/Tests/Cache/FilesystemTest.php b/test/Twig/Tests/Cache/FilesystemTest.php index 818e3ece0..806143eeb 100644 --- a/test/Twig/Tests/Cache/FilesystemTest.php +++ b/test/Twig/Tests/Cache/FilesystemTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -require_once dirname(__DIR__).'/FilesystemHelper.php'; +require_once \dirname(__DIR__).'/FilesystemHelper.php'; class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase { @@ -36,7 +36,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase { $key = $this->directory.'/cache/cachefile.php'; - $dir = dirname($key); + $dir = \dirname($key); @mkdir($dir, 0777, true); $this->assertTrue(is_dir($dir)); $this->assertFalse(class_exists($this->classname, false)); @@ -81,7 +81,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testWriteFailMkdir() { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('Read-only directories not possible on Windows.'); } @@ -103,7 +103,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase */ public function testWriteFailDirWritable() { - if (defined('PHP_WINDOWS_VERSION_BUILD')) { + if (\defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('Read-only directories not possible on Windows.'); } @@ -143,7 +143,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase { $key = $this->directory.'/cache/cachefile.php'; - $dir = dirname($key); + $dir = \dirname($key); @mkdir($dir, 0777, true); $this->assertTrue(is_dir($dir)); @@ -167,7 +167,7 @@ class Twig_Tests_Cache_FilesystemTest extends \PHPUnit\Framework\TestCase public function testGenerateKey($expected, $input) { $cache = new Twig_Cache_Filesystem($input); - $this->assertRegExp($expected, $cache->generateKey('_test_', get_class($this))); + $this->assertRegExp($expected, $cache->generateKey('_test_', \get_class($this))); } public function provideDirectories() diff --git a/test/Twig/Tests/EnvironmentTest.php b/test/Twig/Tests/EnvironmentTest.php index 97b48eb10..8c177755b 100644 --- a/test/Twig/Tests/EnvironmentTest.php +++ b/test/Twig/Tests/EnvironmentTest.php @@ -393,7 +393,7 @@ EOF $twig = new Twig_Environment($loader); $twig->addExtension($extension); - $this->assertInstanceOf('Twig_ExtensionInterface', $twig->getExtension(get_class($extension))); + $this->assertInstanceOf('Twig_ExtensionInterface', $twig->getExtension(\get_class($extension))); $this->assertTrue($twig->isTemplateFresh('page', time())); } diff --git a/test/Twig/Tests/Extension/CoreTest.php b/test/Twig/Tests/Extension/CoreTest.php index e19300e25..61f29099c 100644 --- a/test/Twig/Tests/Extension/CoreTest.php +++ b/test/Twig/Tests/Extension/CoreTest.php @@ -19,7 +19,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase $env = new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock()); for ($i = 0; $i < 100; ++$i) { - $this->assertTrue(in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type + $this->assertTrue(\in_array(twig_random($env, $value), $expectedInArray, true)); // assertContains() would not consider the type } } @@ -63,7 +63,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase for ($i = 0; $i < 100; ++$i) { $val = twig_random(new Twig_Environment($this->getMockBuilder('Twig_LoaderInterface')->getMock())); - $this->assertTrue(is_int($val) && $val >= 0 && $val <= $max); + $this->assertTrue(\is_int($val) && $val >= 0 && $val <= $max); } } @@ -86,7 +86,7 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase public function testRandomFunctionOnNonUTF8String() { - if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + if (!\function_exists('iconv') && !\function_exists('mb_convert_encoding')) { $this->markTestSkipped('needs iconv or mbstring'); } @@ -96,13 +96,13 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase $text = twig_convert_encoding('Äé', 'ISO-8859-1', 'UTF-8'); for ($i = 0; $i < 30; ++$i) { $rand = twig_random($twig, $text); - $this->assertTrue(in_array(twig_convert_encoding($rand, 'UTF-8', 'ISO-8859-1'), ['Ä', 'é'], true)); + $this->assertTrue(\in_array(twig_convert_encoding($rand, 'UTF-8', 'ISO-8859-1'), ['Ä', 'é'], true)); } } public function testReverseFilterOnNonUTF8String() { - if (!function_exists('iconv') && !function_exists('mb_convert_encoding')) { + if (!\function_exists('iconv') && !\function_exists('mb_convert_encoding')) { $this->markTestSkipped('needs iconv or mbstring'); } @@ -260,8 +260,8 @@ class Twig_Tests_Extension_CoreTest extends \PHPUnit\Framework\TestCase [[2, 3], [1, 2, 3, 4], 1, 2], [[2, 3], new CoreTestIterator($i, $keys, true), 1, 2], [['c' => 3, 'd' => 4], new CoreTestIteratorAggregate($i, $keys, true), 2, null, true], - [$i, new CoreTestIterator($i, $keys, true), 0, count($keys) + 10, true], - [[], new CoreTestIterator($i, $keys, true), count($keys) + 10], + [$i, new CoreTestIterator($i, $keys, true), 0, \count($keys) + 10, true], + [[], new CoreTestIterator($i, $keys, true), \count($keys) + 10], ['de', 'abcdef', 3, 2], [[], new \SimpleXMLElement('12'), 3], [[], new \ArrayIterator([1, 2]), 3], @@ -318,7 +318,7 @@ final class CoreTestIterator implements Iterator $this->arrayKeys = $keys; $this->position = 0; $this->allowValueAccess = $allowValueAccess; - $this->maxPosition = false === $maxPosition ? count($values) + 1 : $maxPosition; + $this->maxPosition = false === $maxPosition ? \count($values) + 1 : $maxPosition; } public function rewind() diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 1db144583..05dd264d4 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -35,7 +35,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase $node = $this->createFilter($expr, 'upper'); $node = $this->createFilter($node, 'number_format', [new Twig_Node_Expression_Constant(2, 1), new Twig_Node_Expression_Constant('.', 1), new Twig_Node_Expression_Constant(',', 1)]); - if (function_exists('mb_get_info')) { + if (\function_exists('mb_get_info')) { $tests[] = [$node, 'twig_number_format_filter($this->env, twig_upper_filter($this->env, "foo"), 2, ".", ",")']; } else { $tests[] = [$node, 'twig_number_format_filter($this->env, strtoupper("foo"), 2, ".", ",")']; diff --git a/test/Twig/Tests/Node/ForTest.php b/test/Twig/Tests/Node/ForTest.php index 20955c9ec..dadcf090f 100644 --- a/test/Twig/Tests/Node/ForTest.php +++ b/test/Twig/Tests/Node/ForTest.php @@ -26,7 +26,7 @@ class Twig_Tests_Node_ForTest extends Twig_Test_NodeTestCase $this->assertEquals($valueTarget, $node->getNode('value_target')); $this->assertEquals($seq, $node->getNode('seq')); $this->assertTrue($node->getAttribute('ifexpr')); - $this->assertEquals('Twig_Node_If', get_class($node->getNode('body'))); + $this->assertEquals('Twig_Node_If', \get_class($node->getNode('body'))); $this->assertEquals($body, $node->getNode('body')->getNode('tests')->getNode(1)->getNode(0)); $this->assertFalse($node->hasNode('else')); diff --git a/test/Twig/Tests/NodeVisitor/OptimizerTest.php b/test/Twig/Tests/NodeVisitor/OptimizerTest.php index 1d3a6341f..cbf72ff12 100644 --- a/test/Twig/Tests/NodeVisitor/OptimizerTest.php +++ b/test/Twig/Tests/NodeVisitor/OptimizerTest.php @@ -18,7 +18,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase $node = $stream->getNode('body')->getNode(0); - $this->assertEquals('Twig_Node_Expression_BlockReference', get_class($node)); + $this->assertEquals('Twig_Node_Expression_BlockReference', \get_class($node)); $this->assertTrue($node->getAttribute('output')); } @@ -30,7 +30,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase $node = $stream->getNode('blocks')->getNode('content')->getNode(0)->getNode('body'); - $this->assertEquals('Twig_Node_Expression_Parent', get_class($node)); + $this->assertEquals('Twig_Node_Expression_Parent', \get_class($node)); $this->assertTrue($node->getAttribute('output')); } @@ -45,7 +45,7 @@ class Twig_Tests_NodeVisitor_OptimizerTest extends \PHPUnit\Framework\TestCase $node = $stream->getNode('body')->getNode(0)->getNode(1); - $this->assertEquals('Twig_Node_Expression_BlockReference', get_class($node)); + $this->assertEquals('Twig_Node_Expression_BlockReference', \get_class($node)); $this->assertTrue($node->getAttribute('output')); } diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 5a8611ffc..2180200b7 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -103,7 +103,7 @@ class Twig_Tests_ParserTest extends \PHPUnit\Framework\TestCase */ public function testFilterBodyNodesWithBOM($emptyNode) { - $this->assertNull($this->getParser()->filterBodyNodes(new Twig_Node_Text(chr(0xEF).chr(0xBB).chr(0xBF).$emptyNode, 1))); + $this->assertNull($this->getParser()->filterBodyNodes(new Twig_Node_Text(\chr(0xEF).\chr(0xBB).\chr(0xBF).$emptyNode, 1))); } public function getFilterBodyNodesWithBOMData() diff --git a/test/Twig/Tests/TemplateTest.php b/test/Twig/Tests/TemplateTest.php index 9df09e346..69fe0475b 100644 --- a/test/Twig/Tests/TemplateTest.php +++ b/test/Twig/Tests/TemplateTest.php @@ -499,7 +499,7 @@ class Twig_TemplateTest extends Twig_Template public function getAttribute($object, $item, array $arguments = [], $type = Twig_Template::ANY_CALL, $isDefinedTest = false, $ignoreStrictCheck = false) { - if (function_exists('twig_template_get_attributes')) { + if (\function_exists('twig_template_get_attributes')) { return twig_template_get_attributes($this, $object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); } else { return parent::getAttribute($object, $item, $arguments, $type, $isDefinedTest, $ignoreStrictCheck); @@ -528,12 +528,12 @@ class Twig_TemplateArrayAccessObject implements ArrayAccess public function offsetExists($name) { - return array_key_exists($name, $this->attributes); + return \array_key_exists($name, $this->attributes); } public function offsetGet($name) { - return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; + return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; } public function offsetSet($name, $value) @@ -563,12 +563,12 @@ class Twig_TemplateMagicPropertyObject public function __isset($name) { - return array_key_exists($name, $this->attributes); + return \array_key_exists($name, $this->attributes); } public function __get($name) { - return array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; + return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; } } @@ -613,7 +613,7 @@ class Twig_TemplatePropertyObjectAndArrayAccess extends Twig_TemplatePropertyObj public function offsetExists($offset) { - return array_key_exists($offset, $this->data); + return \array_key_exists($offset, $this->data); } public function offsetGet($offset) @@ -736,7 +736,7 @@ class Twig_TemplateArrayAccess implements ArrayAccess public function offsetExists($offset) { - return array_key_exists($offset, $this->children); + return \array_key_exists($offset, $this->children); } public function offsetGet($offset) diff --git a/test/Twig/Tests/escapingTest.php b/test/Twig/Tests/escapingTest.php index 66e3b7d11..7bbd92cfe 100644 --- a/test/Twig/Tests/escapingTest.php +++ b/test/Twig/Tests/escapingTest.php @@ -238,22 +238,22 @@ class Twig_Test_EscapingTest extends \PHPUnit\Framework\TestCase protected function codepointToUtf8($codepoint) { if ($codepoint < 0x80) { - return chr($codepoint); + return \chr($codepoint); } if ($codepoint < 0x800) { - return chr($codepoint >> 6 & 0x3f | 0xc0) - .chr($codepoint & 0x3f | 0x80); + return \chr($codepoint >> 6 & 0x3f | 0xc0) + .\chr($codepoint & 0x3f | 0x80); } if ($codepoint < 0x10000) { - return chr($codepoint >> 12 & 0x0f | 0xe0) - .chr($codepoint >> 6 & 0x3f | 0x80) - .chr($codepoint & 0x3f | 0x80); + return \chr($codepoint >> 12 & 0x0f | 0xe0) + .\chr($codepoint >> 6 & 0x3f | 0x80) + .\chr($codepoint & 0x3f | 0x80); } if ($codepoint < 0x110000) { - return chr($codepoint >> 18 & 0x07 | 0xf0) - .chr($codepoint >> 12 & 0x3f | 0x80) - .chr($codepoint >> 6 & 0x3f | 0x80) - .chr($codepoint & 0x3f | 0x80); + return \chr($codepoint >> 18 & 0x07 | 0xf0) + .\chr($codepoint >> 12 & 0x3f | 0x80) + .\chr($codepoint >> 6 & 0x3f | 0x80) + .\chr($codepoint & 0x3f | 0x80); } throw new \Exception('Codepoint requested outside of Unicode range.'); } @@ -269,7 +269,7 @@ class Twig_Test_EscapingTest extends \PHPUnit\Framework\TestCase $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'js')); } else { $literal = $this->codepointToUtf8($chr); - if (in_array($literal, $immune)) { + if (\in_array($literal, $immune)) { $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'js')); } else { $this->assertNotEquals( @@ -292,7 +292,7 @@ class Twig_Test_EscapingTest extends \PHPUnit\Framework\TestCase $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'html_attr')); } else { $literal = $this->codepointToUtf8($chr); - if (in_array($literal, $immune)) { + if (\in_array($literal, $immune)) { $this->assertEquals($literal, twig_escape_filter($this->env, $literal, 'html_attr')); } else { $this->assertNotEquals(