19
19
use PhpParser \Node \Expr \BinaryOp \GreaterOrEqual ;
20
20
use PhpParser \Node \Expr \BinaryOp \Identical ;
21
21
use PhpParser \Node \Expr \BinaryOp \NotIdentical ;
22
+ use PhpParser \Node \Expr \BinaryOp \Plus ;
22
23
use PhpParser \Node \Expr \BinaryOp \Smaller ;
23
24
use PhpParser \Node \Expr \BinaryOp \SmallerOrEqual ;
24
25
use PhpParser \Node \Expr \BooleanNot ;
25
26
use PhpParser \Node \Expr \Instanceof_ ;
27
+ use PhpParser \Node \Expr \PreInc ;
26
28
use PhpParser \Node \Expr \Ternary ;
27
29
use PhpParser \Node \Name ;
28
30
use PhpParser \Node \Stmt ;
34
36
use PhpParser \Node \Stmt \Else_ ;
35
37
use PhpParser \Node \Stmt \ElseIf_ ;
36
38
use PhpParser \Node \Stmt \Expression ;
39
+ use PhpParser \Node \Stmt \For_ ;
37
40
use PhpParser \Node \Stmt \Foreach_ ;
38
41
use PhpParser \Node \Stmt \If_ ;
39
42
use PhpParser \Node \Stmt \Nop ;
@@ -193,7 +196,7 @@ public function ternary(Expr $cond, Expr $ifTrue, Expr $else): Ternary
193
196
}
194
197
195
198
/**
196
- * @param list<Stmt> $then
199
+ * @param list<Stmt> $then
197
200
* @param list<Stmt>|null $else
198
201
*/
199
202
public function if (Expr $ if , array $ then , ?array $ else = null ): If_
@@ -221,6 +224,29 @@ public function foreach(Expr $expr, Expr $value, Expr $key, array $statements):
221
224
return new Foreach_ ($ expr , $ value , ['stmts ' => $ statements , 'keyVar ' => $ key ]);
222
225
}
223
226
227
+ /**
228
+ * @param list<Stmt> $statements
229
+ */
230
+ public function for (Expr $ init , Expr $ cond , Expr $ loop , array $ statements ): For_
231
+ {
232
+ return new For_ ([
233
+ 'init ' => [$ init ],
234
+ 'cond ' => [$ cond ],
235
+ 'loop ' => [$ loop ],
236
+ 'stmts ' => $ statements ,
237
+ ]);
238
+ }
239
+
240
+ public function preIncrement (Expr $ var ): PreInc
241
+ {
242
+ return new PreInc ($ var , []);
243
+ }
244
+
245
+ public function plus (Expr $ var , Expr $ value ): Plus
246
+ {
247
+ return new Plus ($ var , $ value );
248
+ }
249
+
224
250
/**
225
251
* @param array<int|string, scalar|array<mixed>|Expr|Arg|null> $args
226
252
*/
@@ -239,6 +265,11 @@ public function assign(Expr $var, Expr $expr): Expression
239
265
return new Expression (new Assign ($ var , $ expr ));
240
266
}
241
267
268
+ public function assignExpr (Expr $ var , Expr $ expr ): Assign
269
+ {
270
+ return new Assign ($ var , $ expr );
271
+ }
272
+
242
273
public function return (Expr $ expr ): Return_
243
274
{
244
275
return new Return_ ($ expr );
@@ -303,7 +334,7 @@ public function uniqVariableNames(string ...$names): array
303
334
304
335
/**
305
336
* @template T
306
- * @param callable(): T $cb
337
+ * @param callable(): T $cb
307
338
* @return T
308
339
*/
309
340
public function withVariableScope (callable $ cb ): mixed
@@ -406,7 +437,7 @@ public function importType(TypeNode $type): void
406
437
*/
407
438
public function phpDoc (array $ lines ): string
408
439
{
409
- $ lines = array_filter ($ lines , static fn (?string $ line ): bool => $ line !== null );
440
+ $ lines = array_filter ($ lines , static fn (?string $ line ): bool => $ line !== null );
410
441
411
442
if (count ($ lines ) === 0 ) {
412
443
return '' ;
0 commit comments