Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Twig 4.x and PHPUnit 11 #21

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading