From f5e10e10f1b3f7778e1e5099d0e3c7b42142be9c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 7 Aug 2024 19:34:09 +0200 Subject: [PATCH] Fix CS --- .../TokenParser/CacheTokenParser.php | 2 - extra/markdown-extra/Tests/FunctionalTest.php | 4 +- extra/string-extra/StringExtension.php | 2 +- src/Extension/EscaperExtension.php | 2 +- src/Node/Node.php | 2 +- src/Runtime/EscaperRuntime.php | 2 +- tests/Cache/ChainTest.php | 4 +- tests/Cache/ReadOnlyFilesystemTest.php | 2 +- tests/ExpressionParserTest.php | 144 +++++++++--------- tests/Node/DeprecatedTest.php | 2 +- tests/Node/Expression/Filter/RawTest.php | 2 +- tests/Node/Expression/FilterTest.php | 1 + tests/Node/IncludeTest.php | 2 +- tests/Node/ModuleTest.php | 6 +- tests/TemplateTest.php | 1 - 15 files changed, 88 insertions(+), 90 deletions(-) diff --git a/extra/cache-extra/TokenParser/CacheTokenParser.php b/extra/cache-extra/TokenParser/CacheTokenParser.php index e6d6e1c84..61d5d2877 100644 --- a/extra/cache-extra/TokenParser/CacheTokenParser.php +++ b/extra/cache-extra/TokenParser/CacheTokenParser.php @@ -13,9 +13,7 @@ namespace Twig\Extra\Cache\TokenParser; use Twig\Error\SyntaxError; use Twig\Extra\Cache\Node\CacheNode; -use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\Filter\RawFilter; -use Twig\Node\Expression\FilterExpression; use Twig\Node\Node; use Twig\Node\PrintNode; use Twig\Token; diff --git a/extra/markdown-extra/Tests/FunctionalTest.php b/extra/markdown-extra/Tests/FunctionalTest.php index 42f4ff65a..0d9b73a59 100644 --- a/extra/markdown-extra/Tests/FunctionalTest.php +++ b/extra/markdown-extra/Tests/FunctionalTest.php @@ -70,7 +70,7 @@ Hello Great! {% endapply %} EOF - , "

Hello

\n+

Great!

"], + , "

Hello

\n+

Great!

"], [<<Hello\n+

Great!

"], + , "

Hello

\n+

Great!

"], ["{{ include('html')|markdown_to_html }}", "

Hello

\n+

Great!

