From 14fc89ebead133b80a3a2215ec332ce715b26df1 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 30 Nov 2024 09:42:13 +0100 Subject: [PATCH] Fix CS --- extra/string-extra/StringExtension.php | 1 + src/ExpressionParser.php | 12 ++++-------- src/Extension/CoreExtension.php | 11 +++++------ src/Loader/FilesystemLoader.php | 2 +- src/Node/Expression/ConditionalExpression.php | 1 - src/Node/Expression/GetAttrExpression.php | 1 - src/Node/Expression/OperatorEscapeInterface.php | 2 +- src/Node/ModuleNode.php | 4 ++-- tests/LexerTest.php | 2 +- tests/Node/NodeTest.php | 2 +- 10 files changed, 16 insertions(+), 22 deletions(-) diff --git a/extra/string-extra/StringExtension.php b/extra/string-extra/StringExtension.php index 5327b9d0f..3ee7b7f2e 100644 --- a/extra/string-extra/StringExtension.php +++ b/extra/string-extra/StringExtension.php @@ -88,6 +88,7 @@ final class StringExtension extends AbstractExtension if (!class_exists(SpanishInflector::class)) { throw new RuntimeError('SpanishInflector is not available.'); } + return $this->spanishInflector ?? $this->spanishInflector = new SpanishInflector(); case 'fr': return $this->frenchInflector ?? $this->frenchInflector = new FrenchInflector(); diff --git a/src/ExpressionParser.php b/src/ExpressionParser.php index e7ba93805..eb60a43b3 100644 --- a/src/ExpressionParser.php +++ b/src/ExpressionParser.php @@ -931,10 +931,8 @@ class ExpressionParser $token = $stream->next(); if ( Token::NAME_TYPE == $token->getType() - || - Token::NUMBER_TYPE == $token->getType() - || - (Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue())) + || Token::NUMBER_TYPE == $token->getType() + || (Token::OPERATOR_TYPE == $token->getType() && preg_match(Lexer::REGEX_NAME, $token->getValue())) ) { $attribute = new ConstantExpression($token->getValue(), $token->getLine()); } else { @@ -949,11 +947,9 @@ class ExpressionParser if ( $node instanceof NameExpression - && - ( + && ( null !== $this->parser->getImportedSymbol('template', $node->getAttribute('name')) - || - '_self' === $node->getAttribute('name') && $attribute instanceof ConstantExpression + || '_self' === $node->getAttribute('name') && $attribute instanceof ConstantExpression ) ) { return new MacroReferenceExpression(new TemplateVariable($node->getAttribute('name'), $node->getTemplateLine()), 'macro_'.$attribute->getAttribute('value'), $arguments, $node->getTemplateLine()); diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index eb890b787..a693d947e 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -55,7 +55,6 @@ use Twig\Node\Expression\Filter\DefaultFilter; use Twig\Node\Expression\FunctionNode\EnumCasesFunction; use Twig\Node\Expression\FunctionNode\EnumFunction; use Twig\Node\Expression\GetAttrExpression; -use Twig\Node\Expression\NullCoalesceExpression; use Twig\Node\Expression\ParentExpression; use Twig\Node\Expression\Test\ConstantTest; use Twig\Node\Expression\Test\DefinedTest; @@ -533,8 +532,8 @@ final class CoreExtension extends AbstractExtension * {# do something #} * {% endif %} * - * @param \DateTimeInterface|string|int|null $date A date, a timestamp or null to use the current time - * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged + * @param \DateTimeInterface|string|int|null $date A date, a timestamp or null to use the current time + * @param \DateTimeZone|string|false|null $timezone The target timezone, null to use the default, false to leave unchanged * * @return \DateTime|\DateTimeImmutable */ @@ -785,9 +784,9 @@ final class CoreExtension extends AbstractExtension * {{ [1, 2, 3]|join }} * {# returns 123 #} * - * @param iterable|array|string|float|int|bool|null $value An array - * @param string $glue The separator - * @param string|null $and The separator for the last pair + * @param iterable|array|string|float|int|bool|null $value An array + * @param string $glue The separator + * @param string|null $and The separator for the last pair * * @internal */ diff --git a/src/Loader/FilesystemLoader.php b/src/Loader/FilesystemLoader.php index cad163ead..49f2b8915 100644 --- a/src/Loader/FilesystemLoader.php +++ b/src/Loader/FilesystemLoader.php @@ -35,7 +35,7 @@ class FilesystemLoader implements LoaderInterface /** * @param string|string[] $paths A path or an array of paths where to look for templates - * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) + * @param string|null $rootPath The root path common to all relative paths (null for getcwd()) */ public function __construct($paths = [], ?string $rootPath = null) { diff --git a/src/Node/Expression/ConditionalExpression.php b/src/Node/Expression/ConditionalExpression.php index 69d55a358..1ca90f811 100644 --- a/src/Node/Expression/ConditionalExpression.php +++ b/src/Node/Expression/ConditionalExpression.php @@ -13,7 +13,6 @@ namespace Twig\Node\Expression; use Twig\Compiler; -use Twig\Node\Expression\OperatorEscapeInterface; use Twig\Node\Expression\Ternary\ConditionalTernary; class ConditionalExpression extends AbstractExpression implements OperatorEscapeInterface diff --git a/src/Node/Expression/GetAttrExpression.php b/src/Node/Expression/GetAttrExpression.php index e7373de11..0d4b96b14 100644 --- a/src/Node/Expression/GetAttrExpression.php +++ b/src/Node/Expression/GetAttrExpression.php @@ -18,7 +18,6 @@ use Twig\Template; class GetAttrExpression extends AbstractExpression { - /** * @param ArrayExpression|NameExpression|null $arguments */ diff --git a/src/Node/Expression/OperatorEscapeInterface.php b/src/Node/Expression/OperatorEscapeInterface.php index 7b1e43e35..06db6c616 100644 --- a/src/Node/Expression/OperatorEscapeInterface.php +++ b/src/Node/Expression/OperatorEscapeInterface.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ - namespace Twig\Node\Expression; +namespace Twig\Node\Expression; /** * Interface implemented by n-ary operators for n > 1. diff --git a/src/Node/ModuleNode.php b/src/Node/ModuleNode.php index 97c2089fd..17840dd0a 100644 --- a/src/Node/ModuleNode.php +++ b/src/Node/ModuleNode.php @@ -244,9 +244,9 @@ final class ModuleNode extends Node ->string($key) ->raw(\sprintf(']; unset($_trait_%s_blocks[', $i)) ->string($key) - ->raw("]); \$this->traitAliases[") + ->raw(']); $this->traitAliases[') ->subcompile($value) - ->raw("] = ") + ->raw('] = ') ->string($key) ->raw(";\n\n") ; diff --git a/tests/LexerTest.php b/tests/LexerTest.php index d5640c8da..bfc7f9bb2 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -201,7 +201,7 @@ class LexerTest extends TestCase EOF, "\x6", ]; - yield [ + yield [ <<<'EOF' {{ '\065\x64' }} EOF, diff --git a/tests/Node/NodeTest.php b/tests/Node/NodeTest.php index a8d6b699e..13ad334bf 100644 --- a/tests/Node/NodeTest.php +++ b/tests/Node/NodeTest.php @@ -134,4 +134,4 @@ EOF class NodeForTest extends Node { -} \ No newline at end of file +}