diff --git a/extra/html-extra/HtmlExtension.php b/extra/html-extra/HtmlExtension.php
index 4721fa37f..5434ec8a4 100644
--- a/extra/html-extra/HtmlExtension.php
+++ b/extra/html-extra/HtmlExtension.php
@@ -113,10 +113,10 @@ final class HtmlExtension extends AbstractExtension
}
/**
- * @param string|list $base
+ * @param string|list $base
* @param array> $variants
- * @param array>> $compoundVariants
- * @param array $defaultVariant
+ * @param array>> $compoundVariants
+ * @param array $defaultVariant
*
* @internal
*/
diff --git a/extra/twig-extra-bundle/phpunit-bootstrap.php b/extra/twig-extra-bundle/phpunit-bootstrap.php
index d896a46b9..b087898d1 100644
--- a/extra/twig-extra-bundle/phpunit-bootstrap.php
+++ b/extra/twig-extra-bundle/phpunit-bootstrap.php
@@ -2,7 +2,7 @@
use Symfony\Component\ErrorHandler\ErrorHandler;
-require __DIR__ . '/vendor/autoload.php';
+require __DIR__.'/vendor/autoload.php';
// see https://github.com/symfony/symfony/issues/53812#issuecomment-1962740145
set_exception_handler([new ErrorHandler(), 'handleException']);
diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php
index 124c51d73..c8c28104d 100644
--- a/src/ExpressionParser.php
+++ b/src/ExpressionParser.php
@@ -22,7 +22,6 @@ use Twig\Node\Expression\Binary\ConcatBinary;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\MacroReferenceExpression;
-use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\Ternary\ConditionalTernary;
use Twig\Node\Expression\TestExpression;
use Twig\Node\Expression\Unary\AbstractUnary;
@@ -782,7 +781,7 @@ class ExpressionParser
$name = null;
if (($token = $stream->nextIf(Token::OPERATOR_TYPE, '=')) || ($token = $stream->nextIf(Token::PUNCTUATION_TYPE, ':'))) {
if (!$value instanceof ContextVariable) {
- 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');
$value = $this->parseExpression();
@@ -830,8 +829,7 @@ class ExpressionParser
if (
$node instanceof ContextVariable
- &&
- (
+ && (
null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name'))
|| '_self' === $node->getAttribute('name') && $attribute instanceof ConstantExpression
)
diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php
index 13f3ff948..88dbc58a4 100644
--- a/src/Extension/CoreExtension.php
+++ b/src/Extension/CoreExtension.php
@@ -378,7 +378,7 @@ final class CoreExtension extends AbstractExtension
throw new RuntimeError('The "cycle" function expects an array or "ArrayAccess" as first argument.');
}
- if (!\is_countable($values)) {
+ if (!is_countable($values)) {
throw new RuntimeError('The "cycle" function expects a countable sequence as first argument.');
}
@@ -504,7 +504,6 @@ final class CoreExtension extends AbstractExtension
* Returns a formatted string.
*
* @param string|null $format
- * @param ...$values
*
* @internal
*/
diff --git a/src/Lexer.php b/src/Lexer.php
index bc3d2db6f..2d75442f0 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -433,7 +433,7 @@ class Lexer
if (isset(self::SPECIAL_CHARS[$nextChar])) {
$result .= self::SPECIAL_CHARS[$nextChar];
- } elseif ($nextChar === '\\' || $nextChar === $quoteType) {
+ } elseif ('\\' === $nextChar || $nextChar === $quoteType) {
$result .= $nextChar;
} elseif ('#' === $nextChar && $i + 1 < $length && '{' === $str[$i + 1]) {
$result .= '#{';
diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php
index 28a4c633d..9aea4dfd5 100644
--- a/src/Node/Expression/CallExpression.php
+++ b/src/Node/Expression/CallExpression.php
@@ -13,7 +13,6 @@ namespace Twig\Node\Expression;
use Twig\Compiler;
use Twig\Extension\ExtensionInterface;
-use Twig\TwigCallableInterface;
use Twig\Util\CallableArgumentsExtractor;
use Twig\Util\ReflectionCallable;
diff --git a/src/Node/Expression/Variable/AssignContextVariable.php b/src/Node/Expression/Variable/AssignContextVariable.php
index 36dca76a7..6387b7ec2 100644
--- a/src/Node/Expression/Variable/AssignContextVariable.php
+++ b/src/Node/Expression/Variable/AssignContextVariable.php
@@ -13,7 +13,6 @@ namespace Twig\Node\Expression\Variable;
use Twig\Compiler;
use Twig\Error\SyntaxError;
-use Twig\Node\Expression\Variable\ContextVariable;
final class AssignContextVariable extends ContextVariable
{
diff --git a/src/Node/Expression/Variable/LocalVariable.php b/src/Node/Expression/Variable/LocalVariable.php
index 1215ed5e3..4e5074b70 100644
--- a/src/Node/Expression/Variable/LocalVariable.php
+++ b/src/Node/Expression/Variable/LocalVariable.php
@@ -11,8 +11,8 @@
namespace Twig\Node\Expression\Variable;
-use Twig\Error\SyntaxError;
use Twig\Compiler;
+use Twig\Error\SyntaxError;
use Twig\Node\Expression\AbstractExpression;
final class LocalVariable extends AbstractExpression
@@ -26,9 +26,9 @@ final class LocalVariable extends AbstractExpression
throw new SyntaxError(\sprintf('You cannot assign a value to "%s".', $name), $lineno);
}
- if (null !== $name && (is_int($name) || ctype_digit($name))) {
+ if (null !== $name && (\is_int($name) || ctype_digit($name))) {
$name = (int) $name;
- } elseif (in_array($name, self::RESERVED_NAMES)) {
+ } elseif (\in_array($name, self::RESERVED_NAMES)) {
$name = "\u{035C}".$name;
}
diff --git a/src/Node/Expression/Variable/TemplateVariable.php b/src/Node/Expression/Variable/TemplateVariable.php
index ddaeeadb4..15730f0c0 100644
--- a/src/Node/Expression/Variable/TemplateVariable.php
+++ b/src/Node/Expression/Variable/TemplateVariable.php
@@ -26,9 +26,9 @@ final class TemplateVariable extends AbstractExpression
throw new SyntaxError(\sprintf('You cannot assign a value to "%s".', $name), $lineno);
}
- if (null !== $name && (is_int($name) || ctype_digit($name))) {
+ if (null !== $name && (\is_int($name) || ctype_digit($name))) {
$name = (int) $name;
- } elseif (in_array($name, self::RESERVED_NAMES)) {
+ } elseif (\in_array($name, self::RESERVED_NAMES)) {
$name = "\u{035C}".$name;
}
diff --git a/src/Node/ForNode.php b/src/Node/ForNode.php
index b3ca78707..51972528d 100644
--- a/src/Node/ForNode.php
+++ b/src/Node/ForNode.php
@@ -60,7 +60,7 @@ class ForNode extends Node
}
$compiler
- ->write("foreach (\$iterator as ")
+ ->write('foreach ($iterator as ')
->subcompile($this->getNode('key_target'))
->raw(' => ')
->subcompile($this->getNode('value_target'))
diff --git a/src/Node/MacroNode.php b/src/Node/MacroNode.php
index c652553a4..c2fe37ff8 100644
--- a/src/Node/MacroNode.php
+++ b/src/Node/MacroNode.php
@@ -15,7 +15,6 @@ use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\ArrayExpression;
-use Twig\Node\Expression\Variable\LocalVariable;
/**
* Represents a macro node.
diff --git a/src/Node/SetNode.php b/src/Node/SetNode.php
index 1fced5c2e..bd6655300 100644
--- a/src/Node/SetNode.php
+++ b/src/Node/SetNode.php
@@ -33,7 +33,7 @@ class SetNode extends Node implements NodeCaptureInterface
$safe = false;
if ($capture) {
$safe = true;
- if ($values instanceof Nodes && !count($values)) {
+ if ($values instanceof Nodes && !\count($values)) {
$values = new ConstantExpression('', $values->getTemplateLine());
$capture = false;
} elseif ($values instanceof TextNode) {
diff --git a/src/NodeVisitor/OptimizerNodeVisitor.php b/src/NodeVisitor/OptimizerNodeVisitor.php
index 74e72f863..4f92ce14f 100644
--- a/src/NodeVisitor/OptimizerNodeVisitor.php
+++ b/src/NodeVisitor/OptimizerNodeVisitor.php
@@ -58,7 +58,7 @@ final class OptimizerNodeVisitor implements NodeVisitorInterface
public function __construct(
private int $optimizers = -1,
) {
- if ($optimizers > (self::OPTIMIZE_FOR)) {
+ if ($optimizers > self::OPTIMIZE_FOR) {
throw new \InvalidArgumentException(\sprintf('Optimizer mode "%s" is not valid.', $optimizers));
}
}
diff --git a/src/NodeVisitor/SandboxNodeVisitor.php b/src/NodeVisitor/SandboxNodeVisitor.php
index 4947e2337..f9724353d 100644
--- a/src/NodeVisitor/SandboxNodeVisitor.php
+++ b/src/NodeVisitor/SandboxNodeVisitor.php
@@ -21,8 +21,8 @@ use Twig\Node\Expression\Binary\RangeBinary;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Expression\GetAttrExpression;
-use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Expression\Unary\SpreadUnary;
+use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
use Twig\Node\Nodes;
diff --git a/src/Parser.php b/src/Parser.php
index 4d3ece03b..1b10a6561 100644
--- a/src/Parser.php
+++ b/src/Parser.php
@@ -17,9 +17,7 @@ use Twig\Node\BlockNode;
use Twig\Node\BlockReferenceNode;
use Twig\Node\BodyNode;
use Twig\Node\EmptyNode;
-use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\Variable\AssignTemplateVariable;
-use Twig\Node\Expression\Variable\TemplateVariable;
use Twig\Node\MacroNode;
use Twig\Node\ModuleNode;
use Twig\Node\Node;
diff --git a/src/Runtime/LoopIterator.php b/src/Runtime/LoopIterator.php
index db9c0ce71..53a773bd1 100644
--- a/src/Runtime/LoopIterator.php
+++ b/src/Runtime/LoopIterator.php
@@ -22,6 +22,7 @@ use Twig\Error\RuntimeError;
*
* @template TKey
* @template TValue
+ *
* @implements \Iterator
*/
final class LoopIterator implements \Iterator
diff --git a/src/Template.php b/src/Template.php
index 775b12586..9bbfe2bf9 100644
--- a/src/Template.php
+++ b/src/Template.php
@@ -287,6 +287,7 @@ abstract class Template
/**
* @internal
+ *
* @return $this
*/
public function unwrap(): self
diff --git a/tests/DeprecatedCallableInfoTest.php b/tests/DeprecatedCallableInfoTest.php
index 4e6d1583c..454d826ef 100644
--- a/tests/DeprecatedCallableInfoTest.php
+++ b/tests/DeprecatedCallableInfoTest.php
@@ -30,7 +30,7 @@ class DeprecatedCallableInfoTest extends TestCase
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}
-
+
return false;
});
@@ -62,7 +62,7 @@ class DeprecatedCallableInfoTest extends TestCase
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}
-
+
return false;
});
diff --git a/tests/Extension/SandboxTest.php b/tests/Extension/SandboxTest.php
index e050d3a0a..525e5239a 100644
--- a/tests/Extension/SandboxTest.php
+++ b/tests/Extension/SandboxTest.php
@@ -14,7 +14,6 @@ namespace Twig\Tests\Extension;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Twig\Environment;
-use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use Twig\Extension\SandboxExtension;
use Twig\Extension\StringLoaderExtension;
diff --git a/tests/Node/Expression/FilterTest.php b/tests/Node/Expression/FilterTest.php
index 6597f6cf8..a794ceea1 100644
--- a/tests/Node/Expression/FilterTest.php
+++ b/tests/Node/Expression/FilterTest.php
@@ -114,7 +114,7 @@ class FilterTest extends NodeTestCase
// from extension
$node = self::createFilter($environment, $string, 'foo');
- $tests[] = [$node, \sprintf('$this->extensions[\'%s\']->foo("abc")', get_class(self::createExtension())), $environment];
+ $tests[] = [$node, \sprintf('$this->extensions[\'%s\']->foo("abc")', \get_class(self::createExtension())), $environment];
$node = self::createFilter($environment, $string, 'foobar');
$tests[] = [$node, '$this->env->getFilter(\'foobar\')->getCallable()("abc")', $environment];