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

Removed usage of deprecated AbstractNodeVisitor #587

Merged
merged 1 commit into from
Jun 8, 2024
Merged
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
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 <[email protected]>
*/
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 <[email protected]>
*/
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 <[email protected]>
*/
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
Loading