Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/Function_.php

raw
1 <?php
2 /**
3 * This file is part of the Peast package
4 *
5 * (c) Marco Marchiò <[email protected]>
6 *
7 * For the full copyright and license information refer to the LICENSE file
8 * distributed with this source code
9 */
10 namespace Peast\Syntax\Node;
11
12 /**
13 * Abstract class for functions.
14 *
15 * @author Marco Marchiò <[email protected]>
16 */
17 abstract class Function_ extends Node
18 {
19 /**
20 * Map of node properties
21 *
22 * @var array
23 */
24 protected $propertiesMap = array(
25 "id" => true,
26 "params" => true,
27 "body" => true,
28 "generator" => false,
29 "async" => false
30 );
31
32 /**
33 * Function name
34 *
35 * @var Identifier
36 */
37 protected $id;
38
39 /**
40 * Function parameters array
41 *
42 * @var Pattern[]
43 */
44 protected $params = array();
45
46 /**
47 * Function body
48 *
49 * @var BlockStatement
50 */
51 protected $body;
52
53 /**
54 * Generator flag that is true when the function is a generator
55 *
56 * @var bool
57 */
58 protected $generator = false;
59
60 /**
61 * Async flag that is true when it is an async function
62 *
63 * @var bool
64 */
65 protected $async = false;
66
67 /**
68 * Returns function name
69 *
70 * @return Identifier
71 */
72 public function getId()
73 {
74 return $this->id;
75 }
76
77 /**
78 * Sets function name
79 *
80 * @param Identifier $id Function name
81 *
82 * @return $this
83 */
84 public function setId($id)
85 {
86 $this->assertType($id, "Identifier", true);
87 $this->id = $id;
88 return $this;
89 }
90
91 /**
92 * Returns function parameters array
93 *
94 * @return Pattern[]
95 */
96 public function getParams()
97 {
98 return $this->params;
99 }
100
101 /**
102 * Sets function parameters array
103 *
104 * @param Pattern[] $params Function parameters array
105 *
106 * @return $this
107 */
108 public function setParams($params)
109 {
110 $this->assertArrayOf($params, "Pattern");
111 $this->params = $params;
112 return $this;
113 }
114
115 /**
116 * Returns function body
117 *
118 * @return BlockStatement
119 */
120 public function getBody()
121 {
122 return $this->body;
123 }
124
125 /**
126 * Sets function body
127 *
128 * @param BlockStatement $body Function body
129 *
130 * @return $this
131 */
132 public function setBody($body)
133 {
134 $this->assertType($body, "BlockStatement");
135 $this->body = $body;
136 return $this;
137 }
138
139 /**
140 * Returns the generator flag that is true when the function is a generator
141 *
142 * @return bool
143 */
144 public function getGenerator()
145 {
146 return $this->generator;
147 }
148
149 /**
150 * Sets the generator flag that is true when the function is a generator
151 *
152 * @param bool $generator Generator flag
153 *
154 * @return $this
155 */
156 public function setGenerator($generator)
157 {
158 $this->generator = (bool) $generator;
159 return $this;
160 }
161
162 /**
163 * Returns the async flag that is true when it is an async function
164 *
165 * @return bool
166 */
167 public function getAsync()
168 {
169 return $this->async;
170 }
171
172 /**
173 * Sets the async flag that is true when it is an async function
174 *
175 * @param bool $async Async flag
176 *
177 * @return $this
178 */
179 public function setAsync($async)
180 {
181 $this->async = (bool) $async;
182 return $this;
183 }
184 }