| 148 |
lars |
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 |
{
|
|
|
11 |
/** @var bool */
|
|
|
12 |
public $static;
|
|
|
13 |
|
|
|
14 |
/** @var bool */
|
|
|
15 |
public $byRef;
|
|
|
16 |
|
|
|
17 |
/** @var Node\Param[] */
|
|
|
18 |
public $params = [];
|
|
|
19 |
|
|
|
20 |
/** @var null|Node\Identifier|Node\Name|Node\ComplexType */
|
|
|
21 |
public $returnType;
|
|
|
22 |
|
|
|
23 |
/** @var Expr */
|
|
|
24 |
public $expr;
|
|
|
25 |
/** @var Node\AttributeGroup[] */
|
|
|
26 |
public $attrGroups;
|
|
|
27 |
|
|
|
28 |
/**
|
|
|
29 |
* @param array $subNodes Array of the following optional subnodes:
|
|
|
30 |
* 'static' => false : Whether the closure is static
|
|
|
31 |
* 'byRef' => false : Whether to return by reference
|
|
|
32 |
* 'params' => array() : Parameters
|
|
|
33 |
* 'returnType' => null : Return type
|
|
|
34 |
* 'expr' => Expr : Expression body
|
|
|
35 |
* 'attrGroups' => array() : PHP attribute groups
|
|
|
36 |
* @param array $attributes Additional attributes
|
|
|
37 |
*/
|
|
|
38 |
public function __construct(array $subNodes = [], array $attributes = []) {
|
|
|
39 |
$this->attributes = $attributes;
|
|
|
40 |
$this->static = $subNodes['static'] ?? false;
|
|
|
41 |
$this->byRef = $subNodes['byRef'] ?? false;
|
|
|
42 |
$this->params = $subNodes['params'] ?? [];
|
|
|
43 |
$returnType = $subNodes['returnType'] ?? null;
|
|
|
44 |
$this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
|
|
|
45 |
$this->expr = $subNodes['expr'];
|
|
|
46 |
$this->attrGroups = $subNodes['attrGroups'] ?? [];
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public function getSubNodeNames() : array {
|
|
|
50 |
return ['attrGroups', 'static', 'byRef', 'params', 'returnType', 'expr'];
|
|
|
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 |
/**
|
|
|
70 |
* @return Node\Stmt\Return_[]
|
|
|
71 |
*/
|
|
|
72 |
public function getStmts() : array {
|
|
|
73 |
return [new Node\Stmt\Return_($this->expr)];
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
public function getType() : string {
|
|
|
77 |
return 'Expr_ArrowFunction';
|
|
|
78 |
}
|
|
|
79 |
}
|