Debian Codegraph @

vendor/mck89/peast/lib/Peast/Syntax/Node/Property.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 * A node that represents a property in an object literal.
14 * For example "b" in: a = {b: 1}
15 *
16 * @author Marco Marchiò <[email protected]>
17 */
18 class Property extends Node
19 {
20 /**
21 * Map of node properties
22 *
23 * @var array
24 */
25 protected $propertiesMap = array(
26 "key" => true,
27 "value" => true,
28 "kind" => false,
29 "method" => false,
30 "shorthand" => false,
31 "computed" => false
32 );
33
34 //Kind constants
35 /**
36 * The default kind for properties
37 */
38 const KIND_INIT = "init";
39
40 /**
41 * Getter property
42 */
43 const KIND_GET = "get";
44
45 /**
46 * Setter property
47 */
48 const KIND_SET = "set";
49
50 /**
51 * Property key
52 *
53 * @var Expression
54 */
55 protected $key;
56
57 /**
58 * Property value
59 *
60 * @var Expression
61 */
62 protected $value;
63
64 /**
65 * Property kind that is one of the kind constants
66 *
67 * @var string
68 */
69 protected $kind = self::KIND_INIT;
70
71 /**
72 * Property method flag that is true when the property is a method
73 *
74 * @var bool
75 */
76 protected $method = false;
77
78 /**
79 * Property shorthand flag that is true when the property is declared
80 * using an identifier and without a value
81 *
82 * @var bool
83 */
84 protected $shorthand = false;
85
86 /**
87 * Property computed flag that is true when the property is declared using
88 * the square brackets syntax
89 *
90 * @var bool
91 */
92 protected $computed = false;
93
94 /**
95 * Returns the property key
96 *
97 * @return Expression
98 */
99 public function getKey()
100 {
101 return $this->key;
102 }
103
104 /**
105 * Sets the property key
106 *
107 * @param Expression $key Property key
108 *
109 * @return $this
110 */
111 public function setKey(Expression $key)
112 {
113 $this->key = $key;
114 return $this;
115 }
116
117 /**
118 * Returns the property value
119 *
120 * @return Expression
121 */
122 public function getValue()
123 {
124 return $this->value;
125 }
126
127 /**
128 * Sets the property value
129 *
130 * @param Expression $value Property value
131 *
132 * @return $this
133 */
134 public function setValue($value)
135 {
136 $this->assertType($value, "Expression");
137 $this->value = $value;
138 return $this;
139 }
140
141 /**
142 * Returns the property kind that is one of the kind constants
143 *
144 * @return string
145 */
146 public function getKind()
147 {
148 return $this->kind;
149 }
150
151 /**
152 * Sets the property kind that is one of the kind constants
153 *
154 * @param string $kind Property kind
155 *
156 * @return $this
157 */
158 public function setKind($kind)
159 {
160 $this->kind = $kind;
161 return $this;
162 }
163
164 /**
165 * Returns the property method flag that is true when the property is a
166 * method
167 *
168 * @return bool
169 */
170 public function getMethod()
171 {
172 return $this->method;
173 }
174
175 /**
176 * Sets the property method flag that is true when the property is a method
177 *
178 * @param bool $method Method flag
179 *
180 * @return $this
181 */
182 public function setMethod($method)
183 {
184 $this->method = (bool) $method;
185 return $this;
186 }
187
188 /**
189 * Returns the property shorthand flag that is true when the property
190 * is declared using an identifier and without a value
191 *
192 * @return bool
193 */
194 public function getShorthand()
195 {
196 return $this->shorthand;
197 }
198
199 /**
200 * Sets the property shorthand flag that is true when the property
201 * is declared using an identifier and without a value
202 *
203 * @param bool $shorthand Property shorthand flag
204 *
205 * @return $this
206 */
207 public function setShorthand($shorthand)
208 {
209 $this->shorthand = (bool) $shorthand;
210 return $this;
211 }
212
213 /**
214 * Returns the property computed flag that is true when the property is
215 * declared using the square brackets syntax
216 *
217 * @return bool
218 */
219 public function getComputed()
220 {
221 return $this->computed;
222 }
223
224 /**
225 * Sets the property computed flag that is true when the property is
226 * declared using the square brackets syntax
227 *
228 * @param bool $computed Property computed flag
229 *
230 * @return $this
231 */
232 public function setComputed($computed)
233 {
234 $this->computed = (bool) $computed;
235 return $this;
236 }
237 }