This commit is contained in:
Fabien Potencier
2026-02-07 09:16:06 +01:00
parent df07638b63
commit cdce18d02a
9 changed files with 15 additions and 19 deletions
+1
View File
@@ -16,6 +16,7 @@ return (new Config())
'braces' => ['allow_single_line_closure' => true],
'heredoc_to_nowdoc' => false,
'single_line_throw' => false,
'phpdoc_to_comment' => ['ignored_tags' => ['var']],
'ordered_imports' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
])
+1 -1
View File
@@ -36,7 +36,7 @@ fwrite($output, "\n+------------+------------------+---------+---------------+".
fwrite($output, '| Precedence | Operator | Type | Associativity | Description'.str_repeat(' ', $descriptionLength - 11)." |\n");
fwrite($output, '+============+==================+=========+===============+'.str_repeat('=', $descriptionLength + 2).'+');
usort($expressionParsers, fn ($a, $b) => $b->getPrecedence() <=> $a->getPrecedence());
usort($expressionParsers, static fn ($a, $b) => $b->getPrecedence() <=> $a->getPrecedence());
$previous = null;
foreach ($expressionParsers as $expressionParser) {
+8 -9
View File
@@ -423,7 +423,6 @@ final class CoreExtension extends AbstractExtension
if (!is_countable($values)) {
throw new RuntimeError('The "cycle" function expects a countable sequence as first argument.');
$values = self::toArray($values, false);
}
}
@@ -1116,9 +1115,9 @@ final class CoreExtension extends AbstractExtension
}
if ((int) $bTrim == $bTrim) {
return $a <=> (int) $bTrim;
} else {
return (float) $a <=> (float) $bTrim;
}
return (float) $a <=> (float) $bTrim;
}
if (\is_string($a) && \is_int($b)) {
$aTrim = trim($a, " \t\n\r\v\f");
@@ -1127,9 +1126,9 @@ final class CoreExtension extends AbstractExtension
}
if ((int) $aTrim == $aTrim) {
return (int) $aTrim <=> $b;
} else {
return (float) $aTrim <=> (float) $b;
}
return (float) $aTrim <=> (float) $b;
}
// float <=> string
@@ -1167,7 +1166,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function matches(string $regexp, ?string $str): int
{
set_error_handler(function ($t, $m) use ($regexp) {
set_error_handler(static function ($t, $m) use ($regexp) {
throw new RuntimeError(\sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
});
try {
@@ -2020,7 +2019,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function parseBlockFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
{
$fakeFunction = new TwigFunction('block', fn ($name, $template = null) => null);
$fakeFunction = new TwigFunction('block', static fn ($name, $template = null) => null);
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
return new BlockReferenceExpression($args[0], $args[1] ?? null, $line);
@@ -2031,7 +2030,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function parseAttributeFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
{
$fakeFunction = new TwigFunction('attribute', fn ($variable, $attribute, $arguments = null) => null);
$fakeFunction = new TwigFunction('attribute', static fn ($variable, $attribute, $arguments = null) => null);
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
/*
@@ -2051,7 +2050,7 @@ final class CoreExtension extends AbstractExtension
*/
public static function parseLoopFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
{
$fakeFunction = new TwigFunction('loop', fn ($iterator) => null);
$fakeFunction = new TwigFunction('loop', static fn ($iterator) => null);
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
$recurseArgs = new ArrayExpression([new ConstantExpression(0, $line), $args[0]], $line);
+1 -1
View File
@@ -360,7 +360,7 @@ class EnvironmentTest extends TestCase
public function testAddRuntimeLoader()
{
$runtimeLoader = new FactoryRuntimeLoader([
EnvironmentTest_Runtime::class => function () { return new EnvironmentTest_Runtime(); },
EnvironmentTest_Runtime::class => static function () { return new EnvironmentTest_Runtime(); },
]);
$loader = new ArrayLoader([
-1
View File
@@ -22,7 +22,6 @@ namespace Twig\Tests\Extension;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
use Twig\Environment;
use Twig\Error\RuntimeError;
use Twig\Extension\CoreExtension;
+1 -2
View File
@@ -65,8 +65,7 @@ public function block_foo(array \$context, array \$blocks = []): iterable
\$macros = \$this->macros;
yield from [];
}
EOF
, new Environment(new ArrayLoader()),
EOF, new Environment(new ArrayLoader()),
];
return $tests;
+1 -1
View File
@@ -88,7 +88,7 @@ class TestTest extends NodeTestCase
protected static function createEnvironment(): Environment
{
$env = new Environment(new ArrayLoader());
$env->addTest(new TwigTest('anonymous', function () {}));
$env->addTest(new TwigTest('anonymous', static function () {}));
$env->addTest(new TwigTest('barbar', twig_tests_test_barbar(...), ['is_variadic' => true, 'need_context' => true]));
return $env;
+1 -2
View File
@@ -192,8 +192,7 @@ yield from (\$_v1 = function (\$iterator, &\$context, \$blocks, \$recurseFunc, \
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
})(\$_v0, \$context, \$blocks, \$_v1, 0);
EOF
, $env];
EOF, $env];
return $tests;
}
+1 -2
View File
@@ -67,8 +67,7 @@ EOF
yield "foo";
yield from [];
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
EOF
, new Environment(new ArrayLoader()),
EOF, new Environment(new ArrayLoader()),
];
$names = new Nodes([new AssignContextVariable('foo', 1)], 1);