diff --git a/extra/html-extra/HtmlExtension.php b/extra/html-extra/HtmlExtension.php
index 06329977f..e1766ad45 100644
--- a/extra/html-extra/HtmlExtension.php
+++ b/extra/html-extra/HtmlExtension.php
@@ -116,7 +116,7 @@ final class HtmlExtension extends AbstractExtension
* @param string|list $base
* @param array> $variants
* @param array>> $compoundVariants
- * @param array $defaultVariant
+ * @param array $defaultVariant
*
* @internal
*/
diff --git a/src/AbstractTwigCallable.php b/src/AbstractTwigCallable.php
index d9fc45f2f..f67184300 100644
--- a/src/AbstractTwigCallable.php
+++ b/src/AbstractTwigCallable.php
@@ -41,7 +41,7 @@ abstract class AbstractTwigCallable implements TwigCallableInterface
public function __toString(): string
{
- return sprintf('%s(%s)', static::class, $this->name);
+ return \sprintf('%s(%s)', static::class, $this->name);
}
public function getName(): string
diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php
index 51cda50a1..28b556ccc 100644
--- a/src/ExpressionParser.php
+++ b/src/ExpressionParser.php
@@ -20,20 +20,17 @@ use Twig\Node\Expression\ArrowFunctionExpression;
use Twig\Node\Expression\AssignNameExpression;
use Twig\Node\Expression\Binary\AbstractBinary;
use Twig\Node\Expression\Binary\ConcatBinary;
-use Twig\Node\Expression\BlockReferenceExpression;
use Twig\Node\Expression\ConditionalExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\MethodCallExpression;
use Twig\Node\Expression\NameExpression;
-use Twig\Node\Expression\ParentExpression;
use Twig\Node\Expression\TestExpression;
use Twig\Node\Expression\Unary\AbstractUnary;
use Twig\Node\Expression\Unary\NegUnary;
use Twig\Node\Expression\Unary\NotUnary;
use Twig\Node\Expression\Unary\PosUnary;
use Twig\Node\Node;
-use Twig\Util\CallableArgumentsExtractor;
/**
* Parses expressions.
diff --git a/src/Lexer.php b/src/Lexer.php
index d264dea96..78b071565 100644
--- a/src/Lexer.php
+++ b/src/Lexer.php
@@ -393,8 +393,8 @@ class Lexer
private function stripcslashes(string $str, string $quoteType): string
{
$result = '';
- $length = strlen($str);
-
+ $length = \strlen($str);
+
$i = 0;
while ($i < $length) {
if (false === $pos = strpos($str, '\\', $i)) {
@@ -414,34 +414,34 @@ class Lexer
if (isset(self::SPECIAL_CHARS[$nextChar])) {
$result .= self::SPECIAL_CHARS[$nextChar];
- } elseif ($nextChar === '\\') {
+ } elseif ('\\' === $nextChar) {
$result .= $nextChar;
- } elseif ($nextChar === "'" || $nextChar === '"') {
+ } elseif ("'" === $nextChar || '"' === $nextChar) {
if ($nextChar !== $quoteType) {
trigger_deprecation('twig/twig', '3.12', 'Character "%s" at position %d does not need to be escaped anymore.', $nextChar, $i + 1);
}
$result .= $nextChar;
- } elseif ($nextChar === '#' && $i + 1 < $length && $str[$i + 1] === '{') {
+ } elseif ('#' === $nextChar && $i + 1 < $length && '{' === $str[$i + 1]) {
$result .= '#{';
- $i++;
- } elseif ($nextChar === 'x' && $i + 1 < $length && ctype_xdigit($str[$i + 1])) {
+ ++$i;
+ } elseif ('x' === $nextChar && $i + 1 < $length && ctype_xdigit($str[$i + 1])) {
$hex = $str[++$i];
if ($i + 1 < $length && ctype_xdigit($str[$i + 1])) {
$hex .= $str[++$i];
}
- $result .= chr(hexdec($hex));
+ $result .= \chr(hexdec($hex));
} elseif (ctype_digit($nextChar) && $nextChar < '8') {
$octal = $nextChar;
- while ($i + 1 < $length && ctype_digit($str[$i + 1]) && $str[$i + 1] < '8' && strlen($octal) < 3) {
+ while ($i + 1 < $length && ctype_digit($str[$i + 1]) && $str[$i + 1] < '8' && \strlen($octal) < 3) {
$octal .= $str[++$i];
}
- $result .= chr(octdec($octal));
+ $result .= \chr(octdec($octal));
} else {
- trigger_deprecation('twig/twig', '3.12', sprintf('Character "%s" at position %d does not need to be escaped anymore.', $nextChar, $i + 1));
+ trigger_deprecation('twig/twig', '3.12', \sprintf('Character "%s" at position %d does not need to be escaped anymore.', $nextChar, $i + 1));
$result .= $nextChar;
}
- $i++;
+ ++$i;
}
return $result;
diff --git a/src/Node/DeprecatedNode.php b/src/Node/DeprecatedNode.php
index afeb8332e..c4c4a8aec 100644
--- a/src/Node/DeprecatedNode.php
+++ b/src/Node/DeprecatedNode.php
@@ -65,7 +65,7 @@ class DeprecatedNode extends Node
}
$compiler
- ->raw(".")
+ ->raw('.')
->string(\sprintf(' in "%s" at line %d.', $this->getTemplateName(), $this->getTemplateLine()))
->raw(");\n")
;
diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php
index 91faf271a..f61adc725 100644
--- a/src/Node/Expression/CallExpression.php
+++ b/src/Node/Expression/CallExpression.php
@@ -319,7 +319,7 @@ abstract class CallExpression extends AbstractExpression
}
/**
- * Overrides the Twig callable based on attributes (as potentially, attributes changed between the creation and the compilation of the node)
+ * Overrides the Twig callable based on attributes (as potentially, attributes changed between the creation and the compilation of the node).
*
* To be removed in 4.0 and replace by $this->getAttribute('twig_callable').
*/
@@ -334,7 +334,7 @@ abstract class CallExpression extends AbstractExpression
[
'is_variadic' => $this->hasAttribute('is_variadic') ? $this->getAttribute('is_variadic') : $current->isVariadic(),
],
- ))->withDynamicArguments($this->getAttribute('name'), $this->hasAttribute('dynamic_name') ? $this->getAttribute('dynamic_name') : $current->getDynamicName(), $this->hasAttribute('arguments') ? $this->hasAttribute('arguments') : $current->getArguments()),
+ ))->withDynamicArguments($this->getAttribute('name'), $this->hasAttribute('dynamic_name') ? $this->getAttribute('dynamic_name') : $current->getDynamicName(), $this->hasAttribute('arguments') ?: $current->getArguments()),
'function' => (new TwigFunction(
$this->hasAttribute('name') ? $this->getAttribute('name') : $current->getName(),
$this->hasAttribute('callable') ? $this->getAttribute('callable') : $current->getCallable(),
@@ -344,7 +344,7 @@ abstract class CallExpression extends AbstractExpression
'needs_charset' => $this->hasAttribute('needs_charset') ? $this->getAttribute('needs_charset') : $current->needsCharset(),
'is_variadic' => $this->hasAttribute('is_variadic') ? $this->getAttribute('is_variadic') : $current->isVariadic(),
],
- ))->withDynamicArguments($this->getAttribute('name'), $this->hasAttribute('dynamic_name') ? $this->getAttribute('dynamic_name') : $current->getDynamicName(), $this->hasAttribute('arguments') ? $this->hasAttribute('arguments') : $current->getArguments()),
+ ))->withDynamicArguments($this->getAttribute('name'), $this->hasAttribute('dynamic_name') ? $this->getAttribute('dynamic_name') : $current->getDynamicName(), $this->hasAttribute('arguments') ?: $current->getArguments()),
'filter' => (new TwigFilter(
$this->getAttribute('name'),
$this->hasAttribute('callable') ? $this->getAttribute('callable') : $current->getCallable(),
@@ -354,7 +354,7 @@ abstract class CallExpression extends AbstractExpression
'needs_charset' => $this->hasAttribute('needs_charset') ? $this->getAttribute('needs_charset') : $current->needsCharset(),
'is_variadic' => $this->hasAttribute('is_variadic') ? $this->getAttribute('is_variadic') : $current->isVariadic(),
],
- ))->withDynamicArguments($this->getAttribute('name'), $this->hasAttribute('dynamic_name') ? $this->getAttribute('dynamic_name') : $current->getDynamicName(), $this->hasAttribute('arguments') ? $this->hasAttribute('arguments') : $current->getArguments()),
+ ))->withDynamicArguments($this->getAttribute('name'), $this->hasAttribute('dynamic_name') ? $this->getAttribute('dynamic_name') : $current->getDynamicName(), $this->hasAttribute('arguments') ?: $current->getArguments()),
});
return $this->getAttribute('twig_callable');
diff --git a/src/Node/Expression/FunctionNode/EnumCasesFunction.php b/src/Node/Expression/FunctionNode/EnumCasesFunction.php
index 171f611de..7e5c25ff4 100644
--- a/src/Node/Expression/FunctionNode/EnumCasesFunction.php
+++ b/src/Node/Expression/FunctionNode/EnumCasesFunction.php
@@ -20,7 +20,7 @@ class EnumCasesFunction extends FunctionExpression
$firstArgument = null;
}
- if (!$firstArgument instanceof ConstantExpression || \count($arguments) !== 1) {
+ if (!$firstArgument instanceof ConstantExpression || 1 !== \count($arguments)) {
parent::compile($compiler);
return;
diff --git a/src/Node/Expression/Test/DefinedTest.php b/src/Node/Expression/Test/DefinedTest.php
index f4c1b1e4b..24d3ee82c 100644
--- a/src/Node/Expression/Test/DefinedTest.php
+++ b/src/Node/Expression/Test/DefinedTest.php
@@ -14,7 +14,6 @@ namespace Twig\Node\Expression\Test;
use Twig\Attribute\FirstClassTwigCallableReady;
use Twig\Compiler;
use Twig\Error\SyntaxError;
-use Twig\Extension\CoreExtension;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\BlockReferenceExpression;
use Twig\Node\Expression\ConstantExpression;
@@ -58,7 +57,7 @@ class DefinedTest extends TestExpression
throw new SyntaxError('The "defined" test only works with simple variables.', $lineno);
}
- if (is_string($name) && 'defined' !== $name) {
+ if (\is_string($name) && 'defined' !== $name) {
trigger_deprecation('twig/twig', '3.12', 'Creating a "DefinedTest" instance with a test name that is not "defined" is deprecated.');
}
diff --git a/src/Node/Node.php b/src/Node/Node.php
index a9bd84a3e..770cdaf43 100644
--- a/src/Node/Node.php
+++ b/src/Node/Node.php
@@ -15,7 +15,6 @@ namespace Twig\Node;
use Twig\Attribute\YieldReady;
use Twig\Compiler;
use Twig\Source;
-use Twig\TwigCallableInterface;
/**
* Represents a node in the AST.
diff --git a/src/Util/CallableArgumentsExtractor.php b/src/Util/CallableArgumentsExtractor.php
index 1eb6a4524..e8dea5217 100644
--- a/src/Util/CallableArgumentsExtractor.php
+++ b/src/Util/CallableArgumentsExtractor.php
@@ -65,8 +65,8 @@ final class CallableArgumentsExtractor
if (!$named && !$this->twigCallable->isVariadic()) {
$min = $this->twigCallable->getMinimalNumberOfRequiredArguments();
- if (count($extractedArguments) < $rc->getReflector()->getNumberOfRequiredParameters() - $min) {
- throw new SyntaxError(\sprintf('Value for argument "%s" is required for %s "%s".', $rc->getReflector()->getParameters()[$min + count($extractedArguments)]->getName(), $this->type, $this->name), $this->node->getTemplateLine(), $this->node->getSourceContext());
+ if (\count($extractedArguments) < $rc->getReflector()->getNumberOfRequiredParameters() - $min) {
+ throw new SyntaxError(\sprintf('Value for argument "%s" is required for %s "%s".', $rc->getReflector()->getParameters()[$min + \count($extractedArguments)]->getName(), $this->type, $this->name), $this->node->getTemplateLine(), $this->node->getSourceContext());
}
return $extractedArguments;
diff --git a/tests/LexerTest.php b/tests/LexerTest.php
index 81690829a..87dfd2e8d 100644
--- a/tests/LexerTest.php
+++ b/tests/LexerTest.php
@@ -495,7 +495,7 @@ bar
public function getTemplateForStrings()
{
- yield ["日本では、春になると桜の花が咲きます。多くの人々は、公園や川の近くに集まり、お花見を楽しみます。桜の花びらが風に舞い、まるで雪のように見える瞬間は、とても美しいです。"];
- yield ["في العالم العربي، يُعتبر الخط العربي أحد أجمل أشكال الفن. يُستخدم الخط في تزيين المساجد والكتب والمخطوطات القديمة. يتميز الخط العربي بجماله وتناسقه، ويُعتبر رمزًا للثقافة الإسلامية."];
+ yield ['日本では、春になると桜の花が咲きます。多くの人々は、公園や川の近くに集まり、お花見を楽しみます。桜の花びらが風に舞い、まるで雪のように見える瞬間は、とても美しいです。'];
+ yield ['في العالم العربي، يُعتبر الخط العربي أحد أجمل أشكال الفن. يُستخدم الخط في تزيين المساجد والكتب والمخطوطات القديمة. يتميز الخط العربي بجماله وتناسقه، ويُعتبر رمزًا للثقافة الإسلامية.'];
}
}
diff --git a/tests/Node/NodeTest.php b/tests/Node/NodeTest.php
index b224c3636..94c9197b5 100644
--- a/tests/Node/NodeTest.php
+++ b/tests/Node/NodeTest.php
@@ -47,7 +47,7 @@ class NodeTest extends TestCase
$node = new Node([], ['foo' => false]);
$node->deprecateAttribute('foo', new NameDeprecation('foo/bar', '2.0', 'bar'));
- $this->assertSame(false, $node->getAttribute('foo', false));
+ $this->assertFalse($node->getAttribute('foo', false));
}
/**
@@ -59,7 +59,7 @@ class NodeTest extends TestCase
$node->deprecateAttribute('foo', new NameDeprecation('foo/bar', '2.0'));
$this->expectDeprecation('Since foo/bar 2.0: Getting attribute "foo" on a "Twig\Node\Node" class is deprecated.');
- $this->assertSame(false, $node->getAttribute('foo'));
+ $this->assertFalse($node->getAttribute('foo'));
}
/**
@@ -71,7 +71,7 @@ class NodeTest extends TestCase
$node->deprecateAttribute('foo', new NameDeprecation('foo/bar', '2.0', 'bar'));
$this->expectDeprecation('Since foo/bar 2.0: Getting attribute "foo" on a "Twig\Node\Node" class is deprecated, get the "bar" attribute instead.');
- $this->assertSame(false, $node->getAttribute('foo'));
+ $this->assertFalse($node->getAttribute('foo'));
}
public function testNodeDeprecationIgnore()