1: | <?php declare(strict_types=1); |
2: | |
3: | namespace PhpParser\Builder; |
4: | |
5: | use PhpParser\BuilderHelpers; |
6: | use PhpParser\Node; |
7: | |
8: | abstract class FunctionLike extends Declaration { |
9: | protected bool $returnByRef = false; |
10: | |
11: | protected array $params = []; |
12: | |
13: | |
14: | protected ?Node $returnType = null; |
15: | |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | public function makeReturnByRef() { |
22: | $this->returnByRef = true; |
23: | |
24: | return $this; |
25: | } |
26: | |
27: | |
28: | |
29: | |
30: | |
31: | |
32: | |
33: | |
34: | public function addParam($param) { |
35: | $param = BuilderHelpers::normalizeNode($param); |
36: | |
37: | if (!$param instanceof Node\Param) { |
38: | throw new \LogicException(sprintf('Expected parameter node, got "%s"', $param->getType())); |
39: | } |
40: | |
41: | $this->params[] = $param; |
42: | |
43: | return $this; |
44: | } |
45: | |
46: | |
47: | |
48: | |
49: | |
50: | |
51: | |
52: | |
53: | public function addParams(array $params) { |
54: | foreach ($params as $param) { |
55: | $this->addParam($param); |
56: | } |
57: | |
58: | return $this; |
59: | } |
60: | |
61: | |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | |
68: | public function setReturnType($type) { |
69: | $this->returnType = BuilderHelpers::normalizeType($type); |
70: | |
71: | return $this; |
72: | } |
73: | } |
74: | |