Skip to content

Commit

Permalink
Support twig 4.x and PHPUnit 11
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Jan 10, 2025
1 parent 2006c55 commit 1d18f03
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 24 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"require": {
"php": "^8.2",
"twig/twig": "^3.17"
"twig/twig": "4.x-dev"
},
"require-dev": {
"phpmyadmin/coding-standard": "^4.0",
Expand All @@ -30,7 +30,7 @@
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10"
"phpunit/phpunit": "^11"
},
"scripts": {
"phpstan": "./vendor/bin/phpstan analyse",
Expand Down
11 changes: 3 additions & 8 deletions src/I18nExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,22 @@ class I18nExtension extends AbstractExtension
/**
* {@inheritdoc}
*/
public function getTokenParsers()
public function getTokenParsers(): array
{
return [new TransTokenParser()];
}

/**
* {@inheritdoc}
*/
public function getFilters()
public function getFilters(): array
{
return [
new TwigFilter('trans', [$this, 'translate']), /* Note, the filter does not handle plurals */
];
}

/**
* {@inheritdoc}
*
* @return string
*/
public function getName()
public function getName(): string
{
return 'i18n';
}
Expand Down
5 changes: 1 addition & 4 deletions src/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ public function __construct(
parent::__construct($nodes, [], $lineno);
}

/**
* {@inheritdoc}
*/
public function compile(Compiler $compiler)
public function compile(Compiler $compiler): void
{
if (self::$enableAddDebugInfo) {
$compiler->addDebugInfo($this);
Expand Down
10 changes: 2 additions & 8 deletions src/TokenParser/TransTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@

class TransTokenParser extends AbstractTokenParser
{
/**
* {@inheritdoc}
*/
public function parse(Token $token)
public function parse(Token $token): Node
{
[
$body,
Expand Down Expand Up @@ -118,10 +115,7 @@ public function decideForEnd(Token $token): bool
return $token->test('endtrans');
}

/**
* {@inheritdoc}
*/
public function getTag()
public function getTag(): string
{
return 'trans';
}
Expand Down
5 changes: 3 additions & 2 deletions test/Node/TransTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
use PhpMyAdmin\Twig\Extensions\Node\TransNode;
use Twig\Environment;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FilterExpression;
use Twig\Node\Expression\Filter\RawFilter;
use Twig\Node\Expression\Variable\ContextVariable;
use Twig\Node\Node;
use Twig\Node\Nodes;
use Twig\Node\PrintNode;
use Twig\Node\TextNode;
use Twig\Test\NodeTestCase;
use Twig\TwigFilter;

use function sprintf;

Expand Down Expand Up @@ -203,7 +204,7 @@ public static function provideTests(): iterable
$body = new Nodes([
new TextNode('J\'ai ', 0),
new PrintNode(
new FilterExpression($contextFoo, new ConstantExpression('escape', 0), new Nodes(), 0),
new RawFilter($contextFoo, new TwigFilter('escape'), new Nodes(), 0),
0,
),
new TextNode(' pommes', 0),
Expand Down

0 comments on commit 1d18f03

Please sign in to comment.