From cb9fd670be54bf4e9eee965423003a9b602903bd Mon Sep 17 00:00:00 2001 From: William Desportes Date: Tue, 7 Jan 2025 14:19:14 +0100 Subject: [PATCH 1/4] Fix #16 - Direct use of Node is deprecated --- src/Node/I18nNode.php | 34 ++++++++++ src/Node/TransNode.php | 2 +- src/TokenParser/TransTokenParser.php | 5 +- test/Node/MoTranslatorTransTest.php | 94 ++++++++++++++-------------- test/Node/TransTest.php | 60 +++++++++--------- 5 files changed, 115 insertions(+), 80 deletions(-) create mode 100644 src/Node/I18nNode.php diff --git a/src/Node/I18nNode.php b/src/Node/I18nNode.php new file mode 100644 index 0000000..fbde515 --- /dev/null +++ b/src/Node/I18nNode.php @@ -0,0 +1,34 @@ + $attributes An array of attributes (should not be nodes) + * @param int $lineno The line number + */ + public function __construct(Node|null $node, array $attributes, int $lineno) + { + parent::__construct($node === null ? [] : [$node], $attributes, $lineno); + } +} diff --git a/src/Node/TransNode.php b/src/Node/TransNode.php index d016afc..5ba9735 100644 --- a/src/Node/TransNode.php +++ b/src/Node/TransNode.php @@ -253,7 +253,7 @@ protected function compileString(Node $body): array $msg = $body->getAttribute('data'); } - return [new Node([new ConstantExpression(trim($msg), $body->getTemplateLine())]), $vars]; + return [new I18nNode(new ConstantExpression(trim($msg), $body->getTemplateLine()), [], 0), $vars]; } /** diff --git a/src/TokenParser/TransTokenParser.php b/src/TokenParser/TransTokenParser.php index 44fd954..1e1c830 100644 --- a/src/TokenParser/TransTokenParser.php +++ b/src/TokenParser/TransTokenParser.php @@ -14,6 +14,7 @@ namespace PhpMyAdmin\Twig\Extensions\TokenParser; +use PhpMyAdmin\Twig\Extensions\Node\I18nNode; use PhpMyAdmin\Twig\Extensions\Node\TransNode; use Twig\Error\SyntaxError; use Twig\Node\Expression\AbstractExpression; @@ -96,12 +97,12 @@ protected function preParse(Token $token): array if ($notes instanceof TextNode) { // Don't use TextNode for $notes to avoid it getting merged with $body when optimizing. - $notes = new Node([], ['data' => $notes->getAttribute('data')], $notes->getTemplateLine()); + $notes = new I18nNode(null, ['data' => $notes->getAttribute('data')], $notes->getTemplateLine()); } if ($context instanceof TextNode) { // Don't use TextNode for $context to avoid it getting merged with $body when optimizing. - $context = new Node([], ['data' => $context->getAttribute('data')], $context->getTemplateLine()); + $context = new I18nNode(null, ['data' => $context->getAttribute('data')], $context->getTemplateLine()); } return [$body, $plural, $count, $context, $notes, $domain, $lineno, $this->getTag()]; diff --git a/test/Node/MoTranslatorTransTest.php b/test/Node/MoTranslatorTransTest.php index d7e6092..56a6c85 100644 --- a/test/Node/MoTranslatorTransTest.php +++ b/test/Node/MoTranslatorTransTest.php @@ -17,7 +17,7 @@ use PhpMyAdmin\Twig\Extensions\Node\TransNode; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\NameExpression; -use Twig\Node\Node; +use Twig\Node\Nodes; use Twig\Node\PrintNode; use Twig\Node\TextNode; use Twig\Test\NodeTestCase; @@ -41,25 +41,25 @@ public static function tearDownAfterClass(): void public function testFullConstructor(): void { $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hello', 0), - ], [], 0); - $notes = new Node([ + ]); + $notes = new Nodes([ new TextNode('notes for translators', 0), - ], [], 0); - $domain = new Node([ + ]); + $domain = new Nodes([ new TextNode('mydomain', 0), - ], [], 0); - $context = new Node([ + ]); + $context = new Nodes([ new TextNode('mydomain', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, $context, $notes, $domain, 0); $this->assertEquals($body, $node->getNode('body')); @@ -76,9 +76,9 @@ public function getTests(): array $tests = []; $body = new NameExpression('foo', 0); - $domain = new Node([ + $domain = new Nodes([ new TextNode('coredomain', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, null, null, $domain, 0); $tests[] = [ $node, @@ -86,12 +86,12 @@ public function getTests(): array ]; $body = new NameExpression('foo', 0); - $domain = new Node([ + $domain = new Nodes([ new TextNode('coredomain', 0), - ], [], 0); - $context = new Node([ + ]); + $context = new Nodes([ new TextNode('The context', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, $context, null, $domain, 0); $tests[] = [ $node, @@ -101,11 +101,11 @@ public function getTests(): array ), ]; - $body = new Node([ + $body = new Nodes([ new TextNode('J\'ai ', 0), new PrintNode(new NameExpression('foo', 0), 0), new TextNode(' pommes', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, null, null, null, 0); $tests[] = [ $node, @@ -116,18 +116,18 @@ public function getTests(): array ]; $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have one apple', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, null, null, null, 0); $tests[] = [ $node, @@ -140,14 +140,14 @@ public function getTests(): array ), ]; - $body = new Node([ + $body = new Nodes([ new TextNode('J\'ai ', 0), new PrintNode(new NameExpression('foo', 0), 0), new TextNode(' pommes', 0), - ], [], 0); - $context = new Node([ + ]); + $context = new Nodes([ new TextNode('The context', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, $context, null, null, 0); $tests[] = [ $node, @@ -158,21 +158,21 @@ public function getTests(): array ]; $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have one apple', 0), - ], [], 0); - $context = new Node([ + ]); + $context = new Nodes([ new TextNode('The context', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, $context, null, null, 0); $tests[] = [ $node, @@ -185,17 +185,17 @@ public function getTests(): array ), ]; - $body = new Node([ + $body = new Nodes([ new TextNode('J\'ai ', 0), new PrintNode(new NameExpression('foo', 0), 0), new TextNode(' pommes', 0), - ], [], 0); - $context = new Node([ + ]); + $context = new Nodes([ new TextNode('The context', 0), - ], [], 0); - $domain = new Node([ + ]); + $domain = new Nodes([ new TextNode('mydomain', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, $context, null, $domain, 0); $tests[] = [ $node, @@ -206,24 +206,24 @@ public function getTests(): array ]; $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have one apple', 0), - ], [], 0); - $context = new Node([ + ]); + $context = new Nodes([ new TextNode('The context', 0), - ], [], 0); - $domain = new Node([ + ]); + $domain = new Nodes([ new TextNode('mydomain', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, $context, null, $domain, 0); $tests[] = [ $node, diff --git a/test/Node/TransTest.php b/test/Node/TransTest.php index b051a9d..b02d96c 100644 --- a/test/Node/TransTest.php +++ b/test/Node/TransTest.php @@ -18,7 +18,7 @@ use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; use Twig\Node\Expression\NameExpression; -use Twig\Node\Node; +use Twig\Node\Nodes; use Twig\Node\PrintNode; use Twig\Node\TextNode; use Twig\Test\NodeTestCase; @@ -30,16 +30,16 @@ class TransTest extends NodeTestCase public function testConstructor(): void { $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hello', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, null, null, null, 0); $this->assertEquals($body, $node->getNode('body')); @@ -50,19 +50,19 @@ public function testConstructor(): void public function testConstructorWithDomain(): void { $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hello', 0), - ], [], 0); - $domain = new Node([ + ]); + $domain = new Nodes([ new TextNode('coredomain', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, null, null, $domain, 0); $this->assertEquals($body, $node->getNode('body')); @@ -75,11 +75,11 @@ public function testEnableDebugNotEnabled(): void { $count = new ConstantExpression(5, 0); $body = new TextNode('There is 1 pending task', 0); - $plural = new Node([ + $plural = new Nodes([ new TextNode('There are ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' pending tasks', 0), - ], [], 0); + ]); $notes = new TextNode('Notes for translators', 0); TransNode::$enableAddDebugInfo = false; TransNode::$notesLabel = '// custom: '; @@ -103,11 +103,11 @@ public function testEnableDebugEnabled(): void { $count = new ConstantExpression(5, 0); $body = new TextNode('There is 1 pending task', 0); - $plural = new Node([ + $plural = new Nodes([ new TextNode('There are ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' pending tasks', 0), - ], [], 0); + ]); $notes = new TextNode('Notes for translators', 0); TransNode::$enableAddDebugInfo = true; @@ -134,9 +134,9 @@ public function getTests(): array $tests = []; $body = new NameExpression('foo', 0); - $domain = new Node([ + $domain = new Nodes([ new TextNode('coredomain', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, null, null, $domain, 0); $tests[] = [ $node, @@ -151,17 +151,17 @@ public function getTests(): array $node = new TransNode($body, null, null, null, null, null, 0); $tests[] = [$node, 'yield gettext("Hello");']; - $body = new Node([ + $body = new Nodes([ new TextNode('Hello', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, null, null, null, 0); $tests[] = [$node, 'yield gettext("Hello");']; - $body = new Node([ + $body = new Nodes([ new TextNode('J\'ai ', 0), new PrintNode(new NameExpression('foo', 0), 0), new TextNode(' pommes', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, null, null, null, 0); $tests[] = [ $node, @@ -172,18 +172,18 @@ public function getTests(): array ]; $count = new ConstantExpression(12, 0); - $body = new Node([ + $body = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have one apple', 0), - ], [], 0); - $plural = new Node([ + ]); + $plural = new Nodes([ new TextNode('Hey ', 0), new PrintNode(new NameExpression('name', 0), 0), new TextNode(', I have ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' apples', 0), - ], [], 0); + ]); $node = new TransNode($body, $plural, $count, null, null, null, 0); $tests[] = [ $node, @@ -197,14 +197,14 @@ public function getTests(): array ]; // with escaper extension set to on - $body = new Node([ + $body = new Nodes([ new TextNode('J\'ai ', 0), new PrintNode( - new FilterExpression(new NameExpression('foo', 0), new ConstantExpression('escape', 0), new Node(), 0), + new FilterExpression(new NameExpression('foo', 0), new ConstantExpression('escape', 0), new Nodes(), 0), 0, ), new TextNode(' pommes', 0), - ], [], 0); + ]); $node = new TransNode($body, null, null, null, null, null, 0); $tests[] = [ @@ -232,11 +232,11 @@ public function getTests(): array $count = new ConstantExpression(5, 0); $body = new TextNode('There is 1 pending task', 0); - $plural = new Node([ + $plural = new Nodes([ new TextNode('There are ', 0), new PrintNode(new NameExpression('count', 0), 0), new TextNode(' pending tasks', 0), - ], [], 0); + ]); $notes = new TextNode('Notes for translators', 0); $node = new TransNode($body, $plural, $count, null, $notes, null, 0); $tests[] = [ From ddbf44a0b757beb8c9af83b85ee012ed1bec1c43 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Tue, 7 Jan 2025 14:23:04 +0100 Subject: [PATCH 2/4] Drop support for Twig < 3.17.0 Last release to have new deprecation warnings --- CHANGELOG.md | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e18d29c..a93f95d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## [Unreleased] -* Drop support for Twig < 3.13.0 +* Drop support for Twig < 3.17.0 * Drop support for PHP 7.2, PHP 7.3, PHP 7.4 and PHP 8.0 ## [4.1.3] - 2024-09-08 diff --git a/composer.json b/composer.json index 34b1d02..066d6da 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ }, "require": { "php": "^8.1", - "twig/twig": "^3.13" + "twig/twig": "^3.17" }, "require-dev": { "phpmyadmin/coding-standard": "^4.0", From cd2a03a6828985ee6d0504fdeec5d66a840aebe9 Mon Sep 17 00:00:00 2001 From: William Desportes Date: Tue, 7 Jan 2025 14:35:47 +0100 Subject: [PATCH 3/4] Fix #17 - Replace `Twig\Node\Expression\NameExpression` and `Twig\Node\Expression\TempNameExpression` are deprecated --- phpstan-baseline.neon | 4 ++-- src/Node/TransNode.php | 14 ++++-------- src/TokenParser/TransTokenParser.php | 4 ++-- test/Node/MoTranslatorTransTest.php | 34 ++++++++++++++-------------- test/Node/TransTest.php | 30 ++++++++++++------------ 5 files changed, 41 insertions(+), 45 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 11b0abd..9ee03fd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,7 +1,7 @@ parameters: ignoreErrors: - - message: "#^Only booleans are allowed in an if condition, array\\ given\\.$#" + message: "#^Only booleans are allowed in an if condition, array\\ given\\.$#" count: 1 path: src/Node/TransNode.php @@ -11,7 +11,7 @@ parameters: path: src/Node/TransNode.php - - message: "#^Parameter \\#1 \\$name of class Twig\\\\Node\\\\Expression\\\\NameExpression constructor expects string, mixed given\\.$#" + message: "#^Parameter \\#1 \\$name of class Twig\\\\Node\\\\Expression\\\\Variable\\\\ContextVariable constructor expects string, mixed given\\.$#" count: 1 path: src/Node/TransNode.php diff --git a/src/Node/TransNode.php b/src/Node/TransNode.php index 5ba9735..3e10f39 100644 --- a/src/Node/TransNode.php +++ b/src/Node/TransNode.php @@ -20,8 +20,8 @@ use Twig\Node\Expression\AbstractExpression; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; -use Twig\Node\Expression\NameExpression; -use Twig\Node\Expression\TempNameExpression; +use Twig\Node\Expression\Variable\ContextVariable; +use Twig\Node\Expression\Variable\LocalVariable; use Twig\Node\Node; use Twig\Node\PrintNode; use Twig\Node\TextNode; @@ -214,15 +214,11 @@ public function compile(Compiler $compiler) /** * Keep this method protected instead of private some implementations may use it * - * @psalm-return array{Node, list} + * @psalm-return array{Node, list} */ protected function compileString(Node $body): array { - if ( - $body instanceof NameExpression - || $body instanceof ConstantExpression - || $body instanceof TempNameExpression - ) { + if ($body instanceof ContextVariable || $body instanceof ConstantExpression || $body instanceof LocalVariable) { return [$body, []]; } @@ -243,7 +239,7 @@ protected function compileString(Node $body): array $attributeName = $n->getAttribute('name'); $msg .= sprintf('%%%s%%', $attributeName); - $vars[] = new NameExpression($attributeName, $n->getTemplateLine()); + $vars[] = new ContextVariable($attributeName, $n->getTemplateLine()); } else { /** @phpstan-var TextNode $node */ $msg .= $node->getAttribute('data'); diff --git a/src/TokenParser/TransTokenParser.php b/src/TokenParser/TransTokenParser.php index 1e1c830..cf8253d 100644 --- a/src/TokenParser/TransTokenParser.php +++ b/src/TokenParser/TransTokenParser.php @@ -18,7 +18,7 @@ use PhpMyAdmin\Twig\Extensions\Node\TransNode; use Twig\Error\SyntaxError; use Twig\Node\Expression\AbstractExpression; -use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\Variable\ContextVariable; use Twig\Node\Node; use Twig\Node\PrintNode; use Twig\Node\TextNode; @@ -133,7 +133,7 @@ protected function checkTransString(Node $body, int $lineno): void if ( $node instanceof TextNode || - ($node instanceof PrintNode && $node->getNode('expr') instanceof NameExpression) + ($node instanceof PrintNode && $node->getNode('expr') instanceof ContextVariable) ) { continue; } diff --git a/test/Node/MoTranslatorTransTest.php b/test/Node/MoTranslatorTransTest.php index 56a6c85..ff8d39f 100644 --- a/test/Node/MoTranslatorTransTest.php +++ b/test/Node/MoTranslatorTransTest.php @@ -16,7 +16,7 @@ use PhpMyAdmin\Twig\Extensions\Node\TransNode; use Twig\Node\Expression\ConstantExpression; -use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\Variable\ContextVariable; use Twig\Node\Nodes; use Twig\Node\PrintNode; use Twig\Node\TextNode; @@ -55,9 +55,9 @@ public function testFullConstructor(): void ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, $context, $notes, $domain, 0); @@ -75,7 +75,7 @@ public function getTests(): array { $tests = []; - $body = new NameExpression('foo', 0); + $body = new ContextVariable('foo', 0); $domain = new Nodes([ new TextNode('coredomain', 0), ]); @@ -85,7 +85,7 @@ public function getTests(): array sprintf('yield _dgettext("coredomain", %s);', $this->getVariableGetter('foo')), ]; - $body = new NameExpression('foo', 0); + $body = new ContextVariable('foo', 0); $domain = new Nodes([ new TextNode('coredomain', 0), ]); @@ -103,7 +103,7 @@ public function getTests(): array $body = new Nodes([ new TextNode('J\'ai ', 0), - new PrintNode(new NameExpression('foo', 0), 0), + new PrintNode(new ContextVariable('foo', 0), 0), new TextNode(' pommes', 0), ]); $node = new TransNode($body, null, null, null, null, null, 0); @@ -118,14 +118,14 @@ public function getTests(): array $count = new ConstantExpression(12, 0); $body = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have one apple', 0), ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, null, null, null, 0); @@ -142,7 +142,7 @@ public function getTests(): array $body = new Nodes([ new TextNode('J\'ai ', 0), - new PrintNode(new NameExpression('foo', 0), 0), + new PrintNode(new ContextVariable('foo', 0), 0), new TextNode(' pommes', 0), ]); $context = new Nodes([ @@ -160,7 +160,7 @@ public function getTests(): array $count = new ConstantExpression(12, 0); $body = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have one apple', 0), ]); $context = new Nodes([ @@ -168,9 +168,9 @@ public function getTests(): array ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, $context, null, null, 0); @@ -187,7 +187,7 @@ public function getTests(): array $body = new Nodes([ new TextNode('J\'ai ', 0), - new PrintNode(new NameExpression('foo', 0), 0), + new PrintNode(new ContextVariable('foo', 0), 0), new TextNode(' pommes', 0), ]); $context = new Nodes([ @@ -208,7 +208,7 @@ public function getTests(): array $count = new ConstantExpression(12, 0); $body = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have one apple', 0), ]); $context = new Nodes([ @@ -219,9 +219,9 @@ public function getTests(): array ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, $context, null, $domain, 0); diff --git a/test/Node/TransTest.php b/test/Node/TransTest.php index b02d96c..5f92830 100644 --- a/test/Node/TransTest.php +++ b/test/Node/TransTest.php @@ -17,7 +17,7 @@ use PhpMyAdmin\Twig\Extensions\Node\TransNode; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; -use Twig\Node\Expression\NameExpression; +use Twig\Node\Expression\Variable\ContextVariable; use Twig\Node\Nodes; use Twig\Node\PrintNode; use Twig\Node\TextNode; @@ -35,9 +35,9 @@ public function testConstructor(): void ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, null, null, null, 0); @@ -58,9 +58,9 @@ public function testConstructorWithDomain(): void ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, null, null, $domain, 0); @@ -77,7 +77,7 @@ public function testEnableDebugNotEnabled(): void $body = new TextNode('There is 1 pending task', 0); $plural = new Nodes([ new TextNode('There are ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' pending tasks', 0), ]); $notes = new TextNode('Notes for translators', 0); @@ -105,7 +105,7 @@ public function testEnableDebugEnabled(): void $body = new TextNode('There is 1 pending task', 0); $plural = new Nodes([ new TextNode('There are ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' pending tasks', 0), ]); $notes = new TextNode('Notes for translators', 0); @@ -133,7 +133,7 @@ public function getTests(): array { $tests = []; - $body = new NameExpression('foo', 0); + $body = new ContextVariable('foo', 0); $domain = new Nodes([ new TextNode('coredomain', 0), ]); @@ -143,7 +143,7 @@ public function getTests(): array sprintf('yield dgettext("coredomain", %s);', $this->getVariableGetter('foo')), ]; - $body = new NameExpression('foo', 0); + $body = new ContextVariable('foo', 0); $node = new TransNode($body, null, null, null, null, null, 0); $tests[] = [$node, sprintf('yield gettext(%s);', $this->getVariableGetter('foo'))]; @@ -159,7 +159,7 @@ public function getTests(): array $body = new Nodes([ new TextNode('J\'ai ', 0), - new PrintNode(new NameExpression('foo', 0), 0), + new PrintNode(new ContextVariable('foo', 0), 0), new TextNode(' pommes', 0), ]); $node = new TransNode($body, null, null, null, null, null, 0); @@ -174,14 +174,14 @@ public function getTests(): array $count = new ConstantExpression(12, 0); $body = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have one apple', 0), ]); $plural = new Nodes([ new TextNode('Hey ', 0), - new PrintNode(new NameExpression('name', 0), 0), + new PrintNode(new ContextVariable('name', 0), 0), new TextNode(', I have ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' apples', 0), ]); $node = new TransNode($body, $plural, $count, null, null, null, 0); @@ -200,7 +200,7 @@ public function getTests(): array $body = new Nodes([ new TextNode('J\'ai ', 0), new PrintNode( - new FilterExpression(new NameExpression('foo', 0), new ConstantExpression('escape', 0), new Nodes(), 0), + new FilterExpression(new ContextVariable('foo', 0), new ConstantExpression('escape', 0), new Nodes(), 0), 0, ), new TextNode(' pommes', 0), @@ -234,7 +234,7 @@ public function getTests(): array $body = new TextNode('There is 1 pending task', 0); $plural = new Nodes([ new TextNode('There are ', 0), - new PrintNode(new NameExpression('count', 0), 0), + new PrintNode(new ContextVariable('count', 0), 0), new TextNode(' pending tasks', 0), ]); $notes = new TextNode('Notes for translators', 0); From 23db94dcfa0401f067edc40f8290d63e9c503d6a Mon Sep 17 00:00:00 2001 From: William Desportes Date: Tue, 7 Jan 2025 15:21:04 +0100 Subject: [PATCH 4/4] Drop PHP 8.1 because motranslator requires PHP 8.2 --- .github/workflows/lint-and-analyse-php.yml | 8 ++++---- .github/workflows/tests.yml | 4 ++-- CHANGELOG.md | 2 +- composer.json | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint-and-analyse-php.yml b/.github/workflows/lint-and-analyse-php.yml index 1c70a82..ed3c174 100644 --- a/.github/workflows/lint-and-analyse-php.yml +++ b/.github/workflows/lint-and-analyse-php.yml @@ -11,10 +11,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up PHP 8.1 + - name: Set up PHP 8.2 uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 - name: Validate composer.json and composer.lock run: composer validate --strict @@ -33,10 +33,10 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Set up PHP 8.1 + - name: Set up PHP 8.2 uses: shivammathur/setup-php@v2 with: - php-version: 8.1 + php-version: 8.2 - name: Install Composer dependencies uses: ramsey/composer-install@v2 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 93be337..a8e57e7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,12 +11,12 @@ jobs: continue-on-error: ${{ matrix.experimental }} strategy: matrix: - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.2', '8.3', '8.4'] experimental: [false] composer-options: [''] os: [ubuntu-latest] include: - - { php-version: '8.4', composer-options: '--ignore-platform-req=php+', experimental: true, os: ubuntu-latest } + - { php-version: '8.5', composer-options: '--ignore-platform-req=php+', experimental: true, os: ubuntu-latest } steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index a93f95d..b6ff4ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## [Unreleased] * Drop support for Twig < 3.17.0 -* Drop support for PHP 7.2, PHP 7.3, PHP 7.4 and PHP 8.0 +* Drop support for PHP 7.2, PHP 7.3, PHP 7.4, PHP 8.0 and PHP 8.1 ## [4.1.3] - 2024-09-08 diff --git a/composer.json b/composer.json index 066d6da..541bd19 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "source": "https://github.com/phpmyadmin/twig-i18n-extension" }, "require": { - "php": "^8.1", + "php": "^8.2", "twig/twig": "^3.17" }, "require-dev": {