1Insertion into list nodes
2-----
3<?php
4$foo;
5
6$bar;
7-----
8$stmts[] = new Stmt\Expression(new Expr\Variable('baz'));
9-----
10<?php
11$foo;
12
13$bar;
14$baz;
15-----
16<?php
17
18function test() {
19    $foo;
20
21    $bar;
22}
23-----
24$stmts[0]->stmts[] = new Stmt\Expression(new Expr\Variable('baz'));
25-----
26<?php
27
28function test() {
29    $foo;
30
31    $bar;
32    $baz;
33}
34-----
35<?php
36
37function test(Foo     $param1) {}
38-----
39$stmts[0]->params[] = new Node\Param(new Expr\Variable('param2'));
40-----
41<?php
42
43function test(Foo     $param1, $param2) {}
44-----
45<?php
46
47try {
48    /* stuff */
49} catch
50(Foo $x) {}
51-----
52$stmts[0]->catches[0]->types[] = new Node\Name('Bar');
53-----
54<?php
55
56try {
57    /* stuff */
58} catch
59(Foo|Bar $x) {}
60-----
61<?php
62
63function test(Foo     $param1) {}
64-----
65array_unshift($stmts[0]->params, new Node\Param(new Expr\Variable('param0')));
66-----
67<?php
68
69function test($param0, Foo     $param1) {}
70-----
71<?php
72
73function test() {}
74-----
75$stmts[0]->params[] = new Node\Param(new Expr\Variable('param0'));
76-----
77<?php
78
79function test($param0) {}
80-----
81<?php
82
83if ($cond) {
84} elseif ($cond2) {
85}
86-----
87$stmts[0]->elseifs[] = new Stmt\ElseIf_(new Expr\Variable('cond3'), []);
88-----
89<?php
90
91if ($cond) {
92} elseif ($cond2) {
93} elseif ($cond3) {
94}
95-----
96<?php
97
98try {
99} catch (Foo $foo) {
100}
101-----
102$stmts[0]->catches[] = new Stmt\Catch_([new Node\Name('Bar')], new Expr\Variable('bar'), []);
103-----
104<?php
105
106try {
107} catch (Foo $foo) {
108} catch (Bar $bar) {
109}
110-----
111<?php
112$foo; $bar;
113-----
114$node = new Stmt\Expression(new Expr\Variable('baz'));
115$node->setAttribute('comments', [new Comment('// Test')]);
116$stmts[] = $node;
117-----
118<?php
119$foo; $bar;
120// Test
121$baz;
122-----
123<?php
124function test() {
125    $foo; $bar;
126}
127-----
128$node = new Stmt\Expression(new Expr\Variable('baz'));
129$node->setAttribute('comments', [new Comment('// Test'), new Comment('// Test 2')]);
130$stmts[0]->stmts[] = $node;
131-----
132<?php
133function test() {
134    $foo; $bar;
135    // Test
136    // Test 2
137    $baz;
138}
139-----
140<?php
141namespace
142Foo;
143-----
144$stmts[0]->name->name = 'Xyz';
145-----
146<?php
147namespace
148Xyz;
149-----
150<?php
151function test() {
152    $foo; $bar;
153}
154-----
155$node = new Stmt\Expression(new Expr\Variable('baz'));
156array_unshift($stmts[0]->stmts, $node);
157-----
158<?php
159function test() {
160    $baz;
161    $foo; $bar;
162}
163-----
164<?php
165function test() {
166    $foo; $bar;
167}
168-----
169$node = new Stmt\Expression(new Expr\Variable('baz'));
170$node->setAttribute('comments', [new Comment('// Test')]);
171array_unshift($stmts[0]->stmts, $node);
172-----
173<?php
174function test() {
175    // Test
176    $baz;
177    $foo; $bar;
178}
179-----
180<?php
181function test() {
182
183    // Foo bar
184    $foo; $bar;
185}
186-----
187$node = new Stmt\Expression(new Expr\Variable('baz'));
188$node->setAttribute('comments', [new Comment('// Test')]);
189array_unshift($stmts[0]->stmts, $node);
190-----
191<?php
192function test() {
193
194    // Test
195    $baz;
196    // Foo bar
197    $foo; $bar;
198}
199-----
200<?php
201function test() {
202
203    // Foo bar
204    $foo; $bar;
205}
206-----
207$node = new Stmt\Expression(new Expr\Variable('baz'));
208$node->setAttribute('comments', [new Comment('// Test')]);
209array_unshift($stmts[0]->stmts, $node);
210$stmts[0]->stmts[1]->setAttribute('comments', [new Comment('// Bar foo')]);
211-----
212<?php
213function test() {
214
215    // Test
216    $baz;
217    // Bar foo
218    $foo; $bar;
219}
220-----
221<?php
222function test() {
223
224    // Foo bar
225    $foo; $bar;
226}
227-----
228$node = new Stmt\Expression(new Expr\Variable('baz'));
229$node->setAttribute('comments', [new Comment('// Test')]);
230array_unshift($stmts[0]->stmts, $node);
231$stmts[0]->stmts[1]->setAttribute('comments', []);
232-----
233<?php
234function test() {
235
236    // Test
237    $baz;
238    $foo; $bar;
239}
240-----
241<?php
242function test() {
243
244    // Foo bar
245    $foo; $bar;
246}
247-----
248array_unshift(
249    $stmts[0]->stmts,
250    new Stmt\Expression(new Expr\Variable('a')),
251    new Stmt\Expression(new Expr\Variable('b')));
252-----
253<?php
254function test() {
255
256    $a;
257    $b;
258    // Foo bar
259    $foo; $bar;
260}
261-----
262<?php
263function test() {}
264-----
265/* Insertion into empty list not handled yet */
266$stmts[0]->stmts = [
267    new Stmt\Expression(new Expr\Variable('a')),
268    new Stmt\Expression(new Expr\Variable('b')),
269];
270-----
271<?php
272function test()
273{
274    $a;
275    $b;
276}
277-----
278<?php
279$array = [
280    1,
281    2,
282    3,
283];
284-----
285array_unshift($stmts[0]->expr->expr->items, new Expr\ArrayItem(new Scalar\LNumber(42)));
286$stmts[0]->expr->expr->items[] = new Expr\ArrayItem(new Scalar\LNumber(24));
287-----
288<?php
289$array = [
290    42,
291    1,
292    2,
293    3,
294    24,
295];
296-----
297<?php
298$array = [
299    1, 2,
300    3,
301];
302-----
303$stmts[0]->expr->expr->items[] = new Expr\ArrayItem(new Scalar\LNumber(24));
304-----
305<?php
306$array = [
307    1, 2,
308    3, 24,
309];
310-----
311<?php
312function test(): A
313|B {}
314-----
315$stmts[0]->returnType->types[] = new Node\Name('C');
316-----
317<?php
318function test(): A
319|B|C {}
320-----
321<?php
322function test(): A
323&B {}
324-----
325$stmts[0]->returnType->types[] = new Node\Name('C');
326-----
327<?php
328function test(): A
329&B&C {}
330-----
331<?php
332function test() {
333    if ($x) {
334        $a;
335        $b;
336    }
337    $z;
338}
339-----
340$fnStmts =& $stmts[0]->stmts;
341array_splice($fnStmts, 0, 1, $fnStmts[0]->stmts);
342-----
343<?php
344function test() {
345    $a;
346    $b;
347    $z;
348}
349-----
350<?php
351list($x, $y) = $z;
352-----
353array_splice($stmts[0]->expr->var->items, 1, 0, [null]);
354-----
355<?php
356list($x, , $y) = $z;
357-----
358<?php
359{
360    $a; $b;
361}
362-----
363$stmts[0]->stmts[] = new Stmt\Expression(new Expr\Variable('c'));
364-----
365<?php
366{
367    $a; $b;
368    $c;
369}
370