8000 minor #59891 [TwigBridge] [WIP] remove no longer needed BC layers (xa… · symfony/symfony@d34aebf · GitHub
[go: up one dir, main page]

Skip to content

Commit d34aebf

Browse files
committed
minor #59891 [TwigBridge] [WIP] remove no longer needed BC layers (xabbuh)
This PR was merged into the 7.3 branch. Discussion ---------- [TwigBridge] [WIP] remove no longer needed BC layers | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT Commits ------- 58e9a80 remove no longer needed BC layers
2 parents 8e47989 + 58e9a80 commit d34aebf

File tree

4 files changed

+68
-173
lines changed

4 files changed

+68
-173
lines changed

src/Symfony/Bridge/Twig/NodeVisitor/TranslationDefaultDomainNodeVisitor.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
use Twig\Node\BlockNode;
1818
use Twig\Node\EmptyNode;
1919
use Twig\Node\Expression\ArrayExpression;
20-
use Twig\Node\Expression\AssignNameExpression;
2120
use Twig\Node\Expression\ConstantExpression;
2221
use Twig\Node\Expression\FilterExpression;
23-
use Twig\Node\Expression\NameExpression;
2422
use Twig\Node\Expression\Variable\AssignContextVariable;
2523
use Twig\Node\Expression\Variable\ContextVariable;
2624
use Twig\Node\ModuleNode;
@@ -60,17 +58,10 @@ public function enterNode(Node $node, Environment $env): Node
6058

6159
$var = '__internal_trans_default_domain'.hash('xxh128', $templateName);
6260

63-
if (class_exists(Nodes::class)) {
64-
$name = new AssignContextVariable($var, $node->getTemplateLine());
65-
$this->scope->set('domain', new ContextVariable($var, $node->getTemplateLine()));
61+
$name = new AssignContextVariable($var, $node->getTemplateLine());
62+
$this->scope->set('domain', new ContextVariable($var, $node->getTemplateLine()));
6663

67-
return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
68-
}
69-
70-
$name = new AssignNameExpression($var, $node->getTemplateLine());
71-
$this->scope->set('domain', new NameExpression($var, $node->getTemplateLine()));
72-
73-
return new SetNode(false, new Node([$name]), new Node([$node->getNode('expr')]), $node->getTemplateLine());
64+
return new SetNode(false, new Nodes([$name]), new Nodes([$node->getNode('expr')]), $node->getTemplateLine());
7465
}
7566

