Skip to content

Commit 861215c

Browse files
committed
Fix CS
1 parent eb516c9 commit 861215c

37 files changed

+84
-111
lines changed

.php-cs-fixer.dist.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

3-
return (new PhpCsFixer\Config())
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
6+
7+
return (new Config())
48
->setRules([
59
'@Symfony' => true,
610
'@Symfony:risky' => true,
@@ -11,19 +15,11 @@
1115
'no_unreachable_default_argument_value' => false,
1216
'braces' => ['allow_single_line_closure' => true],
1317
'heredoc_to_nowdoc' => false,
18+
'single_line_throw' => false,
1419
'ordered_imports' => true,
1520
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
16-
'header_comment' => [
17-
'header' => <<<EOF
18-
This file is part of Twig.
19-
20-
(c) Fabien Potencier
21-
22-
For the full copyright and license information, please view the LICENSE
23-
file that was distributed with this source code.
24-
EOF
25-
],
2621
])
2722
->setRiskyAllowed(true)
28-
->setFinder((new PhpCsFixer\Finder())->in(__DIR__))
23+
->setParallelConfig(ParallelConfigFactory::detect())
24+
->setFinder((new Finder())->in(__DIR__))
2925
;

bin/generate_operators_precedence.php

Lines changed: 2 additions & 2 deletions
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) {
@@ -72,7 +72,7 @@
7272
fwrite($output, '| Precedence | Operator | Type | Associativity | Description'.str_repeat(' ', $descriptionLength - 11)." |\n");
7373
fwrite($output, '+============+==================+=========+===============+'.str_repeat('=', $descriptionLength + 2).'+');
7474

75-
usort($expressionParsers, function ($a, $b) {
75+
usort($expressionParsers, static function ($a, $b) {
7676
$aPrecedence = $a->getPrecedenceChange() ? $a->getPrecedenceChange()->getNewPrecedence() : $a->getPrecedence();
7777
$bPrecedence = $b->getPrecedenceChange() ? $b->getPrecedenceChange()->getNewPrecedence() : $b->getPrecedence();
7878

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
"require-dev": {
3333
"symfony/phpunit-bridge": "^5.4.9|^6.4|^7.0",
3434
"psr/container": "^1.0|^2.0",
35-
"phpstan/phpstan": "^2.0"
35+
"phpstan/phpstan": "^2.0",
36+
"php-cs-fixer/shim": "^3.0"
3637
},
3738
"autoload": {
3839
"files": [

doc/_build/build.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(new Application('Twig docs Builder', '1.0'))
2424
->register('build-docs')
2525
->addOption('disable-cache', null, InputOption::VALUE_NONE, 'Use this option to force a full regeneration of all doc contents')
26-
->setCode(function (InputInterface $input, OutputInterface $output) {
26+
->setCode(static function (InputInterface $input, OutputInterface $output) {
2727
$io = new SymfonyStyle($input, $output);
2828
$io->text('Building all Twig docs...');
2929

extra/cache-extra/Tests/FunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testIsCached()
2929
$twig = $this->createEnvironment(['index' => '{% cache "city;v1" %}{{- city -}}{% endcache %}'], $cache);
3030

3131
$this->assertSame('Paris', $twig->render('index', ['city' => 'Paris']));
32-
$value = $cache->get('city;v1', function () { throw new \RuntimeException('Key should be in the cache'); });
32+
$value = $cache->get('city;v1', static function () { throw new \RuntimeException('Key should be in the cache'); });
3333
$this->assertSame('Paris', $value);
3434
}
3535

extra/html-extra/HtmlExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ public static function htmlClasses(...$args): string
114114
}
115115

116116
/**
117-
* @param string|list<string|null> $base
117+
* @param string|list<string|null> $base
118118
* @param array<string, array<string, string|array<string>>> $variants
119-
* @param array<array<string, string|array<string>>> $compoundVariants
120-
* @param array<string, string> $defaultVariant
119+
* @param array<array<string, string|array<string>>> $compoundVariants
120+
* @param array<string, string> $defaultVariant
121121
*
122122
* @internal
123123
*/

extra/markdown-extra/Tests/FunctionalTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,15 @@ public static function getMarkdownTests()
6767
6868
Great!
6969
{% endapply %}
70-
EOF
71-
, "<h1>Hello</h1>\n+<p>Great!</p>"],
70+
EOF, "<h1>Hello</h1>\n+<p>Great!</p>"],
7271
[<<<EOF
7372
{% apply markdown_to_html %}
7473
Hello
7574
=====
7675
7776
Great!
7877
{% endapply %}
79-
EOF
80-
, "<h1>Hello</h1>\n+<p>Great!</p>"],
78+
EOF, "<h1>Hello</h1>\n+<p>Great!</p>"],
8179
["{{ include('html')|markdown_to_html }}", "<h1>Hello</h1>\n+<p>Great!</p>"],
8280
];
8381
}

extra/twig-extra-bundle/DependencyInjection/TwigExtraExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public function load(array $configs, ContainerBuilder $container)
3737
$this->doLoad($configs, $container);
3838
}
3939
}
40-
4140
}
4241

4342
/**

src/ExpressionParser/Infix/AssignmentExpressionParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public function parse(Parser $parser, AbstractExpression $left, Token $token): A
5151
if ($left instanceof ArrayExpression) {
5252
if ($left->isSequence()) {
5353
return new SequenceDestructuringSetBinary($left, $right, $token->getLine());
54-
} else {
55-
return new ObjectDestructuringSetBinary($left, $right, $token->getLine());
5654
}
57-
} else {
58-
return new SetBinary($left, $right, $token->getLine());
55+
56+
return new ObjectDestructuringSetBinary($left, $right, $token->getLine());
5957
}
58+
59+
return new SetBinary($left, $right, $token->getLine());
6060
}
6161

6262
public function getDescription(): string

src/Extension/CoreExtension.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ final class CoreExtension extends AbstractExtension
134134

135135
private $dateFormats = ['F j, Y H:i', '%d days'];
136136
private $numberFormat = [0, '.', ','];
137-
private $timezone = null;
137+
private $timezone;
138138

139139
/**
140140
* Sets the default format to be used by the date filter.
@@ -1128,9 +1128,9 @@ public static function compare($a, $b)
11281128
}
11291129
if ((int) $bTrim == $bTrim) {
11301130
return $a <=> (int) $bTrim;
1131-
} else {
1132-
return (float) $a <=> (float) $bTrim;
11331131
}
1132+
1133+
return (float) $a <=> (float) $bTrim;
11341134
}
11351135
if (\is_string($a) && \is_int($b)) {
11361136
$aTrim = trim($a, " \t\n\r\v\f");
@@ -1139,9 +1139,9 @@ public static function compare($a, $b)
11391139
}
11401140
if ((int) $aTrim == $aTrim) {
11411141
return (int) $aTrim <=> $b;
1142-
} else {
1143-
return (float) $aTrim <=> (float) $b;
11441142
}
1143+
1144+
return (float) $aTrim <=> (float) $b;
11451145
}
11461146

11471147
// float <=> string
@@ -1179,7 +1179,7 @@ public static function compare($a, $b)
11791179
*/
11801180
public static function matches(string $regexp, ?string $str): int
11811181
{
1182-
set_error_handler(function ($t, $m) use ($regexp) {
1182+
set_error_handler(static function ($t, $m) use ($regexp) {
11831183
throw new RuntimeError(\sprintf('Regexp "%s" passed to "matches" is not valid', $regexp).substr($m, 12));
11841184
});
11851185
try {
@@ -2148,7 +2148,7 @@ public static function parseParentFunction(Parser $parser, Node $fakeNode, $args
21482148
*/
21492149
public static function parseBlockFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
21502150
{
2151-
$fakeFunction = new TwigFunction('block', fn ($name, $template = null) => null);
2151+
$fakeFunction = new TwigFunction('block', static fn ($name, $template = null) => null);
21522152
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
21532153

21542154
return new BlockReferenceExpression($args[0], $args[1] ?? null, $line);
@@ -2159,7 +2159,7 @@ public static function parseBlockFunction(Parser $parser, Node $fakeNode, $args,
21592159
*/
21602160
public static function parseAttributeFunction(Parser $parser, Node $fakeNode, $args, int $line): AbstractExpression
21612161
{
2162-
$fakeFunction = new TwigFunction('attribute', fn ($variable, $attribute, $arguments = null) => null);
2162+
$fakeFunction = new TwigFunction('attribute', static fn ($variable, $attribute, $arguments = null) => null);
21632163
$args = (new CallableArgumentsExtractor($fakeNode, $fakeFunction))->extractArguments($args);
21642164

21652165
/*

0 commit comments

Comments
 (0)