Skip to content
Merged

Fix CS #4763

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'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'],
])
Expand Down
2 changes: 1 addition & 1 deletion bin/generate_operators_precedence.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
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) {
Expand Down
17 changes: 8 additions & 9 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@

if (!is_countable($values)) {
throw new RuntimeError('The "cycle" function expects a countable sequence as first argument.');

$values = self::toArray($values, false);

Check failure on line 426 in src/Extension/CoreExtension.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4)

Unreachable statement - code above always terminates.
}
}

Expand Down Expand Up @@ -1116,9 +1115,9 @@
}
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");
Expand All @@ -1127,9 +1126,9 @@
}
if ((int) $aTrim == $aTrim) {
return (int) $aTrim <=> $b;
} else {
return (float) $aTrim <=> (float) $b;
}

return (float) $aTrim <=> (float) $b;
}

// float <=> string
Expand Down Expand Up @@ -1167,7 +1166,7 @@
*/
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 {
Expand Down Expand Up @@ -2020,7 +2019,7 @@
*/
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);
Expand All @@ -2031,7 +2030,7 @@
*/
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);

/*
Expand All @@ -2051,7 +2050,7 @@
*/
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);
Expand Down
2 changes: 1 addition & 1 deletion tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function testOverrideExtension()
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([
Expand Down
1 change: 0 additions & 1 deletion tests/Extension/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

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;
Expand Down
3 changes: 1 addition & 2 deletions tests/Node/BlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Node/Expression/TestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private static function createTest(Environment $env, $node, $name, array $argume
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;
Expand Down
3 changes: 1 addition & 2 deletions tests/Node/ForTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ public static function provideTests(): iterable
\$context = array_intersect_key(\$context, \$parent) + \$parent;
yield from [];
})(\$_v0, \$context, \$blocks, \$_v1, 0);
EOF
, $env];
EOF, $env];

return $tests;
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Node/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ public static function provideTests(): iterable
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);
Expand Down
Loading