Skip to content

Commit

Permalink
Merge pull request #587 from grossmannmartin/mg-nodevisitor
Browse files Browse the repository at this point in the history
Removed usage of deprecated AbstractNodeVisitor
  • Loading branch information
goetas authored Jun 8, 2024
2 parents 97bb596 + 4c9e012 commit 90d26b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 57 deletions.
19 changes: 5 additions & 14 deletions Translation/Extractor/File/TwigFileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -145,10 +142,7 @@ protected function doEnterNode(Node $node, Environment $env)
return $node;
}

/**
* @return int
*/
public function getPriority()
public function getPriority(): int
{
return 0;
}
Expand Down Expand Up @@ -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);

Expand Down
19 changes: 5 additions & 14 deletions Twig/DefaultApplyingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +39,7 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
class DefaultApplyingNodeVisitor extends AbstractNodeVisitor
class DefaultApplyingNodeVisitor implements NodeVisitorInterface
{
/**
* @var bool
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
19 changes: 5 additions & 14 deletions Twig/NormalizingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,20 +34,14 @@
*
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
*/
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
Expand All @@ -60,10 +54,7 @@ protected function doLeaveNode(Node $node, Environment $env)
return $node;
}

/**
* @return int
*/
public function getPriority()
public function getPriority(): int
{
return -3;
}
Expand Down
19 changes: 5 additions & 14 deletions Twig/RemovingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <schmittjoh@gmail.com>
*/
class RemovingNodeVisitor extends AbstractNodeVisitor
class RemovingNodeVisitor implements NodeVisitorInterface
{
/**
* @var bool
Expand All @@ -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');
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 90d26b3

Please sign in to comment.