From 76062c8d519a0bbeeb3f8468abd5a36f5c74bfcd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 19 Jan 2025 16:54:05 +0100 Subject: [PATCH] Fix CS --- extra/cache-extra/Tests/IntegrationTest.php | 2 +- extra/markdown-extra/Tests/FunctionalTest.php | 2 +- src/Extension/AbstractExtension.php | 2 +- src/Extension/CoreExtension.php | 2 +- src/Lexer.php | 2 +- src/Template.php | 3 ++- tests/DeprecatedCallableInfoTest.php | 4 ++-- tests/EnvironmentTest.php | 4 ++-- tests/ErrorTest.php | 10 +++++----- tests/ExpressionParserTest.php | 10 +++++----- tests/Extension/CoreTest.php | 2 +- tests/Extension/SandboxTest.php | 6 +++--- tests/Node/Expression/FilterTest.php | 2 +- 13 files changed, 26 insertions(+), 25 deletions(-) diff --git a/extra/cache-extra/Tests/IntegrationTest.php b/extra/cache-extra/Tests/IntegrationTest.php index c439976f9..ab72d6442 100644 --- a/extra/cache-extra/Tests/IntegrationTest.php +++ b/extra/cache-extra/Tests/IntegrationTest.php @@ -29,7 +29,7 @@ class IntegrationTest extends IntegrationTestCase protected function getRuntimeLoaders() { return [ - new class() implements RuntimeLoaderInterface { + new class implements RuntimeLoaderInterface { public function load(string $class): ?object { return CacheRuntime::class === $class ? new CacheRuntime(new ArrayAdapter()) : null; diff --git a/extra/markdown-extra/Tests/FunctionalTest.php b/extra/markdown-extra/Tests/FunctionalTest.php index 154d75a9c..72b277e34 100644 --- a/extra/markdown-extra/Tests/FunctionalTest.php +++ b/extra/markdown-extra/Tests/FunctionalTest.php @@ -37,7 +37,7 @@ Hello ===== Great! -EOF +EOF, ])); $twig->addExtension(new MarkdownExtension()); $twig->addRuntimeLoader(new class($class) implements RuntimeLoaderInterface { diff --git a/src/Extension/AbstractExtension.php b/src/Extension/AbstractExtension.php index 4234df087..26c00c680 100644 --- a/src/Extension/AbstractExtension.php +++ b/src/Extension/AbstractExtension.php @@ -53,7 +53,7 @@ abstract class AbstractExtension implements LastModifiedExtensionInterface $lastModified = filemtime($filename); // Track modifications of the runtime class if it exists and follows the naming convention - if (str_ends_with($filename, 'Extension.php') && is_file($filename = substr($filename, 0, -13) . 'Runtime.php')) { + if (str_ends_with($filename, 'Extension.php') && is_file($filename = substr($filename, 0, -13).'Runtime.php')) { $lastModified = max($lastModified, filemtime($filename)); } diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index e9976c139..b83a0fed1 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -917,7 +917,7 @@ final class CoreExtension extends AbstractExtension } /** - * Invokes a callable + * Invokes a callable. * * @internal */ diff --git a/src/Lexer.php b/src/Lexer.php index 0338fd874..e2a030b18 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -53,7 +53,7 @@ class Lexer (?(?&LNUM)(?:(?&FRAC))?) # Decimal number 123_456.456 )(?:(?&DNUM)(?:(?&EXPONENT))?) # 123_456.456E+10 /Ax'; - + public const REGEX_DQ_STRING_DELIM = '/"/A'; public const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As'; public const REGEX_INLINE_COMMENT = '/#[^\n]*/A'; diff --git a/src/Template.php b/src/Template.php index 26f5b5d81..156752f8b 100644 --- a/src/Template.php +++ b/src/Template.php @@ -318,6 +318,7 @@ abstract class Template /** * @internal + * * @return $this */ public function unwrap(): self @@ -492,7 +493,7 @@ abstract class Template return $parent->hasMacro($name, $context); } - protected function getTemplateForMacro(string $name, array $context, int $line, Source $source): Template + protected function getTemplateForMacro(string $name, array $context, int $line, Source $source): self { if (method_exists($this, $name)) { return $this; diff --git a/tests/DeprecatedCallableInfoTest.php b/tests/DeprecatedCallableInfoTest.php index 4e6d1583c..454d826ef 100644 --- a/tests/DeprecatedCallableInfoTest.php +++ b/tests/DeprecatedCallableInfoTest.php @@ -30,7 +30,7 @@ class DeprecatedCallableInfoTest extends TestCase if (\E_USER_DEPRECATED === $type) { $deprecations[] = $msg; } - + return false; }); @@ -62,7 +62,7 @@ class DeprecatedCallableInfoTest extends TestCase if (\E_USER_DEPRECATED === $type) { $deprecations[] = $msg; } - + return false; }); diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index f378b6b38..34774db1c 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -179,7 +179,7 @@ class EnvironmentTest extends TestCase // force compilation $twig = new Environment($loader = new ArrayLoader(['index' => '{{ foo }}']), $options); - $twig->addExtension($extension = new class() extends AbstractExtension { + $twig->addExtension($extension = new class extends AbstractExtension { public bool $throw = false; public function getFilters(): array @@ -475,7 +475,7 @@ EOF public function testResettingGlobals() { $twig = new Environment(new ArrayLoader(['index' => ''])); - $twig->addExtension(new class() extends AbstractExtension implements GlobalsInterface { + $twig->addExtension(new class extends AbstractExtension implements GlobalsInterface { public function getGlobals(): array { return [ diff --git a/tests/ErrorTest.php b/tests/ErrorTest.php index d29112cd7..b7da2d505 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -41,7 +41,7 @@ class ErrorTest extends TestCase {% block foo %} {{ foo.bar }} {% endblock %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -70,7 +70,7 @@ EOHTML {% block foo %} {{ foo.bar }} {% endblock %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -163,7 +163,7 @@ EOHTML {% for n in variable|filter(x => x > 3) %} This list contains {{n}}. {% endfor %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['debug' => true, 'cache' => false]); @@ -190,7 +190,7 @@ EOHTML {% for n in variable|map(x => x * 3) %} {{- n -}} {% endfor %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['debug' => true, 'cache' => false]); @@ -215,7 +215,7 @@ EOHTML 'reduce-null.html' => << carry + x) }} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['debug' => true, 'cache' => false]); diff --git a/tests/ExpressionParserTest.php b/tests/ExpressionParserTest.php index 9b9d9b504..d3887e938 100644 --- a/tests/ExpressionParserTest.php +++ b/tests/ExpressionParserTest.php @@ -408,7 +408,7 @@ class ExpressionParserTest extends TestCase public function testCompiledCodeForDynamicTest() { $env = new Environment(new ArrayLoader(['index' => '{{ "a" is foo_foo_bar_bar }}']), ['cache' => false, 'autoescape' => false]); - $env->addExtension(new class() extends AbstractExtension { + $env->addExtension(new class extends AbstractExtension { public function getTests() { return [ @@ -423,7 +423,7 @@ class ExpressionParserTest extends TestCase public function testCompiledCodeForDynamicFunction() { $env = new Environment(new ArrayLoader(['index' => '{{ foo_foo_bar_bar("a") }}']), ['cache' => false, 'autoescape' => false]); - $env->addExtension(new class() extends AbstractExtension { + $env->addExtension(new class extends AbstractExtension { public function getFunctions() { return [ @@ -438,7 +438,7 @@ class ExpressionParserTest extends TestCase public function testCompiledCodeForDynamicFilter() { $env = new Environment(new ArrayLoader(['index' => '{{ "a"|foo_foo_bar_bar }}']), ['cache' => false, 'autoescape' => false]); - $env->addExtension(new class() extends AbstractExtension { + $env->addExtension(new class extends AbstractExtension { public function getFilters() { return [ @@ -569,10 +569,10 @@ class ExpressionParserTest extends TestCase public function testUnaryPrecedenceChange() { $env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]); - $env->addExtension(new class () extends AbstractExtension { + $env->addExtension(new class extends AbstractExtension { public function getOperators() { - $class = new class (new ConstantExpression('foo', 1), 1) extends AbstractUnary { + $class = new class(new ConstantExpression('foo', 1), 1) extends AbstractUnary { public function operator(Compiler $compiler): Compiler { return $compiler->raw('!'); diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index edce0d3ee..bbea3d56c 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -58,7 +58,7 @@ class CoreTest extends TestCase { return [ 'empty' => [[]], - 'non-countable' => [new class() extends \ArrayObject { + 'non-countable' => [new class extends \ArrayObject { }], ]; } diff --git a/tests/Extension/SandboxTest.php b/tests/Extension/SandboxTest.php index 9993370f6..3fb1f65de 100644 --- a/tests/Extension/SandboxTest.php +++ b/tests/Extension/SandboxTest.php @@ -565,7 +565,7 @@ EOF public function testSandboxSourcePolicyEnableReturningFalse() { - $twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface { + $twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class implements \Twig\Sandbox\SourcePolicyInterface { public function enableSandbox(Source $source): bool { return '1_basic' != $source->getName(); @@ -576,7 +576,7 @@ EOF public function testSandboxSourcePolicyEnableReturningTrue() { - $twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface { + $twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class implements \Twig\Sandbox\SourcePolicyInterface { public function enableSandbox(Source $source): bool { return '1_basic' === $source->getName(); @@ -588,7 +588,7 @@ EOF public function testSandboxSourcePolicyFalseDoesntOverrideOtherEnables() { - $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface { + $twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], [], new class implements \Twig\Sandbox\SourcePolicyInterface { public function enableSandbox(Source $source): bool { return false; diff --git a/tests/Node/Expression/FilterTest.php b/tests/Node/Expression/FilterTest.php index ff4484d4e..a7134c4f9 100644 --- a/tests/Node/Expression/FilterTest.php +++ b/tests/Node/Expression/FilterTest.php @@ -180,7 +180,7 @@ class FilterTest extends NodeTestCase private static function createExtension(): AbstractExtension { - return new class() extends AbstractExtension { + return new class extends AbstractExtension { public function getFilters(): array { return [