1: | <?php declare(strict_types=1); |
2: | |
3: | namespace PhpParser\Builder; |
4: | |
5: | use PhpParser; |
6: | use PhpParser\BuilderHelpers; |
7: | use PhpParser\Node; |
8: | use PhpParser\Node\Stmt; |
9: | |
10: | class Function_ extends FunctionLike { |
11: | protected string $name; |
12: | |
13: | protected array $stmts = []; |
14: | |
15: | |
16: | protected array $attributeGroups = []; |
17: | |
18: | |
19: | |
20: | |
21: | |
22: | |
23: | public function __construct(string $name) { |
24: | $this->name = $name; |
25: | } |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | public function addStmt($stmt) { |
35: | $this->stmts[] = BuilderHelpers::normalizeStmt($stmt); |
36: | |
37: | return $this; |
38: | } |
39: | |
40: | |
41: | |
42: | |
43: | |
44: | |
45: | |
46: | |
47: | public function addAttribute($attribute) { |
48: | $this->attributeGroups[] = BuilderHelpers::normalizeAttribute($attribute); |
49: | |
50: | return $this; |
51: | } |
52: | |
53: | |
54: | |
55: | |
56: | |
57: | |
58: | public function getNode(): Node { |
59: | return new Stmt\Function_($this->name, [ |
60: | 'byRef' => $this->returnByRef, |
61: | 'params' => $this->params, |
62: | 'returnType' => $this->returnType, |
63: | 'stmts' => $this->stmts, |
64: | 'attrGroups' => $this->attributeGroups, |
65: | ], $this->attributes); |
66: | } |
67: | } |
68: | |