From b71c2b5fee03914fee07499efd4c2d0c706b0903 Mon Sep 17 00:00:00 2001 From: Andreas Leathley Date: Thu, 30 Jan 2025 10:47:03 +0100 Subject: [PATCH] Add ForElseNode to avoid deprecation notice in Twig 3.19+ --- composer.json | 2 +- src/TokenParser/ForeachTokenParser.php | 3 ++- tools/phpstan-baseline.php | 6 ------ tools/psalm-baseline.xml | 10 +--------- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index f3b01f7..08f0839 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ ], "require": { "php": ">=8.0.2", - "twig/twig": "^3.15" + "twig/twig": "^3.19" }, "require-dev": { "captainhook/captainhook-phar": "^5.0", diff --git a/src/TokenParser/ForeachTokenParser.php b/src/TokenParser/ForeachTokenParser.php index f9afe30..83716dd 100644 --- a/src/TokenParser/ForeachTokenParser.php +++ b/src/TokenParser/ForeachTokenParser.php @@ -4,6 +4,7 @@ use Twig\Lexer; use Twig\Node\Expression\Variable\AssignContextVariable; +use Twig\Node\ForElseNode; use Twig\Node\ForNode; use Twig\Node\Node; use Twig\Node\Nodes; @@ -27,7 +28,7 @@ public function parse(Token $token): Node $body = $this->parser->subparse([$this, 'decideForeachFork']); if ($stream->next()->getValue() === 'else') { $stream->expect(Token::BLOCK_END_TYPE); - $else = $this->parser->subparse([$this, 'decideForeachEnd'], true); + $else = new ForElseNode($this->parser->subparse([$this, 'decideForeachEnd'], true), $stream->getCurrent()->getLine()); } else { $else = null; } diff --git a/tools/phpstan-baseline.php b/tools/phpstan-baseline.php index 377dad6..84482da 100644 --- a/tools/phpstan-baseline.php +++ b/tools/phpstan-baseline.php @@ -1,12 +1,6 @@ '#^Method Squirrel\\\\TwigPhpSyntax\\\\PhpSyntaxExtension\\:\\:getOperators\\(\\) has invalid return type Twig\\\\Extension\\\\OperatorPrecedenceChange\\.$#', - 'identifier' => 'class.notFound', - 'count' => 2, - 'path' => __DIR__ . '/../src/PhpSyntaxExtension.php', -]; $ignoreErrors[] = [ 'message' => '#^Method Squirrel\\\\TwigPhpSyntax\\\\PhpSyntaxExtension\\:\\:validateType\\(\\) should return bool\\|float\\|int\\|string\\|null but returns mixed\\.$#', 'identifier' => 'return.type', diff --git a/tools/psalm-baseline.xml b/tools/psalm-baseline.xml index 5d0051f..5c064bb 100644 --- a/tools/psalm-baseline.xml +++ b/tools/psalm-baseline.xml @@ -1,10 +1,2 @@ - - - - - - - - - +