"], ]; } diff --git a/extra/string-extra/StringExtension.php b/extra/string-extra/StringExtension.php index e541e7c16..e0abb845f 100644 --- a/extra/string-extra/StringExtension.php +++ b/extra/string-extra/StringExtension.php @@ -84,7 +84,7 @@ final class StringExtension extends AbstractExtension case 'en': return $this->englishInflector ?? $this->englishInflector = new EnglishInflector(); default: - throw new \InvalidArgumentException(sprintf('Locale "%s" is not supported.', $locale)); + throw new \InvalidArgumentException(\sprintf('Locale "%s" is not supported.', $locale)); } } } diff --git a/src/Extension/EscaperExtension.php b/src/Extension/EscaperExtension.php index f453ada93..d8e9b6e48 100644 --- a/src/Extension/EscaperExtension.php +++ b/src/Extension/EscaperExtension.php @@ -118,7 +118,7 @@ final class EscaperExtension extends AbstractExtension /** * Defines a new escaper to be used via the escape filter. * - * @param string $strategy The strategy name that should be used as a strategy in the escape call + * @param string $strategy The strategy name that should be used as a strategy in the escape call * @param callable(Environment, string, string): string $callable A valid PHP callable * * @deprecated since Twig 3.10 diff --git a/src/Node/Node.php b/src/Node/Node.php index 17b60dc35..e0e473e8c 100644 --- a/src/Node/Node.php +++ b/src/Node/Node.php @@ -54,7 +54,7 @@ class Node implements \Countable, \IteratorAggregate { $attributes = []; foreach ($this->attributes as $name => $value) { - $attributes[] = \sprintf('%s: %s', $name, is_callable($value) ? '\Closure' : str_replace("\n", '', var_export($value, true))); + $attributes[] = \sprintf('%s: %s', $name, \is_callable($value) ? '\Closure' : str_replace("\n", '', var_export($value, true))); } $repr = [static::class.'('.implode(', ', $attributes)]; diff --git a/src/Runtime/EscaperRuntime.php b/src/Runtime/EscaperRuntime.php index 4df834306..b1dac9640 100644 --- a/src/Runtime/EscaperRuntime.php +++ b/src/Runtime/EscaperRuntime.php @@ -36,7 +36,7 @@ final class EscaperRuntime implements RuntimeExtensionInterface /** * Defines a new escaper to be used via the escape filter. * - * @param string $strategy The strategy name that should be used as a strategy in the escape call + * @param string $strategy The strategy name that should be used as a strategy in the escape call * @param callable(string $string, string $charset): string $callable A valid PHP callable */ public function setEscaper($strategy, callable $callable) diff --git a/tests/Cache/ChainTest.php b/tests/Cache/ChainTest.php index f87e16293..bb6ed7cf3 100644 --- a/tests/Cache/ChainTest.php +++ b/tests/Cache/ChainTest.php @@ -121,13 +121,13 @@ class ChainTest extends TestCase public function testWrite() { $content = $this->generateSource(); - + $cacheA = new FilesystemCache($this->directory.'/A'); $keyA = $cacheA->generateKey('_test_', $this->classname); $this->assertFileDoesNotExist($keyA); $this->assertFileDoesNotExist($this->directory.'/A'); - + $cacheB = new FilesystemCache($this->directory.'/B'); $keyB = $cacheB->generateKey('_test_', $this->classname); diff --git a/tests/Cache/ReadOnlyFilesystemTest.php b/tests/Cache/ReadOnlyFilesystemTest.php index fe6dffcdb..424f60523 100644 --- a/tests/Cache/ReadOnlyFilesystemTest.php +++ b/tests/Cache/ReadOnlyFilesystemTest.php @@ -12,8 +12,8 @@ namespace Twig\Tests\Cache; */ use PHPUnit\Framework\TestCase; -use Twig\Tests\FilesystemHelper; use Twig\Cache\ReadOnlyFilesystemCache; +use Twig\Tests\FilesystemHelper; class ReadOnlyFilesystemTest extends TestCase { diff --git a/tests/ExpressionParserTest.php b/tests/ExpressionParserTest.php index 8dd91ba67..b1e3d5017 100644 --- a/tests/ExpressionParserTest.php +++ b/tests/ExpressionParserTest.php @@ -93,73 +93,73 @@ class ExpressionParserTest extends TestCase return [ // simple sequence ['{{ [1, 2] }}', new ArrayExpression([ - new ConstantExpression(0, 1), - new ConstantExpression(1, 1), + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), - new ConstantExpression(1, 1), - new ConstantExpression(2, 1), - ], 1), + new ConstantExpression(1, 1), + new ConstantExpression(2, 1), + ], 1), ], // sequence with trailing , ['{{ [1, 2, ] }}', new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), + + new ConstantExpression(1, 1), + new ConstantExpression(2, 1), + ], 1), + ], + + // simple mapping + ['{{ {"a": "b", "b": "c"} }}', new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), + + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), + ], 1), + ], + + // mapping with trailing , + ['{{ {"a": "b", "b": "c", } }}', new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), + + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), + ], 1), + ], + + // mapping in a sequence + ['{{ [1, {"a": "b", "b": "c"}] }}', new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), + + new ConstantExpression(1, 1), + new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), + + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), + ], 1), + ], 1), + ], + + // sequence in a mapping + ['{{ {"a": [1, 2], "b": "c"} }}', new ArrayExpression([ + new ConstantExpression('a', 1), + new ArrayExpression([ new ConstantExpression(0, 1), new ConstantExpression(1, 1), new ConstantExpression(1, 1), new ConstantExpression(2, 1), ], 1), - ], - - // simple mapping - ['{{ {"a": "b", "b": "c"} }}', new ArrayExpression([ - new ConstantExpression('a', 1), - new ConstantExpression('b', 1), - - new ConstantExpression('b', 1), - new ConstantExpression('c', 1), - ], 1), - ], - - // mapping with trailing , - ['{{ {"a": "b", "b": "c", } }}', new ArrayExpression([ - new ConstantExpression('a', 1), - new ConstantExpression('b', 1), - - new ConstantExpression('b', 1), - new ConstantExpression('c', 1), - ], 1), - ], - - // mapping in a sequence - ['{{ [1, {"a": "b", "b": "c"}] }}', new ArrayExpression([ - new ConstantExpression(0, 1), - new ConstantExpression(1, 1), - - new ConstantExpression(1, 1), - new ArrayExpression([ - new ConstantExpression('a', 1), - new ConstantExpression('b', 1), - - new ConstantExpression('b', 1), - new ConstantExpression('c', 1), - ], 1), - ], 1), - ], - - // sequence in a mapping - ['{{ {"a": [1, 2], "b": "c"} }}', new ArrayExpression([ - new ConstantExpression('a', 1), - new ArrayExpression([ - new ConstantExpression(0, 1), - new ConstantExpression(1, 1), - - new ConstantExpression(1, 1), - new ConstantExpression(2, 1), - ], 1), - new ConstantExpression('b', 1), - new ConstantExpression('c', 1), - ], 1), + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), + ], 1), ], ['{{ {a, b} }}', new ArrayExpression([ new ConstantExpression('a', 1), @@ -170,29 +170,29 @@ class ExpressionParserTest extends TestCase // sequence with spread operator ['{{ [1, 2, ...foo] }}', - new ArrayExpression([ - new ConstantExpression(0, 1), - new ConstantExpression(1, 1), + new ArrayExpression([ + new ConstantExpression(0, 1), + new ConstantExpression(1, 1), - new ConstantExpression(1, 1), - new ConstantExpression(2, 1), + new ConstantExpression(1, 1), + new ConstantExpression(2, 1), - new ConstantExpression(2, 1), - $this->createNameExpression('foo', ['spread' => true]), - ], 1)], + new ConstantExpression(2, 1), + $this->createNameExpression('foo', ['spread' => true]), + ], 1)], // mapping with spread operator ['{{ {"a": "b", "b": "c", ...otherLetters} }}', - new ArrayExpression([ - new ConstantExpression('a', 1), - new ConstantExpression('b', 1), + new ArrayExpression([ + new ConstantExpression('a', 1), + new ConstantExpression('b', 1), - new ConstantExpression('b', 1), - new ConstantExpression('c', 1), + new ConstantExpression('b', 1), + new ConstantExpression('c', 1), - new ConstantExpression(0, 1), - $this->createNameExpression('otherLetters', ['spread' => true]), - ], 1)], + new ConstantExpression(0, 1), + $this->createNameExpression('otherLetters', ['spread' => true]), + ], 1)], ]; } diff --git a/tests/Node/DeprecatedTest.php b/tests/Node/DeprecatedTest.php index 63259eda3..90e958cb4 100644 --- a/tests/Node/DeprecatedTest.php +++ b/tests/Node/DeprecatedTest.php @@ -77,7 +77,7 @@ EOF \$$varName = foo(); @trigger_error(\$$varName." (\"foo.twig\" at line 1).", E_USER_DEPRECATED); EOF - , $environment]; + , $environment]; return $tests; } diff --git a/tests/Node/Expression/Filter/RawTest.php b/tests/Node/Expression/Filter/RawTest.php index 89e495cca..72999fd44 100644 --- a/tests/Node/Expression/Filter/RawTest.php +++ b/tests/Node/Expression/Filter/RawTest.php @@ -24,7 +24,7 @@ class RawTest extends NodeTestCase $this->assertSame(12, $filter->getTemplateLine()); $this->assertSame('raw', $filter->getNode('filter')->getAttribute('value')); $this->assertSame($node, $filter->getNode('node')); - $this->assertSame(0, count($filter->getNode('arguments'))); + $this->assertCount(0, $filter->getNode('arguments')); } public function getTests() diff --git a/tests/Node/Expression/FilterTest.php b/tests/Node/Expression/FilterTest.php index 9ce5e4e4c..3e5feebe2 100644 --- a/tests/Node/Expression/FilterTest.php +++ b/tests/Node/Expression/FilterTest.php @@ -190,6 +190,7 @@ class FilterTest extends NodeTestCase if ($this->extension) { return $this->extension; } + return $this->extension = new class() extends AbstractExtension { public function getFilters(): array { diff --git a/tests/Node/IncludeTest.php b/tests/Node/IncludeTest.php index 55454f8d4..446fbd293 100644 --- a/tests/Node/IncludeTest.php +++ b/tests/Node/IncludeTest.php @@ -88,7 +88,7 @@ if (\$__internal_%s) { yield from \$__internal_%s->unwrap()->yield(CoreExtension::toArray(["foo" => true])); } EOF - , null, true]; + , null, true]; return $tests; } diff --git a/tests/Node/ModuleTest.php b/tests/Node/ModuleTest.php index 974bc22ce..1306401df 100644 --- a/tests/Node/ModuleTest.php +++ b/tests/Node/ModuleTest.php @@ -121,7 +121,7 @@ class __TwigTemplate_%x extends Template } } EOF - , $twig, true]; + , $twig, true]; $import = new ImportNode(new ConstantExpression('foo.twig', 1), new AssignNameExpression('macro', 1), 2); @@ -207,7 +207,7 @@ class __TwigTemplate_%x extends Template } } EOF - , $twig, true]; + , $twig, true]; $set = new SetNode(false, new Node([new AssignNameExpression('foo', 4)]), new Node([new ConstantExpression('foo', 4)]), 4); $body = new Node([$set]); @@ -297,7 +297,7 @@ class __TwigTemplate_%x extends Template } } EOF - , $twig, true]; + , $twig, true]; return $tests; } diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 8ee46c19b..37d6fe62a 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -17,7 +17,6 @@ use Twig\Error\RuntimeError; use Twig\Extension\CoreExtension; use Twig\Extension\SandboxExtension; use Twig\Loader\ArrayLoader; -use Twig\Loader\LoaderInterface; use Twig\Sandbox\SecurityError; use Twig\Sandbox\SecurityPolicy; use Twig\Source;