-
Notifications
You must be signed in to change notification settings - Fork 93
refac: replace AbstractNodeVisitor with NodeVisitorInterface #520
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
Open
gimler
wants to merge
1
commit into
php-translation:master
Choose a base branch
from
gimler:feature/nodevisitorinterface
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ | |
use Twig\Node\Expression\Ternary\ConditionalTernary; | ||
use Twig\Node\Node; | ||
use Twig\Node\Nodes; | ||
use Twig\NodeVisitor\AbstractNodeVisitor; | ||
use Twig\NodeVisitor\NodeVisitorInterface; | ||
use Twig\TwigFilter; | ||
|
||
/** | ||
|
@@ -32,19 +32,16 @@ | |
* | ||
* @author Johannes M. Schmitt <[email protected]> | ||
*/ | ||
final class DefaultApplyingNodeVisitor extends AbstractNodeVisitor | ||
final class DefaultApplyingNodeVisitor implements NodeVisitorInterface | ||
{ | ||
/** | ||
* @var bool | ||
*/ | ||
private $enabled = true; | ||
private bool $enabled = true; | ||
|
||
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; | ||
|
@@ -141,7 +138,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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -25,17 +25,14 @@ | |
* | ||
* @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): ConstantExpression|Node | ||
{ | ||
if ($node instanceof ConcatBinary | ||
&& ($left = $node->getNode('left')) instanceof ConstantExpression | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,26 +14,23 @@ | |
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 | ||
*/ | ||
private $enabled = true; | ||
private bool $enabled = true; | ||
|
||
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'); | ||
|
@@ -46,7 +43,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; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