This commit is contained in:
Fabien Potencier
2024-11-30 09:33:57 +01:00
parent f0066c8682
commit 44516133e2
16 changed files with 23 additions and 23 deletions
+4 -4
View File
@@ -92,7 +92,7 @@ class ExpressionParser
public function parseExpression($precedence = 0)
{
if (func_num_args() > 1) {
if (\func_num_args() > 1) {
trigger_deprecation('twig/twig', '3.15', 'Passing a second argument ($allowArrow) to "%s()" is deprecated.', __METHOD__);
}
@@ -153,7 +153,7 @@ class ExpressionParser
/** @var AbstractExpression $node */
$node = $expr->getNode('node');
foreach ($this->precedenceChanges as $operatorName => $changes) {
if (!in_array($unaryOp, $changes)) {
if (!\in_array($unaryOp, $changes)) {
continue;
}
if ($node->hasAttribute('operator') && $operatorName === $node->getAttribute('operator')) {
@@ -616,10 +616,10 @@ class ExpressionParser
{
$namedArguments = false;
$definition = false;
if (func_num_args() > 1) {
if (\func_num_args() > 1) {
$definition = func_get_arg(1);
}
if (func_num_args() > 0) {
if (\func_num_args() > 0) {
trigger_deprecation('twig/twig', '3.15', 'Passing arguments to "%s()" is deprecated.', __METHOD__);
$namedArguments = func_get_arg(0);
}
+2 -2
View File
@@ -1543,11 +1543,11 @@ final class CoreExtension extends AbstractExtension
public static function enum(string $enum): \UnitEnum
{
if (!enum_exists($enum)) {
throw new RuntimeError(sprintf('"%s" is not an enum.', $enum));
throw new RuntimeError(\sprintf('"%s" is not an enum.', $enum));
}
if (!$cases = $enum::cases()) {
throw new RuntimeError(sprintf('"%s" is an empty enum.', $enum));
throw new RuntimeError(\sprintf('"%s" is an empty enum.', $enum));
}
return $cases[0];
@@ -25,10 +25,10 @@ abstract class AbstractBinary extends AbstractExpression
public function __construct(Node $left, Node $right, int $lineno)
{
if (!$left instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($left));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($left));
}
if (!$right instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($right));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($right));
}
parent::__construct(['left' => $left, 'right' => $right], [], $lineno);
@@ -28,7 +28,7 @@ class BlockReferenceExpression extends AbstractExpression
public function __construct(Node $name, ?Node $template, int $lineno)
{
if (!$name instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($name));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($name));
}
$nodes = ['name' => $name];
+1 -1
View File
@@ -42,7 +42,7 @@ class DefaultFilter extends FilterExpression
public function __construct(Node $node, TwigFilter|ConstantExpression $filter, Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
}
if ($filter instanceof TwigFilter) {
+1 -1
View File
@@ -32,7 +32,7 @@ class RawFilter extends FilterExpression
public function __construct(Node $node, TwigFilter|ConstantExpression|null $filter = null, ?Node $arguments = null, int $lineno = 0)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
}
parent::__construct($node, $filter ?: new TwigFilter('raw', null, ['is_safe' => ['all']]), $arguments ?: new EmptyNode(), $lineno ?: $node->getTemplateLine());
+1 -1
View File
@@ -27,7 +27,7 @@ class FilterExpression extends CallExpression
public function __construct(Node $node, TwigFilter|ConstantExpression $filter, Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
}
if ($filter instanceof TwigFilter) {
@@ -32,10 +32,10 @@ class NullCoalesceExpression extends ConditionalExpression
trigger_deprecation('twig/twig', '3.16', \sprintf('"%s" is deprecated; use "%s" instead.', __CLASS__, NullCoalesceBinary::class));
if (!$left instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($left));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "left" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($left));
}
if (!$right instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($right));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "right" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($right));
}
$test = new DefinedTest(clone $left, new TwigTest('defined'), new EmptyNode(), $left->getTemplateLine());
+2 -2
View File
@@ -29,9 +29,9 @@ class TempNameExpression extends AbstractExpression
trigger_deprecation('twig/twig', '3.15', 'The "%s" class is deprecated.', self::class);
}
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;
}
+1 -1
View File
@@ -46,7 +46,7 @@ class DefinedTest extends TestExpression
public function __construct(Node $node, TwigTest|string $name, ?Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
}
if ($node instanceof NameExpression) {
+1 -1
View File
@@ -26,7 +26,7 @@ class TestExpression extends CallExpression
public function __construct(Node $node, string|TwigTest $test, ?Node $arguments, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
}
$nodes = ['node' => $node];
+1 -1
View File
@@ -24,7 +24,7 @@ abstract class AbstractUnary extends AbstractExpression
public function __construct(Node $node, int $lineno)
{
if (!$node instanceof AbstractExpression) {
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance argument to "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance argument to "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, \get_class($node));
}
parent::__construct(['node' => $node], ['with_parentheses' => false], $lineno);
+1 -1
View File
@@ -34,7 +34,7 @@ class SetNode extends Node implements NodeCaptureInterface
if ($capture) {
$safe = true;
// Node::class === get_class($values) should be removed in Twig 4.0
if (($values instanceof Nodes || Node::class === get_class($values)) && !count($values)) {
if (($values instanceof Nodes || Node::class === \get_class($values)) && !\count($values)) {
$values = new ConstantExpression('', $values->getTemplateLine());
$capture = false;
} elseif ($values instanceof TextNode) {
+1 -1
View File
@@ -26,7 +26,7 @@ final class GuardTokenParser extends AbstractTokenParser
{
$stream = $this->parser->getStream();
$typeToken = $stream->expect(Token::NAME_TYPE);
if (!in_array($typeToken->getValue(), ['function', 'filter', 'test'])) {
if (!\in_array($typeToken->getValue(), ['function', 'filter', 'test'])) {
throw new SyntaxError(\sprintf('Supported guard types are function, filter and test, "%s" given.', $typeToken->getValue()), $typeToken->getLine(), $stream->getSourceContext());
}
$method = 'get'.$typeToken->getValue();
+1 -1
View File
@@ -75,7 +75,7 @@ final class MacroTokenParser extends AbstractTokenParser
$stream = $this->parser->getStream();
$stream->expect(Token::PUNCTUATION_TYPE, '(', 'A list of arguments must begin with an opening parenthesis');
while (!$stream->test(Token::PUNCTUATION_TYPE, ')')) {
if (count($arguments)) {
if (\count($arguments)) {
$stream->expect(Token::PUNCTUATION_TYPE, ',', 'Arguments must be separated by a comma');
// if the comma above was a trailing comma, early exit the argument parse loop
+1 -1
View File
@@ -70,7 +70,7 @@ class OptimizerTest extends TestCase
public function checkForVarConfiguration(Node $node, $target)
{
foreach ($node as $n) {
if (NameExpression::class === get_class($n) && $target === $n->getAttribute('name')) {
if (NameExpression::class === \get_class($n) && $target === $n->getAttribute('name')) {
$this->assertTrue($n->getAttribute('always_defined'));
} else {
$this->checkForVarConfiguration($n, $target);