7667
if (!$this->scope->has('domain')) {

src/Symfony/Bridge/Twig/Tests/Node/SearchAndRenderBlockNodeTest.php

Lines changed: 54 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,18 @@
2020
use Twig\Node\Expression\ArrayExpression;
2121
use Twig\Node\Expression\ConditionalExpression;
2222
use Twig\Node\Expression\ConstantExpression;
23-
use Twig\Node\Expression\NameExpression;
2423
use Twig\Node\Expression\Ternary\ConditionalTernary;
2524
use Twig\Node\Expression\Variable\ContextVariable;
26-
use Twig\Node\Node;
2725
use Twig\Node\Nodes;
2826
use Twig\TwigFunction;
2927

3028
class SearchAndRenderBlockNodeTest extends TestCase
3129
{
3230
public function testCompileWidget()
3331
{
34-
if (class_exists(Nodes::class)) {
35-
$ 9E88 arguments = new Nodes([
36-
new ContextVariable('form', 0),
37-
]);
38-
} else {
39-
$arguments = new Node([
40-
new NameExpression('form', 0),
41-
]);
42-
}
32+
$arguments = new Nodes([
33+
new ContextVariable('form', 0),
34+
]);
4335

4436
$node = new SearchAndRenderBlockNode(new TwigFunction('form_widget'), $arguments, 0);
4537

@@ -56,23 +48,13 @@ public function testCompileWidget()
5648

5749
public function testCompileWidgetWithVariables()
5850
{
59-
if (class_exists(Nodes::class)) {
60-
$arguments = new Nodes([
61-
new ContextVariable('form', 0),
62-
new ArrayExpression([
63-
new ConstantExpression('foo', 0),
64-
new ConstantExpression('bar', 0),
65-
], 0),
66-
]);
67-
} else {
68-
$arguments = new Node([
69-
new NameExpression('form', 0),
70-
new ArrayExpression([
71-
new ConstantExpression('foo', 0),
72-
new ConstantExpression('bar', 0),
73-
], 0),
74-
]);
75-
}
51+
$arguments = new Nodes([
52+
new ContextVariable('form', 0),
53+
new ArrayExpression([
54+
new ConstantExpression('foo', 0),
55+
new ConstantExpression('bar', 0),
56+
], 0),
57+
]);
7658

7759
$node = new SearchAndRenderBlockNode(new TwigFunction('form_widget'), $arguments, 0);
7860

@@ -89,17 +71,10 @@ public function testCompileWidgetWithVariables()
8971

9072
public function testCompileLabelWithLabel()
9173
{
92-
if (class_exists(Nodes::class)) {
93-
$arguments = new Nodes([
94-
new ContextVariable('form', 0),
95-
new ConstantExpression('my label', 0),
96-
]);
97-
} else {
98-
$arguments = new Node([
99-
new NameExpression('form', 0),
100-
new ConstantExpression('my label', 0),
101-
]);
102-
}
74+
$arguments = new Nodes([
75+
new ContextVariable('form', 0),
76+
new ConstantExpression('my label', 0),
77+
]);
10378

10479
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
10580

@@ -116,17 +91,10 @@ public function testCompileLabelWithLabel()
11691

11792
public function testCompileLabelWithNullLabel()
11893
{
119-
if (class_exists(Nodes::class)) {
120-
$arguments = new Nodes([
121-
new ContextVariable('form', 0),
122-
new ConstantExpression(null, 0),
123-
]);
124-
} else {
125-
$arguments = new Node([
126-
new NameExpression('form', 0),
127-
new ConstantExpression(null, 0),
128-
]);
129-
}
94+
$arguments = new Nodes([
95+
new ContextVariable('form', 0),
96+
new ConstantExpression(null, 0),
97+
]);
13098

13199
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
132100

@@ -145,17 +113,10 @@ public function testCompileLabelWithNullLabel()
145113

146114
public function testCompileLabelWithEmptyStringLabel()
147115
{
148-
if (class_exists(Nodes::class)) {
149-
$arguments = new Nodes([
150-
new ContextVariable('form', 0),
151-
new ConstantExpression('', 0),
152-
]);
153-
} else {
154-
$arguments = new Node([
155-
new NameExpression('form', 0),
156-
new ConstantExpression('', 0),
157-
]);
158-
}
116+
$arguments = new Nodes([
117+
new ContextVariable('form', 0),
118+
new ConstantExpression('', 0),
119+
]);
159120

160121
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
161122

@@ -174,15 +135,9 @@ public function testCompileLabelWithEmptyStringLabel()
174135

175136
public function testCompileLabelWithDefaultLabel()
176137
{
177-
if (class_exists(Nodes::class)) {
178-
$arguments = new Nodes([
179-
new ContextVariable('form', 0),
180-
]);
181-
} else {
182-
$arguments = new Node([
183-
new NameExpression('form', 0),
184-
]);
185-
}
138+
$arguments = new Nodes([
139+
new ContextVariable('form', 0),
140+
]);
186141

187142
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
188143

@@ -199,25 +154,14 @@ public function testCompileLabelWithDefaultLabel()
199154

200155
public function testCompileLabelWithAttributes()
201156
{
202-
if (class_exists(Nodes::class)) {
203-
$arguments = new Nodes([
204-
new ContextVariable('form', 0),
205-
new ConstantExpression(null, 0),
206-
new ArrayExpression([
207-
new ConstantExpression('foo', 0),
208-
new ConstantExpression('bar', 0),
209-
], 0),
210-
]);
211-
} else {
212-
$arguments = new Node([
213-
new NameExpression('form', 0),
214-
new ConstantExpression(null, 0),
215-
new ArrayExpression([
216-
new ConstantExpression('foo', 0),
217-
new ConstantExpression('bar', 0),
218-
], 0),
219-
]);
220-
}
157+
$arguments = new Nodes([
158+
new ContextVariable('form', 0),
159+
new ConstantExpression(null, 0),
160+
new ArrayExpression([
161+
new ConstantExpression('foo', 0),
162+
new ConstantExpression('bar', 0),
163+
], 0),
164+
]);
221165

222166
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
223167

@@ -237,29 +181,16 @@ public function testCompileLabelWithAttributes()
237181

238182
public function testCompileLabelWithLabelAndAttributes()
239183
{
240-
if (class_exists(Nodes::class)) {
241-
$arguments = new Nodes([
242-
new ContextVariable('form', 0),
243-
new ConstantExpression('value in argument', 0),
244-
new ArrayExpression([
245-
new ConstantExpression('foo', 0),
246-
new ConstantExpression('bar', 0),
247-
new ConstantExpression('label', 0),
248-
new ConstantExpression('value in attributes', 0),
249-
], 0),
250-
]);
251-
} else {
252-
$arguments = new Node([
253-
new NameExpression('form', 0),
254-
new ConstantExpression('value in argument', 0),
255-
new ArrayExpression([
256-
new ConstantExpression('foo', 0),
257-
new ConstantExpression('bar', 0),
258-
new ConstantExpression('label', 0),
259-
new ConstantExpression('value in attributes', 0),
260-
], 0),
261-
]);
262-
}
184+
$arguments = new Nodes([
185+
new ContextVariable('form', 0),
186+
new ConstantExpression('value in argument', 0),
187+
new ArrayExpression([
188+
new ConstantExpression('foo', 0),
189+
new ConstantExpression('bar', 0),
190+
new ConstantExpression('label', 0),
191+
new ConstantExpression('value in attributes', 0),
192+
], 0),
193+
]);
263194

264195
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
265196

@@ -298,11 +229,7 @@ public function testCompileLabelWithLabelThatEvaluatesToNull()
298229
);
299230
}
300231

301-
if (class_exists(Nodes::class)) {
302-
$arguments = new Nodes([new ContextVariable('form', 0), $conditional]);
303-
} else {
304-
$arguments = new Node([new NameExpression('form', 0), $conditional]);
305-
}
232+
$arguments = new Nodes([new ContextVariable('form', 0), $conditional]);
306233

307234
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
308235

@@ -345,29 +272,16 @@ public function testCompileLabelWithLabelThatEvaluatesToNullAndAttributes()
345272
);
346273
}
347274

348-
if (class_exists(Nodes::class)) {
349-
$arguments = new Nodes([
350-
new ContextVariable('form', 0),
351-
$conditional,
352-
new ArrayExpression([
353-
new ConstantExpression('foo', 0),
354-
new ConstantExpression('bar', 0),
355-
new ConstantExpression('label', 0),
356-
new ConstantExpression('value in attributes', 0),
357-
], 0),
358-
]);
359-
} else {
360-
$arguments = new Node([
361-
new NameExpression('form', 0),
362-
$conditional,
363-
new ArrayExpression([
364-
new ConstantExpression('foo', 0),
365-
new ConstantExpression('bar', 0),
366-
new ConstantExpression('label', 0),
367-
new ConstantExpression('value in attributes', 0),
368-
], 0),
369-
]);
370-
}
275+
$arguments = new Nodes([
276+
new ContextVariable('form', 0),
277+
$conditional,
278+
new ArrayExpression([
279+
new ConstantExpression('foo', 0),
280+
new ConstantExpression('bar', 0),
281+
new ConstantExpression('label', 0),
282+
new ConstantExpression('value in attributes', 0),
283+
], 0),
284+
]);
371285

372286
$node = new SearchAndRenderBlockNode(new TwigFunction('form_label'), $arguments, 0);
373287

src/Symfony/Bridge/Twig/Tests/NodeVisitor/TwigNodeProvider.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Twig\Node\Expression\ConstantExpression;
2020
use Twig\Node\Expression\FilterExpression;
2121
use Twig\Node\ModuleNode;
22-
use Twig\Node\Node;
2322
use Twig\Node\Nodes;
2423
use Twig\Source;
2524
use Twig\TwigFilter;
@@ -28,15 +27,13 @@ class TwigNodeProvider
2827
{
2928
public static function getModule($content)
3029
{
31-
$emptyNodeExists = class_exists(EmptyNode::class);
32-
3330
return new ModuleNode(
3431
new BodyNode([new ConstantExpression($content, 0)]),
3532
null,
36-
$emptyNodeExists ? new EmptyNode() : new ArrayExpression([], 0),
37-
$emptyNodeExists ? new EmptyNode() : new ArrayExpression([], 0),
38-
$emptyNodeExists ? new EmptyNode() : new ArrayExpression([], 0),
39-
$emptyNodeExists ? new EmptyNode() : null,
33+
new EmptyNode(),
34+
new EmptyNode(),
35+
new EmptyNode(),
36+
new EmptyNode(),
4037
new Source('', '')
4138
);
4239
}
@@ -50,16 +47,10 @@ public static function getTransFilter($message, $domain = null, $arguments = nul
5047
] : [];
5148
}
5249

53-
if (class_exists(Nodes::class)) {
54-
$args = new Nodes($arguments);
55-
} else {
56-
$args = new Node($arguments);
57-
}
58-
5950
return new FilterExpression(
6051
new ConstantExpression($message, 0),
6152
new TwigFilter('trans'),
62-
$args,
53+
new Nodes($arguments),
6354
0
6455
);
6556
}

0 commit comments

Comments
 (0)
0