Skip to content

Commit 90d26b3

Browse files
authored
Merge pull request #587 from grossmannmartin/mg-nodevisitor
Removed usage of deprecated AbstractNodeVisitor
2 parents 97bb596 + 4c9e012 commit 90d26b3

5 files changed

+21
-57
lines changed

Translation/Extractor/File/TwigFileExtractor.php

+5-14
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
use Twig\Node\Expression\FilterExpression;
3232
use Twig\Node\Node;
3333
use Twig\NodeTraverser;
34-
use Twig\NodeVisitor\AbstractNodeVisitor;
34+
use Twig\NodeVisitor\NodeVisitorInterface;
3535

36-
class TwigFileExtractor extends AbstractNodeVisitor implements FileVisitorInterface
36+
class TwigFileExtractor implements FileVisitorInterface, NodeVisitorInterface
3737
{
3838
/**
3939
* @var FileSourceFactory
@@ -66,10 +66,7 @@ public function __construct(Environment $env, FileSourceFactory $fileSourceFacto
6666
$this->traverser = new NodeTraverser($env, [$this]);
6767
}
6868

69-
/**
70-
* @return Node
71-
*/
72-
protected function doEnterNode(Node $node, Environment $env)
69+
public function enterNode(Node $node, Environment $env): Node
7370
{
7471
$this->stack[] = $node;
7572

@@ -145,10 +142,7 @@ protected function doEnterNode(Node $node, Environment $env)
145142
return $node;
146143
}
147144

148-
/**
149-
* @return int
150-
*/
151-
public function getPriority()
145+
public function getPriority(): int
152146
{
153147
return 0;
154148
}
@@ -178,10 +172,7 @@ private function traverseEmbeddedTemplates(Node $node)
178172
}
179173
}
180174

181-
/**
182-
* @return Node
183-
*/
184-
protected function doLeaveNode(Node $node, Environment $env)
175+
public function leaveNode(Node $node, Environment $env): Node
185176
{
186177
array_pop($this->stack);
187178

Twig/DefaultApplyingNodeVisitor.php

+5-14
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
use Twig\Node\Expression\ConstantExpression;
3030
use Twig\Node\Expression\FilterExpression;
3131
use Twig\Node\Node;
32-
use Twig\NodeVisitor\AbstractNodeVisitor;
32+
use Twig\NodeVisitor\NodeVisitorInterface;
3333

3434
/**
3535
* Applies the value of the "desc" filter if the "trans" filter has no
@@ -39,7 +39,7 @@
3939
*
4040
* @author Johannes M. Schmitt <[email protected]>
4141
*/
42-
class DefaultApplyingNodeVisitor extends AbstractNodeVisitor
42+
class DefaultApplyingNodeVisitor implements NodeVisitorInterface
4343
{
4444
/**
4545
* @var bool
@@ -51,10 +51,7 @@ public function setEnabled($bool)
5151
$this->enabled = (bool) $bool;
5252
}
5353

54-
/**
55-
* @return Node
56-
*/
57-
public function doEnterNode(Node $node, Environment $env)
54+
public function enterNode(Node $node, Environment $env): Node
5855
{
5956
if (!$this->enabled) {
6057
return $node;
@@ -133,18 +130,12 @@ public function doEnterNode(Node $node, Environment $env)
133130
return $node;
134131
}
135132

136-
/**
137-
* @return Node
138-
*/
139-
public function doLeaveNode(Node $node, Environment $env)
133+
public function leaveNode(Node $node, Environment $env): Node
140134
{
141135
return $node;
142136
}
143137

144-
/**
145-
* @return int
146-
*/
147-
public function getPriority()
138+
public function getPriority(): int
148139
{
149140
return -2;
150141
}

Twig/NormalizingNodeVisitor.php

+5-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
use Twig\Node\Expression\Binary\ConcatBinary;
2525
use Twig\Node\Expression\ConstantExpression;
2626
use Twig\Node\Node;
27-
use Twig\NodeVisitor\AbstractNodeVisitor;
27+
use Twig\NodeVisitor\NodeVisitorInterface;
2828

2929
/**
3030
* Performs equivalence transformations on the AST to ensure that
@@ -34,20 +34,14 @@
3434
*
3535
* @author Johannes M. Schmitt <[email protected]>
3636
*/
37-
class NormalizingNodeVisitor extends AbstractNodeVisitor
37+
class NormalizingNodeVisitor implements NodeVisitorInterface
3838
{
39-
/**
40-
* @return Node
41-
*/
42-
protected function doEnterNode(Node $node, Environment $env)
39+
public function enterNode(Node $node, Environment $env): Node
4340
{
4441
return $node;
4542
}
4643

47-
/**
48-
* @return ConstantExpression|Node
49-
*/
50-
protected function doLeaveNode(Node $node, Environment $env)
44+
public function leaveNode(Node $node, Environment $env): Node
5145
{
5246
if (
5347
$node instanceof ConcatBinary
@@ -60,10 +54,7 @@ protected function doLeaveNode(Node $node, Environment $env)
6054
return $node;
6155
}
6256

63-
/**
64-
* @return int
65-
*/
66-
public function getPriority()
57+
public function getPriority(): int
6758
{
6859
return -3;
6960
}

Twig/RemovingNodeVisitor.php

+5-14
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
use Twig\Environment;
2424
use Twig\Node\Expression\FilterExpression;
2525
use Twig\Node\Node;
26-
use Twig\NodeVisitor\AbstractNodeVisitor;
26+
use Twig\NodeVisitor\NodeVisitorInterface;
2727

2828
/**
2929
* Removes translation metadata filters from the AST.
3030
*
3131
* @author Johannes M. Schmitt <[email protected]>
3232
*/
33-
class RemovingNodeVisitor extends AbstractNodeVisitor
33+
class RemovingNodeVisitor implements NodeVisitorInterface
3434
{
3535
/**
3636
* @var bool
@@ -42,10 +42,7 @@ public function setEnabled($bool)
4242
$this->enabled = (bool) $bool;
4343
}
4444

45-
/**
46-
* @return Node
47-
*/
48-
protected function doEnterNode(Node $node, Environment $env)
45+
public function enterNode(Node $node, Environment $env): Node
4946
{
5047
if ($this->enabled && $node instanceof FilterExpression) {
5148
$name = $node->getNode('filter')->getAttribute('value');
@@ -58,18 +55,12 @@ protected function doEnterNode(Node $node, Environment $env)
5855
return $node;
5956
}
6057

61-
/**
62-
* @return Node
63-
*/
64-
protected function doLeaveNode(Node $node, Environment $env)
58+
public function leaveNode(Node $node, Environment $env): Node
6559
{
6660
return $node;
6761
}
6862

69-
/**
70-
* @return int
71-
*/
72-
public function getPriority()
63+
public function getPriority(): int
7364
{
7465
return -1;
7566
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"symfony/translation": "^4.3 || ^5.4 || ^6.0",
3131
"symfony/translation-contracts": "^1.1 || ^2.0 || ^3.0",
3232
"symfony/validator": "^4.3 || ^5.4 || ^6.0",
33-
"twig/twig": "^1.42.4 || ^2.12.5 || ^3.0",
33+
"twig/twig": "^2.13.1 || ^3.0",
3434
"psr/log": "^1.0 || ^2.0"
3535
},
3636
"require-dev": {

0 commit comments

Comments
 (0)