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