diff --git a/extra/cache-extra/Tests/IntegrationTest.php b/extra/cache-extra/Tests/IntegrationTest.php index c439976f9b9..ab72d6442da 100644 --- a/extra/cache-extra/Tests/IntegrationTest.php +++ b/extra/cache-extra/Tests/IntegrationTest.php @@ -29,7 +29,7 @@ public function getExtensions() 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 154d75a9c39..72b277e3436 100644 --- a/extra/markdown-extra/Tests/FunctionalTest.php +++ b/extra/markdown-extra/Tests/FunctionalTest.php @@ -37,7 +37,7 @@ public function testMarkdown(string $template, string $expected) ===== 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 4234df087f6..26c00c68066 100644 --- a/src/Extension/AbstractExtension.php +++ b/src/Extension/AbstractExtension.php @@ -53,7 +53,7 @@ public function getLastModified(): int $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 e9976c1390c..b83a0fed1db 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -917,7 +917,7 @@ public static function keys($array): array } /** - * Invokes a callable + * Invokes a callable. * * @internal */ diff --git a/src/Lexer.php b/src/Lexer.php index 0338fd874ff..e2a030b18c2 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 26f5b5d8154..156752f8b37 100644 --- a/src/Template.php +++ b/src/Template.php @@ -318,6 +318,7 @@ protected function loadTemplate($template, $templateName = null, $line = null, $ /** * @internal + * * @return $this */ public function unwrap(): self @@ -492,7 +493,7 @@ protected function hasMacro(string $name, array $context): bool 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 4e6d1583ce5..454d826ef4c 100644 --- a/tests/DeprecatedCallableInfoTest.php +++ b/tests/DeprecatedCallableInfoTest.php @@ -30,7 +30,7 @@ public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info) if (\E_USER_DEPRECATED === $type) { $deprecations[] = $msg; } - + return false; }); @@ -62,7 +62,7 @@ public function testTriggerDeprecationWithoutFileOrLine() if (\E_USER_DEPRECATED === $type) { $deprecations[] = $msg; } - + return false; }); diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index f378b6b3895..34774db1c5b 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -179,7 +179,7 @@ public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate() // 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 @@ protected function getMockLoader($templateName, $templateContent) 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 d29112cd741..b7da2d50518 100644 --- a/tests/ErrorTest.php +++ b/tests/ErrorTest.php @@ -41,7 +41,7 @@ public function testTwigExceptionGuessWithMissingVarAndArrayLoader() {% block foo %} {{ foo.bar }} {% endblock %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -70,7 +70,7 @@ public function testTwigExceptionGuessWithExceptionAndArrayLoader() {% block foo %} {{ foo.bar }} {% endblock %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]); @@ -163,7 +163,7 @@ public function testTwigArrayFilterThrowsRuntimeExceptions() {% 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 @@ public function testTwigArrayMapThrowsRuntimeExceptions() {% for n in variable|map(x => x * 3) %} {{- n -}} {% endfor %} -EOHTML +EOHTML, ]); $twig = new Environment($loader, ['debug' => true, 'cache' => false]); @@ -215,7 +215,7 @@ public function testTwigArrayReduceThrowsRuntimeExceptions() '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 9b9d9b50488..d3887e93880 100644 --- a/tests/ExpressionParserTest.php +++ b/tests/ExpressionParserTest.php @@ -408,7 +408,7 @@ public function testUnknownTestWithoutSuggestions() 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 @@ public function getTests() 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 @@ public function getFunctions() 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 @@ public function testTwoWordTestPrecedence() 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 edce0d3eede..bbea3d56c2c 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -58,7 +58,7 @@ public static function provideCycleInvalidCases() { 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 9993370f6d4..3fb1f65de65 100644 --- a/tests/Extension/SandboxTest.php +++ b/tests/Extension/SandboxTest.php @@ -565,7 +565,7 @@ protected function getEnvironment($sandboxed, $options, $templates, $tags = [], 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 @@ public function enableSandbox(Source $source): bool 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 @@ public function enableSandbox(Source $source): bool 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 ff4484d4efd..a7134c4f9dd 100644 --- a/tests/Node/Expression/FilterTest.php +++ b/tests/Node/Expression/FilterTest.php @@ -180,7 +180,7 @@ protected static function createEnvironment(): Environment private static function createExtension(): AbstractExtension { - return new class() extends AbstractExtension { + return new class extends AbstractExtension { public function getFilters(): array { return [