Skip to content

Commit 1787147

Browse files
committed
minor #4763 Fix CS (fabpot)
This PR was merged into the 4.x branch. Discussion ---------- Fix CS Commits ------- cdce18d Fix CS
2 parents df07638 + cdce18d commit 1787147

File tree

9 files changed

+15
-19
lines changed

9 files changed

+15
-19
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'braces' => ['allow_single_line_closure' => true],
1717
'heredoc_to_nowdoc' => false,
1818
'single_line_throw' => false,
19+
'phpdoc_to_comment' => ['ignored_tags' => ['var']],
1920
'ordered_imports' => true,
2021
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
2122
])

bin/generate_operators_precedence.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
fwrite($output, '| Precedence | Operator | Type | Associativity | Description'.str_repeat(' ', $descriptionLength - 11)." |\n");
3737
fwrite($output, '+============+==================+=========+===============+'.str_repeat('=', $descriptionLength + 2).'+');
3838

39-
usort($expressionParsers, fn ($a, $b) => $b->getPrecedence() <=> $a->getPrecedence());
39+
usort($expressionParsers, static fn ($a, $b) => $b->getPrecedence() <=> $a->getPrecedence());
4040

4141
$previous = null;
4242
foreach ($expressionParsers as $expressionParser) {

src/Extension/CoreExtension.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ public static function cycle($values, $position): mixed
423423

424424
if (!is_countable($values)) {
425425
throw new RuntimeError('The "cycle" function expects a countable sequence as first argument.');
426-
427426
$values = self::toArray($values, false);
428427
}
429428
}
@@ -1116,9 +1115,9 @@ public static function compare($a, $b)
11161115
}
11171116
if ((int) $bTrim == $bTrim) {
11181117
return $a <=> (int) $bTrim;
1119-
} else {
1120-
return (float) $a <=> (float) $bTrim;
11211118
}
1119+
1120+
return (float) $a <=> (float) $bTrim;
11221121
}
11231122
if (\is_string($a) && \is_int($b)) {
11241123
$aTrim = trim($a, " \t\n\r\v\f");
@@ -1127,9 +1126,9 @@ public static function compare($a, $b)
11271126
}
11281127
if ((int) $aTrim == $aTrim) {
11291128
return (int) $aTrim <=> $b;
1130-
} else {
1131-
return (float) $aTrim <=> (float) $b;
11321129
}
1130+
1131+
return (float) $aTrim <=> (float) $b;
11331132
}
11341133

11351134
// float <=> string
@@ -1167,7 +1166,7 @@ public static function compare($a, $b)
11671166
*/
11681167
public static function matches(string $regexp, ?string $str): int
11691168
{
1170-
set_error_handler(function ($t, $m) use ($regexp) {
1169+
set_error_handler(static function ($t, $m) use ($regexp) {
11711170
throw new RuntimeError(\sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
11721171
});
11731172
try {
@@ -2020,7 +2019,7 @@ public static function parseParentFunction(Parser $parser, Node $fakeNode, $args
20202019
*/
20212020
public static function parseBlockFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
20222021
{
2023-
$fakeFunction = new TwigFunction('block', fn ($name, $template = null) => null);
2022+
$fakeFunction = new TwigFunction('block', static fn ($name, $template = null) => null);
20242023
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
20252024

20262025
return new BlockReferenceExpression($args[0], $args[1] ?? null, $line);
@@ -2031,7 +2030,7 @@ public static function parseBlockFunction(Parser $parser, Node $fakeNode, $args,
20312030
*/
20322031
public static function parseAttributeFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
20332032
{
2034-
$fakeFunction = new TwigFunction('attribute', fn ($variable, $attribute, $arguments = null) => null);
2033+
$fakeFunction = new TwigFunction('attribute', static fn ($variable, $attribute, $arguments = null) => null);
20352034
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
20362035

20372036
/*
@@ -2051,7 +2050,7 @@ public static function parseAttributeFunction(Parser $parser, Node $fakeNode, $a
20512050
*/
20522051
public static function parseLoopFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
20532052
{
2054-
$fakeFunction = new TwigFunction('loop', fn ($iterator) => null);
2053+
$fakeFunction = new TwigFunction('loop', static fn ($iterator) => null);
20552054
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
20562055

20572056
$recurseArgs = new ArrayExpression([new ConstantExpression(0, $line), $args[0]], $line);

tests/EnvironmentTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public function testOverrideExtension()
360360
public function testAddRuntimeLoader()
361361
{
362362
$runtimeLoader = new FactoryRuntimeLoader([
363-
EnvironmentTest_Runtime::class => function () { return new EnvironmentTest_Runtime(); },
363+
EnvironmentTest_Runtime::class => static function () { return new EnvironmentTest_Runtime(); },
364364
]);
365365

366366
$loader = new ArrayLoader([

tests/Extension/CoreTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
use PHPUnit\Framework\Attributes\DataProvider;
2424
use PHPUnit\Framework\TestCase;
25-
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
2625
use Twig\Environment;
2726
use Twig\Error\RuntimeError;
2827
use Twig\Extension\CoreExtension;

tests/Node/BlockTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ public function block_foo(array \$context, array \$blocks = []): iterable
6565
\$macros = \$this->macros;
6666
yield from [];
6767
}
68-
EOF
69-
, new Environment(new ArrayLoader()),
68+
EOF, new Environment(new ArrayLoader()),
7069
];
7170

7271
return $tests;

tests/Node/Expression/TestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private static function createTest(Environment $env, $node, $name, array $argume
8888
protected static function createEnvironment(): Environment
8989
{
9090
$env = new Environment(new ArrayLoader());
91-
$env->addTest(new TwigTest('anonymous', function () {}));
91+
$env->addTest(new TwigTest('anonymous', static function () {}));
9292
$env->addTest(new TwigTest('barbar', twig_tests_test_barbar(...), ['is_variadic' => true, 'need_context' => true]));
9393

9494
return $env;

tests/Node/ForTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@ public static function provideTests(): iterable
192192
\$context = array_intersect_key(\$context, \$parent) + \$parent;
193193
yield from [];
194194
})(\$_v0, \$context, \$blocks, \$_v1, 0);
195-
EOF
196-
, $env];
195+
EOF, $env];
197196

198197
return $tests;
199198
}

tests/Node/SetTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public static function provideTests(): iterable
6767
yield "foo";
6868
yield from [];
6969
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
70-
EOF
71-
, new Environment(new ArrayLoader()),
70+
EOF, new Environment(new ArrayLoader()),
7271
];
7372

7473
$names = new Nodes([new AssignContextVariable('foo', 1)], 1);

0 commit comments

Comments
 (0)