1: <?php declare(strict_types=1);
2:
3: namespace PhpParser\Node\Stmt;
4:
5: use PhpParser\Node;
6: use PhpParser\Node\FunctionLike;
7:
8: class Function_ extends Node\Stmt implements FunctionLike
9: {
10: /** @var bool Whether function returns by reference */
11: public $byRef;
12: /** @var Node\Identifier Name */
13: public $name;
14: /** @var Node\Param[] Parameters */
15: public $params;
16: /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */
17: public $returnType;
18: /** @var Node\Stmt[] Statements */
19: public $stmts;
20: /** @var Node\AttributeGroup[] PHP attribute groups */
21: public $attrGroups;
22:
23: /** @var Node\Name|null Namespaced name (if using NameResolver) */
24: public $namespacedName;
25:
26: /**
27: * Constructs a function node.
28: *
29: * @param string|Node\Identifier $name Name
30: * @param array $subNodes Array of the following optional subnodes:
31: * 'byRef' => false : Whether to return by reference
32: * 'params' => array(): Parameters
33: * 'returnType' => null : Return type
34: * 'stmts' => array(): Statements
35: * 'attrGroups' => array(): PHP attribute groups
36: * @param array $attributes Additional attributes
37: */
38: public function __construct($name, array $subNodes = [], array $attributes = []) {
39: $this->attributes = $attributes;
40: $this->byRef = $subNodes['byRef'] ?? false;
41: $this->name = \is_string($name) ? new Node\Identifier($name) : $name;
42: $this->params = $subNodes['params'] ?? [];
43: $returnType = $subNodes['returnType'] ?? null;
44: $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
45: $this->stmts = $subNodes['stmts'] ?? [];
46: $this->attrGroups = $subNodes['attrGroups'] ?? [];
47: }
48:
49: public function getSubNodeNames() : array {
50: return ['attrGroups', 'byRef', 'name', 'params', 'returnType', 'stmts'];
51: }
52:
53: public function returnsByRef() : bool {
54: return $this->byRef;
55: }
56:
57: public function getParams() : array {
58: return $this->params;
59: }
60:
61: public function getReturnType() {
62: return $this->returnType;
63: }
64:
65: public function getAttrGroups() : array {
66: return $this->attrGroups;
67: }
68:
69: /** @return Node\Stmt[] */
70: public function getStmts() : array {
71: return $this->stmts;
72: }
73:
74: public function getType() : string {
75: return 'Stmt_Function';
76: }
77: }
78: