Skip to content

Commit

Permalink
refac: replace AbstractNodeVisitor with NodeVisitorInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
gimler committed Oct 23, 2024
1 parent 9b7e961 commit 1fddbb6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Twig/Visitor/DefaultApplyingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,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 @@ -29,7 +29,7 @@
*
* @author Johannes M. Schmitt <[email protected]>
*/
final class DefaultApplyingNodeVisitor extends AbstractNodeVisitor
final class DefaultApplyingNodeVisitor implements NodeVisitorInterface
{
/**
* @var bool
Expand All @@ -41,7 +41,7 @@ public function setEnabled(bool $bool): void
$this->enabled = $bool;
}

public function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
if (!$this->enabled) {
return $node;
Expand Down Expand Up @@ -114,7 +114,7 @@ public function doEnterNode(Node $node, Environment $env): Node
return $node;
}

public function doLeaveNode(Node $node, Environment $env): Node
public function leaveNode(Node $node, Environment $env): Node
{
return $node;
}
Expand Down
8 changes: 4 additions & 4 deletions Twig/Visitor/NormalizingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,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 @@ -25,17 +25,17 @@
*
* @author Johannes M. Schmitt <[email protected]>
*/
final class NormalizingNodeVisitor extends AbstractNodeVisitor
final class NormalizingNodeVisitor implements NodeVisitorInterface
{
protected function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
return $node;
}

/**
* @return ConstantExpression|Node
*/
protected function doLeaveNode(Node $node, Environment $env): Node
public function leaveNode(Node $node, Environment $env): Node
{
if ($node instanceof ConcatBinary
&& ($left = $node->getNode('left')) instanceof ConstantExpression
Expand Down
8 changes: 4 additions & 4 deletions Twig/Visitor/RemovingNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,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 <[email protected]>
*/
final class RemovingNodeVisitor extends AbstractNodeVisitor
final class RemovingNodeVisitor implements NodeVisitorInterface
{
/**
* @var bool
Expand All @@ -33,7 +33,7 @@ public function setEnabled(bool $bool): void
$this->enabled = $bool;
}

protected function doEnterNode(Node $node, Environment $env): Node
public function enterNode(Node $node, Environment $env): Node
{
if ($this->enabled && $node instanceof FilterExpression) {
$name = $node->getNode('filter')->getAttribute('value');
Expand All @@ -46,7 +46,7 @@ protected function doEnterNode(Node $node, Environment $env): Node
return $node;
}

protected function doLeaveNode(Node $node, Environment $env): Node
public function leaveNode(Node $node, Environment $env): Node
{
return $node;
}
Expand Down

0 comments on commit 1fddbb6

Please sign in to comment.