diff --git a/Translation/Extractor/File/TwigFileExtractor.php b/Translation/Extractor/File/TwigFileExtractor.php index 7f21c8b7..d0c9af00 100644 --- a/Translation/Extractor/File/TwigFileExtractor.php +++ b/Translation/Extractor/File/TwigFileExtractor.php @@ -31,9 +31,9 @@ use Twig\Node\Expression\FilterExpression; use Twig\Node\Node; use Twig\NodeTraverser; -use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\NodeVisitor\NodeVisitorInterface; -class TwigFileExtractor extends AbstractNodeVisitor implements FileVisitorInterface +class TwigFileExtractor implements FileVisitorInterface, NodeVisitorInterface { /** * @var FileSourceFactory @@ -66,10 +66,7 @@ public function __construct(Environment $env, FileSourceFactory $fileSourceFacto $this->traverser = new NodeTraverser($env, [$this]); } - /** - * @return Node - */ - protected function doEnterNode(Node $node, Environment $env) + public function enterNode(Node $node, Environment $env): Node { $this->stack[] = $node; @@ -145,10 +142,7 @@ protected function doEnterNode(Node $node, Environment $env) return $node; } - /** - * @return int - */ - public function getPriority() + public function getPriority(): int { return 0; } @@ -178,10 +172,7 @@ private function traverseEmbeddedTemplates(Node $node) } } - /** - * @return Node - */ - protected function doLeaveNode(Node $node, Environment $env) + public function leaveNode(Node $node, Environment $env): Node { array_pop($this->stack); diff --git a/Twig/DefaultApplyingNodeVisitor.php b/Twig/DefaultApplyingNodeVisitor.php index b389d72f..881bf5c9 100644 --- a/Twig/DefaultApplyingNodeVisitor.php +++ b/Twig/DefaultApplyingNodeVisitor.php @@ -29,7 +29,7 @@ use Twig\Node\Expression\ConstantExpression; use Twig\Node\Expression\FilterExpression; use Twig\Node\Node; -use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\NodeVisitor\NodeVisitorInterface; /** * Applies the value of the "desc" filter if the "trans" filter has no @@ -39,7 +39,7 @@ * * @author Johannes M. Schmitt */ -class DefaultApplyingNodeVisitor extends AbstractNodeVisitor +class DefaultApplyingNodeVisitor implements NodeVisitorInterface { /** * @var bool @@ -51,10 +51,7 @@ public function setEnabled($bool) $this->enabled = (bool) $bool; } - /** - * @return Node - */ - public function doEnterNode(Node $node, Environment $env) + public function enterNode(Node $node, Environment $env): Node { if (!$this->enabled) { return $node; @@ -133,18 +130,12 @@ public function doEnterNode(Node $node, Environment $env) return $node; } - /** - * @return Node - */ - public function doLeaveNode(Node $node, Environment $env) + public function leaveNode(Node $node, Environment $env): Node { return $node; } - /** - * @return int - */ - public function getPriority() + public function getPriority(): int { return -2; } diff --git a/Twig/NormalizingNodeVisitor.php b/Twig/NormalizingNodeVisitor.php index f4f6fee0..3c4fecb3 100644 --- a/Twig/NormalizingNodeVisitor.php +++ b/Twig/NormalizingNodeVisitor.php @@ -24,7 +24,7 @@ use Twig\Node\Expression\Binary\ConcatBinary; use Twig\Node\Expression\ConstantExpression; use Twig\Node\Node; -use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\NodeVisitor\NodeVisitorInterface; /** * Performs equivalence transformations on the AST to ensure that @@ -34,20 +34,14 @@ * * @author Johannes M. Schmitt */ -class NormalizingNodeVisitor extends AbstractNodeVisitor +class NormalizingNodeVisitor implements NodeVisitorInterface { - /** - * @return Node - */ - protected function doEnterNode(Node $node, Environment $env) + public function enterNode(Node $node, Environment $env): Node { return $node; } - /** - * @return ConstantExpression|Node - */ - protected function doLeaveNode(Node $node, Environment $env) + public function leaveNode(Node $node, Environment $env): Node { if ( $node instanceof ConcatBinary @@ -60,10 +54,7 @@ protected function doLeaveNode(Node $node, Environment $env) return $node; } - /** - * @return int - */ - public function getPriority() + public function getPriority(): int { return -3; } diff --git a/Twig/RemovingNodeVisitor.php b/Twig/RemovingNodeVisitor.php index c5a8d4e2..e9a11c68 100644 --- a/Twig/RemovingNodeVisitor.php +++ b/Twig/RemovingNodeVisitor.php @@ -23,14 +23,14 @@ use Twig\Environment; use Twig\Node\Expression\FilterExpression; use Twig\Node\Node; -use Twig\NodeVisitor\AbstractNodeVisitor; +use Twig\NodeVisitor\NodeVisitorInterface; /** * Removes translation metadata filters from the AST. * * @author Johannes M. Schmitt */ -class RemovingNodeVisitor extends AbstractNodeVisitor +class RemovingNodeVisitor implements NodeVisitorInterface { /** * @var bool @@ -42,10 +42,7 @@ public function setEnabled($bool) $this->enabled = (bool) $bool; } - /** - * @return Node - */ - protected function doEnterNode(Node $node, Environment $env) + public function enterNode(Node $node, Environment $env): Node { if ($this->enabled && $node instanceof FilterExpression) { $name = $node->getNode('filter')->getAttribute('value'); @@ -58,18 +55,12 @@ protected function doEnterNode(Node $node, Environment $env) return $node; } - /** - * @return Node - */ - protected function doLeaveNode(Node $node, Environment $env) + public function leaveNode(Node $node, Environment $env): Node { return $node; } - /** - * @return int - */ - public function getPriority() + public function getPriority(): int { return -1; } diff --git a/composer.json b/composer.json index f65d4aee..d490ca7b 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "symfony/translation": "^4.3 || ^5.4 || ^6.0", "symfony/translation-contracts": "^1.1 || ^2.0 || ^3.0", "symfony/validator": "^4.3 || ^5.4 || ^6.0", - "twig/twig": "^1.42.4 || ^2.12.5 || ^3.0", + "twig/twig": "^2.13.1 || ^3.0", "psr/log": "^1.0 || ^2.0" }, "require-dev": {