261b4440b9596bb412267af71646dc9e1709546d
[yaffs-website] / vendor / nikic / php-parser / lib / PhpParser / Node / Expr / Closure.php
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 Closure extends Expr implements FunctionLike
10 {
11     /** @var bool Whether the closure is static */
12     public $static;
13     /** @var bool Whether to return by reference */
14     public $byRef;
15     /** @var Node\Param[] Parameters */
16     public $params;
17     /** @var ClosureUse[] use()s */
18     public $uses;
19     /** @var null|Node\Identifier|Node\Name|Node\NullableType Return type */
20     public $returnType;
21     /** @var Node\Stmt[] Statements */
22     public $stmts;
23
24     /**
25      * Constructs a lambda function node.
26      *
27      * @param array $subNodes   Array of the following optional subnodes:
28      *                          'static'     => false  : Whether the closure is static
29      *                          'byRef'      => false  : Whether to return by reference
30      *                          'params'     => array(): Parameters
31      *                          'uses'       => array(): use()s
32      *                          'returnType' => null   : Return type
33      *                          'stmts'      => array(): Statements
34      * @param array $attributes Additional attributes
35      */
36     public function __construct(array $subNodes = [], array $attributes = []) {
37         parent::__construct($attributes);
38         $this->static = $subNodes['static'] ?? false;
39         $this->byRef = $subNodes['byRef'] ?? false;
40         $this->params = $subNodes['params'] ?? [];
41         $this->uses = $subNodes['uses'] ?? [];
42         $returnType = $subNodes['returnType'] ?? null;
43         $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType;
44         $this->stmts = $subNodes['stmts'] ?? [];
45     }
46
47     public function getSubNodeNames() : array {
48         return ['static', 'byRef', 'params', 'uses', 'returnType', 'stmts'];
49     }
50
51     public function returnsByRef() : bool {
52         return $this->byRef;
53     }
54
55     public function getParams() : array {
56         return $this->params;
57     }
58
59     public function getReturnType() {
60         return $this->returnType;
61     }
62
63     /** @return Node\Stmt[] */
64     public function getStmts() : array {
65         return $this->stmts;
66     }
67     
68     public function getType() : string {
69         return 'Expr_Closure';
70     }
71 }