diff --git a/extra/markdown-extra/MarkdownExtension.php b/extra/markdown-extra/MarkdownExtension.php index 8f249ce6d86..6c4296bbf1b 100644 --- a/extra/markdown-extra/MarkdownExtension.php +++ b/extra/markdown-extra/MarkdownExtension.php @@ -34,7 +34,7 @@ function twig_html_to_markdown(string $body, array $options = []): string throw new \LogicException('You cannot use the "html_to_markdown" filter as league/html-to-markdown is not installed; try running "composer require league/html-to-markdown".'); } - $options = $options + [ + $options += [ 'hard_break' => true, 'strip_tags' => true, 'remove_nodes' => 'head style', diff --git a/extra/markdown-extra/Tests/FunctionalTest.php b/extra/markdown-extra/Tests/FunctionalTest.php index 368a0467b3b..42f4ff65a97 100644 --- a/extra/markdown-extra/Tests/FunctionalTest.php +++ b/extra/markdown-extra/Tests/FunctionalTest.php @@ -29,7 +29,7 @@ class FunctionalTest extends TestCase */ public function testMarkdown(string $template, string $expected): void { - foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /*MichelfMarkdown::class,*/ DefaultMarkdown::class] as $class) { + foreach ([LeagueMarkdown::class, ErusevMarkdown::class, /* MichelfMarkdown::class, */ DefaultMarkdown::class] as $class) { $twig = new Environment(new ArrayLoader([ 'index' => $template, 'html' => <<isConfigEnabled($container, $config[$extension])) { $loader->load($extension.'.php'); - if ('markdown' === $extension && \class_exists(CommonMarkConverter::class)) { + if ('markdown' === $extension && class_exists(CommonMarkConverter::class)) { $loader->load('markdown_league.php'); } } diff --git a/extra/twig-extra-bundle/Tests/Fixture/Kernel.php b/extra/twig-extra-bundle/Tests/Fixture/Kernel.php index cbc9c4bd850..3df6357fe1f 100644 --- a/extra/twig-extra-bundle/Tests/Fixture/Kernel.php +++ b/extra/twig-extra-bundle/Tests/Fixture/Kernel.php @@ -4,11 +4,11 @@ use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; +use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Symfony\Bundle\TwigBundle\TwigBundle; use Symfony\Component\Config\Loader\LoaderInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Kernel as BaseKernel; -use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; use Twig\Extra\TwigExtraBundle\TwigExtraBundle; class Kernel extends BaseKernel diff --git a/src/Cache/FilesystemCache.php b/src/Cache/FilesystemCache.php index e075563aef6..4024adbd70d 100644 --- a/src/Cache/FilesystemCache.php +++ b/src/Cache/FilesystemCache.php @@ -63,7 +63,7 @@ public function write(string $key, string $content): void if (self::FORCE_BYTECODE_INVALIDATION == ($this->options & self::FORCE_BYTECODE_INVALIDATION)) { // Compile cached file into bytecode cache - if (\function_exists('opcache_invalidate') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) { + if (\function_exists('opcache_invalidate') && filter_var(\ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN)) { @opcache_invalidate($key, true); } elseif (\function_exists('apc_compile_file')) { apc_compile_file($key); diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index 38347cb391d..f69ce6c7f16 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -624,7 +624,7 @@ public function parseArguments($namedArguments = false, $definition = false, $al $name = null; if ($namedArguments && $token = $stream->nextIf(/* Token::OPERATOR_TYPE */ 8, '=')) { if (!$value instanceof NameExpression) { - throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', \get_class($value)), $token->getLine(), $stream->getSourceContext()); + throw new SyntaxError(sprintf('A parameter name must be a string, "%s" given.', $value::class), $token->getLine(), $stream->getSourceContext()); } $name = $value->getAttribute('name'); diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index 0f1a10216f3..f65c850917f 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -343,9 +343,9 @@ function twig_cycle($values, $position) * @param \Traversable|array|int|float|string $values The values to pick a random item from * @param int|null $max Maximum value used when $values is an int * - * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) - * * @return mixed A random value from the given sequence + * + * @throws RuntimeError when $values is an empty array (does not apply to an empty string which is returned as is) */ function twig_random(Environment $env, $values = null, $max = null) { @@ -530,7 +530,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null) function twig_replace_filter($str, $from) { if (!twig_test_iterable($from)) { - throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); + throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? $from::class : \gettype($from))); } return strtr($str ?? '', twig_to_array($from)); @@ -768,7 +768,7 @@ function twig_split_filter(Environment $env, $value, $delimiter, $limit = null) { $value = $value ?? ''; - if (\strlen($delimiter) > 0) { + if ('' !== $delimiter) { return null === $limit ? explode($delimiter, $value) : explode($delimiter, $value, $limit); } @@ -1022,9 +1022,6 @@ function twig_compare($a, $b) } /** - * @param string $pattern - * @param string|null $subject - * * @return int * * @throws RuntimeError When an invalid pattern is used @@ -1123,7 +1120,7 @@ function twig_length_filter(Environment $env, $thing) return 0; } - if (is_scalar($thing)) { + if (\is_scalar($thing)) { return mb_strlen($thing, $env->getCharset()); } @@ -1386,10 +1383,10 @@ function twig_constant($constant, $object = null) { if (null !== $object) { if ('class' === $constant) { - return \get_class($object); + return $object::class; } - $constant = \get_class($object).'::'.$constant; + $constant = $object::class.'::'.$constant; } if (!\defined($constant)) { @@ -1414,7 +1411,7 @@ function twig_constant_is_defined($constant, $object = null) return true; } - $constant = \get_class($object).'::'.$constant; + $constant = $object::class.'::'.$constant; } return \defined($constant); @@ -1432,7 +1429,7 @@ function twig_constant_is_defined($constant, $object = null) function twig_array_batch($items, $size, $fill = null, $preserveKeys = true) { if (!twig_test_iterable($items)) { - throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); + throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? $items::class : \gettype($items))); } $size = ceil($size); @@ -1494,9 +1491,9 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar } if ($object instanceof ArrayAccess) { - $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, \get_class($object)); + $message = sprintf('Key "%s" in object with ArrayAccess of class "%s" does not exist.', $arrayItem, $object::class); } 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)); + $message = sprintf('Impossible to access a key "%s" on an object of class "%s" that does not implement ArrayAccess interface.', $item, $object::class); } elseif (\is_array($object)) { if (empty($object)) { $message = sprintf('Key "%s" does not exist as the array is empty.', $arrayItem); @@ -1560,7 +1557,7 @@ function twig_get_attribute(Environment $env, Source $source, $object, $item, ar static $cache = []; - $class = \get_class($object); + $class = $object::class; // object method // precedence: getXxx() > isXxx() > hasXxx() @@ -1676,7 +1673,7 @@ function twig_array_column($array, $name, $index = null): array function twig_array_filter(Environment $env, $array, $arrow) { if (!twig_test_iterable($array)) { - throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array))); + throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? $array::class : \gettype($array))); } twig_check_arrow_in_sandbox($env, $arrow, 'filter', 'filter'); diff --git a/src/Extension/DebugExtension.php b/src/Extension/DebugExtension.php index bfb23d7bd4f..c0f10d5a303 100644 --- a/src/Extension/DebugExtension.php +++ b/src/Extension/DebugExtension.php @@ -19,10 +19,10 @@ public function getFunctions(): array // dump is safe if var_dump is overridden by 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 === \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 // xdebug.overload_var_dump produces HTML only when html_errors is also enabled - && (false === ini_get('html_errors') || ini_get('html_errors')) + && (false === \ini_get('html_errors') || \ini_get('html_errors')) || 'cli' === \PHP_SAPI ; diff --git a/src/Extension/EscaperExtension.php b/src/Extension/EscaperExtension.php index 9d2251dc6e1..90dd5023ad1 100644 --- a/src/Extension/EscaperExtension.php +++ b/src/Extension/EscaperExtension.php @@ -172,7 +172,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char if (!\is_string($string)) { if (\is_object($string) && method_exists($string, '__toString')) { if ($autoescape) { - $c = \get_class($string); + $c = $string::class; $ext = $env->getExtension(EscaperExtension::class); if (!isset($ext->safeClasses[$c])) { $ext->safeClasses[$c] = []; @@ -341,7 +341,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char * The following replaces characters undefined in HTML with the * hex entity for the Unicode replacement character. */ - if (($ord <= 0x1f && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7f && $ord <= 0x9f)) { + if (($ord <= 0x1F && "\t" != $chr && "\n" != $chr && "\r" != $chr) || ($ord >= 0x7F && $ord <= 0x9F)) { return '�'; } @@ -388,7 +388,7 @@ function twig_escape_filter(Environment $env, $string, $strategy = 'html', $char default: $escapers = $env->getExtension(EscaperExtension::class)->getEscapers(); - if (array_key_exists($strategy, $escapers)) { + if (\array_key_exists($strategy, $escapers)) { return $escapers[$strategy]($env, $string, $charset); } diff --git a/src/ExtensionSet.php b/src/ExtensionSet.php index d32200ceb51..f7ecd074651 100644 --- a/src/ExtensionSet.php +++ b/src/ExtensionSet.php @@ -122,7 +122,7 @@ public function getLastModified(): int public function addExtension(ExtensionInterface $extension): void { - $class = \get_class($extension); + $class = $extension::class; if ($this->initialized) { throw new \LogicException(sprintf('Unable to register extension "%s" as extensions have already been initialized.', $class)); @@ -330,7 +330,7 @@ public function getGlobals(): array $extGlobals = $extension->getGlobals(); if (!\is_array($extGlobals)) { - throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', \get_class($extension))); + throw new \UnexpectedValueException(sprintf('"%s::getGlobals()" must return an array of globals.', $extension::class)); } $globals = array_merge($globals, $extGlobals); @@ -466,11 +466,11 @@ private function initExtension(ExtensionInterface $extension): void // 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))); + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array with operators, got "%s".', $extension::class, \is_object($operators) ? $operators::class : \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))); + throw new \InvalidArgumentException(sprintf('"%s::getOperators()" must return an array of 2 elements, got %d.', $extension::class, \count($operators))); } $this->unaryOperators = array_merge($this->unaryOperators, $operators[0]); diff --git a/src/Lexer.php b/src/Lexer.php index 6c45efbc9f6..5a6258c2c96 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -422,7 +422,7 @@ private function lexString(): void $this->pushToken(/* Token::INTERPOLATION_START_TYPE */ 10); $this->moveCursor($match[0]); $this->pushState(self::STATE_INTERPOLATION); - } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && \strlen($match[0]) > 0) { + } elseif (preg_match(self::REGEX_DQ_STRING_PART, $this->code, $match, 0, $this->cursor) && '' !== $match[0]) { $this->pushToken(/* Token::STRING_TYPE */ 7, stripcslashes($match[0])); $this->moveCursor($match[0]); } elseif (preg_match(self::REGEX_DQ_STRING_DELIM, $this->code, $match, 0, $this->cursor)) { diff --git a/src/Loader/ChainLoader.php b/src/Loader/ChainLoader.php index fbf4f3a0654..210ec174b95 100644 --- a/src/Loader/ChainLoader.php +++ b/src/Loader/ChainLoader.php @@ -92,7 +92,7 @@ public function getCacheKey(string $name): string try { return $loader->getCacheKey($name); } catch (LoaderError $e) { - $exceptions[] = \get_class($loader).': '.$e->getMessage(); + $exceptions[] = $loader::class.': '.$e->getMessage(); } } @@ -110,7 +110,7 @@ public function isFresh(string $name, int $time): bool try { return $loader->isFresh($name, $time); } catch (LoaderError $e) { - $exceptions[] = \get_class($loader).': '.$e->getMessage(); + $exceptions[] = $loader::class.': '.$e->getMessage(); } } diff --git a/src/Markup.php b/src/Markup.php index 1788acc4f73..231a29b4121 100644 --- a/src/Markup.php +++ b/src/Markup.php @@ -41,9 +41,6 @@ public function count() return mb_strlen($this->content, $this->charset); } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function jsonSerialize() { diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index 11a6b1abcae..3d2bcb41652 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -303,7 +303,7 @@ private function reflectCallable($callable) if ($object = $r->getClosureThis()) { $callable = [$object, $r->name]; - $callableName = (\function_exists('get_debug_type') ? get_debug_type($object) : \get_class($object)).'::'.$r->name; + $callableName = (\function_exists('get_debug_type') ? get_debug_type($object) : $object::class).'::'.$r->name; } elseif (\PHP_VERSION_ID >= 80111 && $class = $r->getClosureCalledClass()) { $callableName = $class->name.'::'.$r->name; } elseif (\PHP_VERSION_ID < 80111 && $class = $r->getClosureScopeClass()) { diff --git a/src/Node/Node.php b/src/Node/Node.php index c0558b9afdc..9d207362518 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -40,7 +40,7 @@ public function __construct(array $nodes = [], array $attributes = [], int $line { foreach ($nodes as $name => $node) { if (!$node instanceof self) { - throw new \InvalidArgumentException(sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? \get_class($node) : (null === $node ? 'null' : \gettype($node)), $name, static::class)); + throw new \InvalidArgumentException(sprintf('Using "%s" for the value of node "%s" of "%s" is not supported. You must pass a \Twig\Node\Node instance.', \is_object($node) ? $node::class : (null === $node ? 'null' : \gettype($node)), $name, static::class)); } } $this->nodes = $nodes; diff --git a/src/NodeVisitor/EscaperNodeVisitor.php b/src/NodeVisitor/EscaperNodeVisitor.php index fe56ea30741..f7ed51b2e8a 100644 --- a/src/NodeVisitor/EscaperNodeVisitor.php +++ b/src/NodeVisitor/EscaperNodeVisitor.php @@ -141,7 +141,7 @@ private function escapePrintNode(PrintNode $node, Environment $env, string $type return $node; } - $class = \get_class($node); + $class = $node::class; return new $class($this->getEscaperFilter($type, $expression), $node->getTemplateLine()); } diff --git a/src/NodeVisitor/MacroAutoImportNodeVisitor.php b/src/NodeVisitor/MacroAutoImportNodeVisitor.php index af477e65356..d6a7781ba27 100644 --- a/src/NodeVisitor/MacroAutoImportNodeVisitor.php +++ b/src/NodeVisitor/MacroAutoImportNodeVisitor.php @@ -50,10 +50,10 @@ public function leaveNode(Node $node, Environment $env): Node } } elseif ($this->inAModule) { if ( - $node instanceof GetAttrExpression && - $node->getNode('node') instanceof NameExpression && - '_self' === $node->getNode('node')->getAttribute('name') && - $node->getNode('attribute') instanceof ConstantExpression + $node instanceof GetAttrExpression + && $node->getNode('node') instanceof NameExpression + && '_self' === $node->getNode('node')->getAttribute('name') + && $node->getNode('attribute') instanceof ConstantExpression ) { $this->hasMacroCalls = true; diff --git a/src/NodeVisitor/OptimizerNodeVisitor.php b/src/NodeVisitor/OptimizerNodeVisitor.php index 7ac75e41ad3..d9c23ff0ec0 100644 --- a/src/NodeVisitor/OptimizerNodeVisitor.php +++ b/src/NodeVisitor/OptimizerNodeVisitor.php @@ -99,8 +99,8 @@ private function optimizePrintNode(Node $node, Environment $env): Node $exprNode = $node->getNode('expr'); if ( - $exprNode instanceof BlockReferenceExpression || - $exprNode instanceof ParentExpression + $exprNode instanceof BlockReferenceExpression + || $exprNode instanceof ParentExpression ) { $exprNode->setAttribute('output', true); @@ -166,7 +166,7 @@ private function enterOptimizeFor(Node $node, Environment $env): void && 'include' === $node->getAttribute('name') && (!$node->getNode('arguments')->hasNode('with_context') || false !== $node->getNode('arguments')->getNode('with_context')->getAttribute('value') - ) + ) ) { $this->addLoopToAll(); } @@ -175,12 +175,12 @@ private function enterOptimizeFor(Node $node, Environment $env): void elseif ($node instanceof GetAttrExpression && (!$node->getNode('attribute') instanceof ConstantExpression || 'parent' === $node->getNode('attribute')->getAttribute('value') - ) + ) && (true === $this->loops[0]->getAttribute('with_loop') - || ($node->getNode('node') instanceof NameExpression - && 'loop' === $node->getNode('node')->getAttribute('name') - ) - ) + || ($node->getNode('node') instanceof NameExpression + && 'loop' === $node->getNode('node')->getAttribute('name') + ) + ) ) { $this->addLoopToAll(); } diff --git a/src/Parser.php b/src/Parser.php index 4428208fed3..22f334ea830 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -303,8 +303,7 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node // check that the body does not contain non-empty output nodes if ( ($node instanceof TextNode && !ctype_space($node->getAttribute('data'))) - || - (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface) + || (!$node instanceof TextNode && !$node instanceof BlockReferenceNode && $node instanceof NodeOutputInterface) ) { if (false !== strpos((string) $node, \chr(0xEF).\chr(0xBB).\chr(0xBF))) { $t = substr($node->getAttribute('data'), 3); @@ -336,7 +335,7 @@ private function filterBodyNodes(Node $node, bool $nested = false): ?Node // here, $nested means "being at the root level of a child template" // we need to discard the wrapping "Node" for the "body" node - $nested = $nested || Node::class !== \get_class($node); + $nested = $nested || Node::class !== $node::class; foreach ($node as $k => $n) { if (null !== $n && null === $this->filterBodyNodes($n, $nested)) { $node->removeNode($k); diff --git a/src/Sandbox/SecurityPolicy.php b/src/Sandbox/SecurityPolicy.php index 2fc0d01318a..1f23332b78a 100644 --- a/src/Sandbox/SecurityPolicy.php +++ b/src/Sandbox/SecurityPolicy.php @@ -102,7 +102,7 @@ public function checkMethodAllowed($obj, $method): void } if (!$allowed) { - $class = \get_class($obj); + $class = $obj::class; throw new SecurityNotAllowedMethodError(sprintf('Calling "%s" method on a "%s" object is not allowed.', $method, $class), $class, $method); } } @@ -119,7 +119,7 @@ public function checkPropertyAllowed($obj, $property): void } if (!$allowed) { - $class = \get_class($obj); + $class = $obj::class; throw new SecurityNotAllowedPropertyError(sprintf('Calling "%s" property on a "%s" object is not allowed.', $property, $class), $class, $property); } } diff --git a/src/Test/IntegrationTestCase.php b/src/Test/IntegrationTestCase.php index 307302bb624..b7ec98637cb 100644 --- a/src/Test/IntegrationTestCase.php +++ b/src/Test/IntegrationTestCase.php @@ -84,6 +84,7 @@ public function testIntegration($file, $message, $condition, $templates, $except /** * @dataProvider getLegacyTests + * * @group legacy */ public function testLegacyIntegration($file, $message, $condition, $templates, $exception, $outputs, $deprecation = '') @@ -204,14 +205,14 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e } catch (\Exception $e) { if (false !== $exception) { $message = $e->getMessage(); - $this->assertSame(trim($exception), trim(sprintf('%s: %s', \get_class($e), $message))); + $this->assertSame(trim($exception), trim(sprintf('%s: %s', $e::class, $message))); $last = substr($message, \strlen($message) - 1); $this->assertTrue('.' === $last || '?' === $last, 'Exception message must end with a dot or a question mark.'); return; } - throw new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + throw new Error(sprintf('%s: %s', $e::class, $e->getMessage()), -1, null, $e); } finally { restore_error_handler(); } @@ -222,14 +223,14 @@ protected function doIntegrationTest($file, $message, $condition, $templates, $e $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', $e::class, $e->getMessage()))); return; } - $e = new Error(sprintf('%s: %s', \get_class($e), $e->getMessage()), -1, null, $e); + $e = new Error(sprintf('%s: %s', $e::class, $e->getMessage()), -1, null, $e); - $output = trim(sprintf('%s: %s', \get_class($e), $e->getMessage())); + $output = trim(sprintf('%s: %s', $e::class, $e->getMessage())); } if (false !== $exception) { @@ -257,7 +258,7 @@ protected static function parseTemplates($test) $templates = []; preg_match_all('/--TEMPLATE(?:\((.*?)\))?--(.*?)(?=\-\-TEMPLATE|$)/s', $test, $matches, \PREG_SET_ORDER); foreach ($matches as $match) { - $templates[($match[1] ?: 'index.twig')] = $match[2]; + $templates[$match[1] ?: 'index.twig'] = $match[2]; } return $templates; diff --git a/src/Token.php b/src/Token.php index fd1a89d2adc..59279b8fe7c 100644 --- a/src/Token.php +++ b/src/Token.php @@ -68,9 +68,9 @@ public function test($type, $values = null): bool } return ($this->type === $type) && ( - null === $values || - (\is_array($values) && \in_array($this->value, $values)) || - $this->value == $values + null === $values + || (\is_array($values) && \in_array($this->value, $values)) + || $this->value == $values ); } diff --git a/src/TokenParser/FromTokenParser.php b/src/TokenParser/FromTokenParser.php index 35098c267b1..31b6cde4148 100644 --- a/src/TokenParser/FromTokenParser.php +++ b/src/TokenParser/FromTokenParser.php @@ -32,7 +32,7 @@ public function parse(Token $token): Node $stream->expect(/* Token::NAME_TYPE */ 5, 'import'); $targets = []; - do { + while (true) { $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); $alias = $name; @@ -45,7 +45,7 @@ public function parse(Token $token): Node if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { break; } - } while (true); + } $stream->expect(/* Token::BLOCK_END_TYPE */ 3); diff --git a/src/TokenParser/UseTokenParser.php b/src/TokenParser/UseTokenParser.php index d0a2de41a2e..3cdbb98ad01 100644 --- a/src/TokenParser/UseTokenParser.php +++ b/src/TokenParser/UseTokenParser.php @@ -43,7 +43,7 @@ public function parse(Token $token): Node $targets = []; if ($stream->nextIf('with')) { - do { + while (true) { $name = $stream->expect(/* Token::NAME_TYPE */ 5)->getValue(); $alias = $name; @@ -56,7 +56,7 @@ public function parse(Token $token): Node if (!$stream->nextIf(/* Token::PUNCTUATION_TYPE */ 9, ',')) { break; } - } while (true); + } } $stream->expect(/* Token::BLOCK_END_TYPE */ 3); diff --git a/src/Util/TemplateDirIterator.php b/src/Util/TemplateDirIterator.php index 3bef14beec3..8125341bd81 100644 --- a/src/Util/TemplateDirIterator.php +++ b/src/Util/TemplateDirIterator.php @@ -16,18 +16,12 @@ */ class TemplateDirIterator extends \IteratorIterator { - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function current() { return file_get_contents(parent::current()); } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function key() { diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index b22fdf42450..549b40e41e2 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -301,7 +301,7 @@ public function testAddMockExtension() $twig = new Environment($loader); $twig->addExtension($extension); - $this->assertInstanceOf(ExtensionInterface::class, $twig->getExtension(\get_class($extension))); + $this->assertInstanceOf(ExtensionInterface::class, $twig->getExtension($extension::class)); $this->assertTrue($twig->isTemplateFresh('page', time())); } diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index 29a799b8103..431517f6b21 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -380,9 +380,6 @@ public function rewind(): void $this->position = 0; } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function current() { @@ -393,9 +390,6 @@ public function current() throw new \LogicException('Code should only use the keys, not the values provided by iterator.'); } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function key() { diff --git a/tests/Extension/EscaperTest.php b/tests/Extension/EscaperTest.php index 9804feaa5c7..7c558c3ac1d 100644 --- a/tests/Extension/EscaperTest.php +++ b/tests/Extension/EscaperTest.php @@ -189,10 +189,10 @@ public function testJavascriptEscapingConvertsSpecialCharsWithInternalEncoding() try { mb_internal_encoding('ISO-8859-1'); foreach ($this->jsSpecialChars as $key => $value) { - $this->assertEquals($value, twig_escape_filter($twig, $key, 'js'), 'Failed to escape: ' . $key); + $this->assertEquals($value, twig_escape_filter($twig, $key, 'js'), 'Failed to escape: '.$key); } } finally { - if ($previousInternalEncoding !== false) { + if (false !== $previousInternalEncoding) { mb_internal_encoding($previousInternalEncoding); } } @@ -249,7 +249,7 @@ public function testUrlEscapingConvertsSpecialChars() public function testUnicodeCodepointConversionToUtf8() { $expected = ' ~ޙ'; - $codepoints = [0x20, 0x7e, 0x799]; + $codepoints = [0x20, 0x7E, 0x799]; $result = ''; foreach ($codepoints as $value) { $result .= $this->codepointToUtf8($value); @@ -270,19 +270,19 @@ protected function codepointToUtf8($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.'); } diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index 893bda345e8..aa24d5fbe8f 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -105,18 +105,12 @@ public function rewind(): void $this->position = 0; } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function current() { return $this->array[$this->position]; } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function key() { @@ -371,9 +365,6 @@ class SimpleIteratorForTesting implements \Iterator private $data = [1, 2, 3, 4, 5, 6, 7]; private $key = 0; - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function current() { @@ -385,9 +376,6 @@ public function next(): void ++$this->key; } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function key() { diff --git a/tests/Node/Expression/FilterTest.php b/tests/Node/Expression/FilterTest.php index b8cc48fab16..04b7d2f4253 100644 --- a/tests/Node/Expression/FilterTest.php +++ b/tests/Node/Expression/FilterTest.php @@ -131,7 +131,7 @@ protected function foobar() // from extension $node = $this->createFilter($string, 'foo'); - $tests[] = [$node, sprintf('$this->extensions[\'%s\']->foo("abc")', \get_class($extension)), $environment]; + $tests[] = [$node, sprintf('$this->extensions[\'%s\']->foo("abc")', $extension::class), $environment]; $node = $this->createFilter($string, 'foobar'); $tests[] = [$node, '$this->env->getFilter(\'foobar\')->getCallable()("abc")', $environment]; diff --git a/tests/Node/IncludeTest.php b/tests/Node/IncludeTest.php index ab1fdf0bfe0..92681662da7 100644 --- a/tests/Node/IncludeTest.php +++ b/tests/Node/IncludeTest.php @@ -47,11 +47,11 @@ public function getTests() ]; $expr = new ConditionalExpression( - new ConstantExpression(true, 1), - new ConstantExpression('foo', 1), - new ConstantExpression('foo', 1), - 0 - ); + new ConstantExpression(true, 1), + new ConstantExpression('foo', 1), + new ConstantExpression('foo', 1), + 0 + ); $node = new IncludeNode($expr, null, false, false, 1); $tests[] = [$node, <<createMock(LoaderInterface::class), ['debug' => true]); $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 65956cf7e74..cdd8e875743 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -168,7 +168,7 @@ public function testGetVarName() {{ foo }} {% endmacro %} EOF - , 'index'))); + , 'index'))); // The getVarName() must not depend on the template loaders, // If this test does not throw any exception, that's good. diff --git a/tests/Profiler/Dumper/AbstractTest.php b/tests/Profiler/Dumper/AbstractTest.php index 29e40d26cbc..1891c27507a 100644 --- a/tests/Profiler/Dumper/AbstractTest.php +++ b/tests/Profiler/Dumper/AbstractTest.php @@ -73,7 +73,6 @@ private function getMacroProfile(array $subProfiles = []) /** * @param string $name * @param float $duration - * @param bool $isTemplate * @param string $type * @param string $templateName * diff --git a/tests/Profiler/Dumper/BlackfireTest.php b/tests/Profiler/Dumper/BlackfireTest.php index b1c2cd7d1f0..3a33d94031b 100644 --- a/tests/Profiler/Dumper/BlackfireTest.php +++ b/tests/Profiler/Dumper/BlackfireTest.php @@ -31,6 +31,6 @@ public function testDump() embedded.twig==>included.twig//2 %d %d %d index.twig==>index.twig::macro(foo)//1 %d %d %d EOF - , $dumper->dump($this->getProfile())); + , $dumper->dump($this->getProfile())); } } diff --git a/tests/Profiler/Dumper/HtmlTest.php b/tests/Profiler/Dumper/HtmlTest.php index 20a1ab439c5..2dcbb9aec57 100644 --- a/tests/Profiler/Dumper/HtmlTest.php +++ b/tests/Profiler/Dumper/HtmlTest.php @@ -29,6 +29,6 @@ public function testDump() └ included.twig EOF - , $dumper->dump($this->getProfile())); + , $dumper->dump($this->getProfile())); } } diff --git a/tests/Profiler/Dumper/TextTest.php b/tests/Profiler/Dumper/TextTest.php index 8240e356bd2..ba19c2c90dc 100644 --- a/tests/Profiler/Dumper/TextTest.php +++ b/tests/Profiler/Dumper/TextTest.php @@ -29,6 +29,6 @@ public function testDump() └ included.twig EOF - , $dumper->dump($this->getProfile())); + , $dumper->dump($this->getProfile())); } } diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index bd26e9d95b7..9c2364c1d21 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -89,7 +89,7 @@ public function getAttributeExceptions() public function testGetAttributeWithSandbox($object, $item, $allowed) { $twig = new Environment($this->createMock(LoaderInterface::class)); - $policy = new SecurityPolicy([], [], [/*method*/], [/*prop*/], []); + $policy = new SecurityPolicy([], [], [/* method */], [/* prop */], []); $twig->addExtension(new SandboxExtension($policy, !$allowed)); $template = new TemplateForTest($twig); @@ -477,25 +477,22 @@ class TemplateArrayAccessObject implements \ArrayAccess '+4' => '+4', ]; - public function offsetExists($name) : bool + public function offsetExists($name): bool { return \array_key_exists($name, $this->attributes); } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function offsetGet($name) { return \array_key_exists($name, $this->attributes) ? $this->attributes[$name] : null; } - public function offsetSet($name, $value) : void + public function offsetSet($name, $value): void { } - public function offsetUnset($name) : void + public function offsetUnset($name): void { } } @@ -570,25 +567,22 @@ class TemplatePropertyObjectAndArrayAccess extends TemplatePropertyObject implem 'baf' => 'baf', ]; - public function offsetExists($offset) : bool + public function offsetExists($offset): bool { return \array_key_exists($offset, $this->data); } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->offsetExists($offset) ? $this->data[$offset] : 'n/a'; } - public function offsetSet($offset, $value) : void + public function offsetSet($offset, $value): void { } - public function offsetUnset($offset) : void + public function offsetUnset($offset): void { } } @@ -722,26 +716,23 @@ class TemplateArrayAccess implements \ArrayAccess ]; private $children = []; - public function offsetExists($offset) : bool + public function offsetExists($offset): bool { return \array_key_exists($offset, $this->children); } - /** - * @return mixed - */ #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->children[$offset]; } - public function offsetSet($offset, $value) : void + public function offsetSet($offset, $value): void { $this->children[$offset] = $value; } - public function offsetUnset($offset) : void + public function offsetUnset($offset): void { unset($this->children[$offset]); }