@@ -6,249 +6,249 @@ |
||
6 | 6 | |
7 | 7 | class Name extends NodeAbstract |
8 | 8 | { |
9 | - /** |
|
10 | - * @var string[] Parts of the name |
|
11 | - * @deprecated Use getParts() instead |
|
12 | - */ |
|
13 | - public $parts; |
|
14 | - |
|
15 | - private static $specialClassNames = [ |
|
16 | - 'self' => true, |
|
17 | - 'parent' => true, |
|
18 | - 'static' => true, |
|
19 | - ]; |
|
20 | - |
|
21 | - /** |
|
22 | - * Constructs a name node. |
|
23 | - * |
|
24 | - * @param string|string[]|self $name Name as string, part array or Name instance (copy ctor) |
|
25 | - * @param array $attributes Additional attributes |
|
26 | - */ |
|
27 | - public function __construct($name, array $attributes = []) { |
|
28 | - $this->attributes = $attributes; |
|
29 | - $this->parts = self::prepareName($name); |
|
30 | - } |
|
31 | - |
|
32 | - public function getSubNodeNames() : array { |
|
33 | - return ['parts']; |
|
34 | - } |
|
35 | - |
|
36 | - /** |
|
37 | - * Get parts of name (split by the namespace separator). |
|
38 | - * |
|
39 | - * @return string[] Parts of name |
|
40 | - */ |
|
41 | - public function getParts(): array { |
|
42 | - return $this->parts; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * Gets the first part of the name, i.e. everything before the first namespace separator. |
|
47 | - * |
|
48 | - * @return string First part of the name |
|
49 | - */ |
|
50 | - public function getFirst() : string { |
|
51 | - return $this->parts[0]; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Gets the last part of the name, i.e. everything after the last namespace separator. |
|
56 | - * |
|
57 | - * @return string Last part of the name |
|
58 | - */ |
|
59 | - public function getLast() : string { |
|
60 | - return $this->parts[count($this->parts) - 1]; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Checks whether the name is unqualified. (E.g. Name) |
|
65 | - * |
|
66 | - * @return bool Whether the name is unqualified |
|
67 | - */ |
|
68 | - public function isUnqualified() : bool { |
|
69 | - return 1 === count($this->parts); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * Checks whether the name is qualified. (E.g. Name\Name) |
|
74 | - * |
|
75 | - * @return bool Whether the name is qualified |
|
76 | - */ |
|
77 | - public function isQualified() : bool { |
|
78 | - return 1 < count($this->parts); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Checks whether the name is fully qualified. (E.g. \Name) |
|
83 | - * |
|
84 | - * @return bool Whether the name is fully qualified |
|
85 | - */ |
|
86 | - public function isFullyQualified() : bool { |
|
87 | - return false; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) |
|
92 | - * |
|
93 | - * @return bool Whether the name is relative |
|
94 | - */ |
|
95 | - public function isRelative() : bool { |
|
96 | - return false; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns a string representation of the name itself, without taking the name type into |
|
101 | - * account (e.g., not including a leading backslash for fully qualified names). |
|
102 | - * |
|
103 | - * @return string String representation |
|
104 | - */ |
|
105 | - public function toString() : string { |
|
106 | - return implode('\\', $this->parts); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Returns a string representation of the name as it would occur in code (e.g., including |
|
111 | - * leading backslash for fully qualified names. |
|
112 | - * |
|
113 | - * @return string String representation |
|
114 | - */ |
|
115 | - public function toCodeString() : string { |
|
116 | - return $this->toString(); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Returns lowercased string representation of the name, without taking the name type into |
|
121 | - * account (e.g., no leading backslash for fully qualified names). |
|
122 | - * |
|
123 | - * @return string Lowercased string representation |
|
124 | - */ |
|
125 | - public function toLowerString() : string { |
|
126 | - return strtolower(implode('\\', $this->parts)); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Checks whether the identifier is a special class name (self, parent or static). |
|
131 | - * |
|
132 | - * @return bool Whether identifier is a special class name |
|
133 | - */ |
|
134 | - public function isSpecialClassName() : bool { |
|
135 | - return count($this->parts) === 1 |
|
136 | - && isset(self::$specialClassNames[strtolower($this->parts[0])]); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Returns a string representation of the name by imploding the namespace parts with the |
|
141 | - * namespace separator. |
|
142 | - * |
|
143 | - * @return string String representation |
|
144 | - */ |
|
145 | - public function __toString() : string { |
|
146 | - return implode('\\', $this->parts); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Gets a slice of a name (similar to array_slice). |
|
151 | - * |
|
152 | - * This method returns a new instance of the same type as the original and with the same |
|
153 | - * attributes. |
|
154 | - * |
|
155 | - * If the slice is empty, null is returned. The null value will be correctly handled in |
|
156 | - * concatenations using concat(). |
|
157 | - * |
|
158 | - * Offset and length have the same meaning as in array_slice(). |
|
159 | - * |
|
160 | - * @param int $offset Offset to start the slice at (may be negative) |
|
161 | - * @param int|null $length Length of the slice (may be negative) |
|
162 | - * |
|
163 | - * @return static|null Sliced name |
|
164 | - */ |
|
165 | - public function slice(int $offset, ?int $length = null) { |
|
166 | - $numParts = count($this->parts); |
|
167 | - |
|
168 | - $realOffset = $offset < 0 ? $offset + $numParts : $offset; |
|
169 | - if ($realOffset < 0 || $realOffset > $numParts) { |
|
170 | - throw new \OutOfBoundsException(sprintf('Offset %d is out of bounds', $offset)); |
|
171 | - } |
|
172 | - |
|
173 | - if (null === $length) { |
|
174 | - $realLength = $numParts - $realOffset; |
|
175 | - } else { |
|
176 | - $realLength = $length < 0 ? $length + $numParts - $realOffset : $length; |
|
177 | - if ($realLength < 0 || $realLength > $numParts - $realOffset) { |
|
178 | - throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length)); |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - if ($realLength === 0) { |
|
183 | - // Empty slice is represented as null |
|
184 | - return null; |
|
185 | - } |
|
186 | - |
|
187 | - return new static(array_slice($this->parts, $realOffset, $realLength), $this->attributes); |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Concatenate two names, yielding a new Name instance. |
|
192 | - * |
|
193 | - * The type of the generated instance depends on which class this method is called on, for |
|
194 | - * example Name\FullyQualified::concat() will yield a Name\FullyQualified instance. |
|
195 | - * |
|
196 | - * If one of the arguments is null, a new instance of the other name will be returned. If both |
|
197 | - * arguments are null, null will be returned. As such, writing |
|
198 | - * Name::concat($namespace, $shortName) |
|
199 | - * where $namespace is a Name node or null will work as expected. |
|
200 | - * |
|
201 | - * @param string|string[]|self|null $name1 The first name |
|
202 | - * @param string|string[]|self|null $name2 The second name |
|
203 | - * @param array $attributes Attributes to assign to concatenated name |
|
204 | - * |
|
205 | - * @return static|null Concatenated name |
|
206 | - */ |
|
207 | - public static function concat($name1, $name2, array $attributes = []) { |
|
208 | - if (null === $name1 && null === $name2) { |
|
209 | - return null; |
|
210 | - } elseif (null === $name1) { |
|
211 | - return new static(self::prepareName($name2), $attributes); |
|
212 | - } elseif (null === $name2) { |
|
213 | - return new static(self::prepareName($name1), $attributes); |
|
214 | - } else { |
|
215 | - return new static( |
|
216 | - array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes |
|
217 | - ); |
|
218 | - } |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Prepares a (string, array or Name node) name for use in name changing methods by converting |
|
223 | - * it to an array. |
|
224 | - * |
|
225 | - * @param string|string[]|self $name Name to prepare |
|
226 | - * |
|
227 | - * @return string[] Prepared name |
|
228 | - */ |
|
229 | - private static function prepareName($name) : array { |
|
230 | - if (\is_string($name)) { |
|
231 | - if ('' === $name) { |
|
232 | - throw new \InvalidArgumentException('Name cannot be empty'); |
|
233 | - } |
|
234 | - |
|
235 | - return explode('\\', $name); |
|
236 | - } elseif (\is_array($name)) { |
|
237 | - if (empty($name)) { |
|
238 | - throw new \InvalidArgumentException('Name cannot be empty'); |
|
239 | - } |
|
240 | - |
|
241 | - return $name; |
|
242 | - } elseif ($name instanceof self) { |
|
243 | - return $name->parts; |
|
244 | - } |
|
245 | - |
|
246 | - throw new \InvalidArgumentException( |
|
247 | - 'Expected string, array of parts or Name instance' |
|
248 | - ); |
|
249 | - } |
|
250 | - |
|
251 | - public function getType() : string { |
|
252 | - return 'Name'; |
|
253 | - } |
|
9 | + /** |
|
10 | + * @var string[] Parts of the name |
|
11 | + * @deprecated Use getParts() instead |
|
12 | + */ |
|
13 | + public $parts; |
|
14 | + |
|
15 | + private static $specialClassNames = [ |
|
16 | + 'self' => true, |
|
17 | + 'parent' => true, |
|
18 | + 'static' => true, |
|
19 | + ]; |
|
20 | + |
|
21 | + /** |
|
22 | + * Constructs a name node. |
|
23 | + * |
|
24 | + * @param string|string[]|self $name Name as string, part array or Name instance (copy ctor) |
|
25 | + * @param array $attributes Additional attributes |
|
26 | + */ |
|
27 | + public function __construct($name, array $attributes = []) { |
|
28 | + $this->attributes = $attributes; |
|
29 | + $this->parts = self::prepareName($name); |
|
30 | + } |
|
31 | + |
|
32 | + public function getSubNodeNames() : array { |
|
33 | + return ['parts']; |
|
34 | + } |
|
35 | + |
|
36 | + /** |
|
37 | + * Get parts of name (split by the namespace separator). |
|
38 | + * |
|
39 | + * @return string[] Parts of name |
|
40 | + */ |
|
41 | + public function getParts(): array { |
|
42 | + return $this->parts; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * Gets the first part of the name, i.e. everything before the first namespace separator. |
|
47 | + * |
|
48 | + * @return string First part of the name |
|
49 | + */ |
|
50 | + public function getFirst() : string { |
|
51 | + return $this->parts[0]; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Gets the last part of the name, i.e. everything after the last namespace separator. |
|
56 | + * |
|
57 | + * @return string Last part of the name |
|
58 | + */ |
|
59 | + public function getLast() : string { |
|
60 | + return $this->parts[count($this->parts) - 1]; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Checks whether the name is unqualified. (E.g. Name) |
|
65 | + * |
|
66 | + * @return bool Whether the name is unqualified |
|
67 | + */ |
|
68 | + public function isUnqualified() : bool { |
|
69 | + return 1 === count($this->parts); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * Checks whether the name is qualified. (E.g. Name\Name) |
|
74 | + * |
|
75 | + * @return bool Whether the name is qualified |
|
76 | + */ |
|
77 | + public function isQualified() : bool { |
|
78 | + return 1 < count($this->parts); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Checks whether the name is fully qualified. (E.g. \Name) |
|
83 | + * |
|
84 | + * @return bool Whether the name is fully qualified |
|
85 | + */ |
|
86 | + public function isFullyQualified() : bool { |
|
87 | + return false; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Checks whether the name is explicitly relative to the current namespace. (E.g. namespace\Name) |
|
92 | + * |
|
93 | + * @return bool Whether the name is relative |
|
94 | + */ |
|
95 | + public function isRelative() : bool { |
|
96 | + return false; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns a string representation of the name itself, without taking the name type into |
|
101 | + * account (e.g., not including a leading backslash for fully qualified names). |
|
102 | + * |
|
103 | + * @return string String representation |
|
104 | + */ |
|
105 | + public function toString() : string { |
|
106 | + return implode('\\', $this->parts); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Returns a string representation of the name as it would occur in code (e.g., including |
|
111 | + * leading backslash for fully qualified names. |
|
112 | + * |
|
113 | + * @return string String representation |
|
114 | + */ |
|
115 | + public function toCodeString() : string { |
|
116 | + return $this->toString(); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Returns lowercased string representation of the name, without taking the name type into |
|
121 | + * account (e.g., no leading backslash for fully qualified names). |
|
122 | + * |
|
123 | + * @return string Lowercased string representation |
|
124 | + */ |
|
125 | + public function toLowerString() : string { |
|
126 | + return strtolower(implode('\\', $this->parts)); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Checks whether the identifier is a special class name (self, parent or static). |
|
131 | + * |
|
132 | + * @return bool Whether identifier is a special class name |
|
133 | + */ |
|
134 | + public function isSpecialClassName() : bool { |
|
135 | + return count($this->parts) === 1 |
|
136 | + && isset(self::$specialClassNames[strtolower($this->parts[0])]); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Returns a string representation of the name by imploding the namespace parts with the |
|
141 | + * namespace separator. |
|
142 | + * |
|
143 | + * @return string String representation |
|
144 | + */ |
|
145 | + public function __toString() : string { |
|
146 | + return implode('\\', $this->parts); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Gets a slice of a name (similar to array_slice). |
|
151 | + * |
|
152 | + * This method returns a new instance of the same type as the original and with the same |
|
153 | + * attributes. |
|
154 | + * |
|
155 | + * If the slice is empty, null is returned. The null value will be correctly handled in |
|
156 | + * concatenations using concat(). |
|
157 | + * |
|
158 | + * Offset and length have the same meaning as in array_slice(). |
|
159 | + * |
|
160 | + * @param int $offset Offset to start the slice at (may be negative) |
|
161 | + * @param int|null $length Length of the slice (may be negative) |
|
162 | + * |
|
163 | + * @return static|null Sliced name |
|
164 | + */ |
|
165 | + public function slice(int $offset, ?int $length = null) { |
|
166 | + $numParts = count($this->parts); |
|
167 | + |
|
168 | + $realOffset = $offset < 0 ? $offset + $numParts : $offset; |
|
169 | + if ($realOffset < 0 || $realOffset > $numParts) { |
|
170 | + throw new \OutOfBoundsException(sprintf('Offset %d is out of bounds', $offset)); |
|
171 | + } |
|
172 | + |
|
173 | + if (null === $length) { |
|
174 | + $realLength = $numParts - $realOffset; |
|
175 | + } else { |
|
176 | + $realLength = $length < 0 ? $length + $numParts - $realOffset : $length; |
|
177 | + if ($realLength < 0 || $realLength > $numParts - $realOffset) { |
|
178 | + throw new \OutOfBoundsException(sprintf('Length %d is out of bounds', $length)); |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + if ($realLength === 0) { |
|
183 | + // Empty slice is represented as null |
|
184 | + return null; |
|
185 | + } |
|
186 | + |
|
187 | + return new static(array_slice($this->parts, $realOffset, $realLength), $this->attributes); |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Concatenate two names, yielding a new Name instance. |
|
192 | + * |
|
193 | + * The type of the generated instance depends on which class this method is called on, for |
|
194 | + * example Name\FullyQualified::concat() will yield a Name\FullyQualified instance. |
|
195 | + * |
|
196 | + * If one of the arguments is null, a new instance of the other name will be returned. If both |
|
197 | + * arguments are null, null will be returned. As such, writing |
|
198 | + * Name::concat($namespace, $shortName) |
|
199 | + * where $namespace is a Name node or null will work as expected. |
|
200 | + * |
|
201 | + * @param string|string[]|self|null $name1 The first name |
|
202 | + * @param string|string[]|self|null $name2 The second name |
|
203 | + * @param array $attributes Attributes to assign to concatenated name |
|
204 | + * |
|
205 | + * @return static|null Concatenated name |
|
206 | + */ |
|
207 | + public static function concat($name1, $name2, array $attributes = []) { |
|
208 | + if (null === $name1 && null === $name2) { |
|
209 | + return null; |
|
210 | + } elseif (null === $name1) { |
|
211 | + return new static(self::prepareName($name2), $attributes); |
|
212 | + } elseif (null === $name2) { |
|
213 | + return new static(self::prepareName($name1), $attributes); |
|
214 | + } else { |
|
215 | + return new static( |
|
216 | + array_merge(self::prepareName($name1), self::prepareName($name2)), $attributes |
|
217 | + ); |
|
218 | + } |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Prepares a (string, array or Name node) name for use in name changing methods by converting |
|
223 | + * it to an array. |
|
224 | + * |
|
225 | + * @param string|string[]|self $name Name to prepare |
|
226 | + * |
|
227 | + * @return string[] Prepared name |
|
228 | + */ |
|
229 | + private static function prepareName($name) : array { |
|
230 | + if (\is_string($name)) { |
|
231 | + if ('' === $name) { |
|
232 | + throw new \InvalidArgumentException('Name cannot be empty'); |
|
233 | + } |
|
234 | + |
|
235 | + return explode('\\', $name); |
|
236 | + } elseif (\is_array($name)) { |
|
237 | + if (empty($name)) { |
|
238 | + throw new \InvalidArgumentException('Name cannot be empty'); |
|
239 | + } |
|
240 | + |
|
241 | + return $name; |
|
242 | + } elseif ($name instanceof self) { |
|
243 | + return $name->parts; |
|
244 | + } |
|
245 | + |
|
246 | + throw new \InvalidArgumentException( |
|
247 | + 'Expected string, array of parts or Name instance' |
|
248 | + ); |
|
249 | + } |
|
250 | + |
|
251 | + public function getType() : string { |
|
252 | + return 'Name'; |
|
253 | + } |
|
254 | 254 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\NodeAbstract; |
6 | 6 | |
7 | -class Name extends NodeAbstract |
|
8 | -{ |
|
7 | +class Name extends NodeAbstract { |
|
9 | 8 | /** |
10 | 9 | * @var string[] Parts of the name |
11 | 10 | * @deprecated Use getParts() instead |
@@ -6,72 +6,72 @@ |
||
6 | 6 | |
7 | 7 | class DNumber extends Scalar |
8 | 8 | { |
9 | - /** @var float Number value */ |
|
10 | - public $value; |
|
9 | + /** @var float Number value */ |
|
10 | + public $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a float number scalar node. |
|
14 | - * |
|
15 | - * @param float $value Value of the number |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(float $value, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->value = $value; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a float number scalar node. |
|
14 | + * |
|
15 | + * @param float $value Value of the number |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(float $value, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->value = $value; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['value']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['value']; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param mixed[] $attributes |
|
29 | - */ |
|
30 | - public static function fromString(string $str, array $attributes = []): DNumber |
|
31 | - { |
|
32 | - $attributes['rawValue'] = $str; |
|
33 | - $float = self::parse($str); |
|
27 | + /** |
|
28 | + * @param mixed[] $attributes |
|
29 | + */ |
|
30 | + public static function fromString(string $str, array $attributes = []): DNumber |
|
31 | + { |
|
32 | + $attributes['rawValue'] = $str; |
|
33 | + $float = self::parse($str); |
|
34 | 34 | |
35 | - return new DNumber($float, $attributes); |
|
36 | - } |
|
35 | + return new DNumber($float, $attributes); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @internal |
|
40 | - * |
|
41 | - * Parses a DNUMBER token like PHP would. |
|
42 | - * |
|
43 | - * @param string $str A string number |
|
44 | - * |
|
45 | - * @return float The parsed number |
|
46 | - */ |
|
47 | - public static function parse(string $str) : float { |
|
48 | - $str = str_replace('_', '', $str); |
|
38 | + /** |
|
39 | + * @internal |
|
40 | + * |
|
41 | + * Parses a DNUMBER token like PHP would. |
|
42 | + * |
|
43 | + * @param string $str A string number |
|
44 | + * |
|
45 | + * @return float The parsed number |
|
46 | + */ |
|
47 | + public static function parse(string $str) : float { |
|
48 | + $str = str_replace('_', '', $str); |
|
49 | 49 | |
50 | - // Check whether this is one of the special integer notations. |
|
51 | - if ('0' === $str[0]) { |
|
52 | - // hex |
|
53 | - if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | - return hexdec($str); |
|
55 | - } |
|
50 | + // Check whether this is one of the special integer notations. |
|
51 | + if ('0' === $str[0]) { |
|
52 | + // hex |
|
53 | + if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | + return hexdec($str); |
|
55 | + } |
|
56 | 56 | |
57 | - // bin |
|
58 | - if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | - return bindec($str); |
|
60 | - } |
|
57 | + // bin |
|
58 | + if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | + return bindec($str); |
|
60 | + } |
|
61 | 61 | |
62 | - // oct, but only if the string does not contain any of '.eE'. |
|
63 | - if (false === strpbrk($str, '.eE')) { |
|
64 | - // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit |
|
65 | - // (8 or 9) so that only the digits before that are used. |
|
66 | - return octdec(substr($str, 0, strcspn($str, '89'))); |
|
67 | - } |
|
68 | - } |
|
62 | + // oct, but only if the string does not contain any of '.eE'. |
|
63 | + if (false === strpbrk($str, '.eE')) { |
|
64 | + // substr($str, 0, strcspn($str, '89')) cuts the string at the first invalid digit |
|
65 | + // (8 or 9) so that only the digits before that are used. |
|
66 | + return octdec(substr($str, 0, strcspn($str, '89'))); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - // dec |
|
71 | - return (float) $str; |
|
72 | - } |
|
70 | + // dec |
|
71 | + return (float) $str; |
|
72 | + } |
|
73 | 73 | |
74 | - public function getType() : string { |
|
75 | - return 'Scalar_DNumber'; |
|
76 | - } |
|
74 | + public function getType() : string { |
|
75 | + return 'Scalar_DNumber'; |
|
76 | + } |
|
77 | 77 | } |
@@ -68,7 +68,7 @@ |
||
68 | 68 | } |
69 | 69 | |
70 | 70 | // dec |
71 | - return (float) $str; |
|
71 | + return (float)$str; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | public function getType() : string { |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar; |
6 | 6 | |
7 | -class DNumber extends Scalar |
|
8 | -{ |
|
7 | +class DNumber extends Scalar { |
|
9 | 8 | /** @var float Number value */ |
10 | 9 | public $value; |
11 | 10 |
@@ -7,151 +7,151 @@ |
||
7 | 7 | |
8 | 8 | class String_ extends Scalar |
9 | 9 | { |
10 | - /* For use in "kind" attribute */ |
|
11 | - const KIND_SINGLE_QUOTED = 1; |
|
12 | - const KIND_DOUBLE_QUOTED = 2; |
|
13 | - const KIND_HEREDOC = 3; |
|
14 | - const KIND_NOWDOC = 4; |
|
15 | - |
|
16 | - /** @var string String value */ |
|
17 | - public $value; |
|
18 | - |
|
19 | - protected static $replacements = [ |
|
20 | - '\\' => '\\', |
|
21 | - '$' => '$', |
|
22 | - 'n' => "\n", |
|
23 | - 'r' => "\r", |
|
24 | - 't' => "\t", |
|
25 | - 'f' => "\f", |
|
26 | - 'v' => "\v", |
|
27 | - 'e' => "\x1B", |
|
28 | - ]; |
|
29 | - |
|
30 | - /** |
|
31 | - * Constructs a string scalar node. |
|
32 | - * |
|
33 | - * @param string $value Value of the string |
|
34 | - * @param array $attributes Additional attributes |
|
35 | - */ |
|
36 | - public function __construct(string $value, array $attributes = []) { |
|
37 | - $this->attributes = $attributes; |
|
38 | - $this->value = $value; |
|
39 | - } |
|
40 | - |
|
41 | - public function getSubNodeNames() : array { |
|
42 | - return ['value']; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
47 | - */ |
|
48 | - public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self |
|
49 | - { |
|
50 | - $attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B'))) |
|
51 | - ? Scalar\String_::KIND_SINGLE_QUOTED |
|
52 | - : Scalar\String_::KIND_DOUBLE_QUOTED; |
|
53 | - |
|
54 | - $attributes['rawValue'] = $str; |
|
55 | - |
|
56 | - $string = self::parse($str, $parseUnicodeEscape); |
|
57 | - |
|
58 | - return new self($string, $attributes); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @internal |
|
63 | - * |
|
64 | - * Parses a string token. |
|
65 | - * |
|
66 | - * @param string $str String token content |
|
67 | - * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
68 | - * |
|
69 | - * @return string The parsed string |
|
70 | - */ |
|
71 | - public static function parse(string $str, bool $parseUnicodeEscape = true) : string { |
|
72 | - $bLength = 0; |
|
73 | - if ('b' === $str[0] || 'B' === $str[0]) { |
|
74 | - $bLength = 1; |
|
75 | - } |
|
76 | - |
|
77 | - if ('\'' === $str[$bLength]) { |
|
78 | - return str_replace( |
|
79 | - ['\\\\', '\\\''], |
|
80 | - ['\\', '\''], |
|
81 | - substr($str, $bLength + 1, -1) |
|
82 | - ); |
|
83 | - } else { |
|
84 | - return self::parseEscapeSequences( |
|
85 | - substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape |
|
86 | - ); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * @internal |
|
92 | - * |
|
93 | - * Parses escape sequences in strings (all string types apart from single quoted). |
|
94 | - * |
|
95 | - * @param string $str String without quotes |
|
96 | - * @param null|string $quote Quote type |
|
97 | - * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
98 | - * |
|
99 | - * @return string String with escape sequences parsed |
|
100 | - */ |
|
101 | - public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { |
|
102 | - if (null !== $quote) { |
|
103 | - $str = str_replace('\\' . $quote, $quote, $str); |
|
104 | - } |
|
105 | - |
|
106 | - $extra = ''; |
|
107 | - if ($parseUnicodeEscape) { |
|
108 | - $extra = '|u\{([0-9a-fA-F]+)\}'; |
|
109 | - } |
|
110 | - |
|
111 | - return preg_replace_callback( |
|
112 | - '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', |
|
113 | - function($matches) { |
|
114 | - $str = $matches[1]; |
|
115 | - |
|
116 | - if (isset(self::$replacements[$str])) { |
|
117 | - return self::$replacements[$str]; |
|
118 | - } elseif ('x' === $str[0] || 'X' === $str[0]) { |
|
119 | - return chr(hexdec(substr($str, 1))); |
|
120 | - } elseif ('u' === $str[0]) { |
|
121 | - return self::codePointToUtf8(hexdec($matches[2])); |
|
122 | - } else { |
|
123 | - return chr(octdec($str)); |
|
124 | - } |
|
125 | - }, |
|
126 | - $str |
|
127 | - ); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Converts a Unicode code point to its UTF-8 encoded representation. |
|
132 | - * |
|
133 | - * @param int $num Code point |
|
134 | - * |
|
135 | - * @return string UTF-8 representation of code point |
|
136 | - */ |
|
137 | - private static function codePointToUtf8(int $num) : string { |
|
138 | - if ($num <= 0x7F) { |
|
139 | - return chr($num); |
|
140 | - } |
|
141 | - if ($num <= 0x7FF) { |
|
142 | - return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); |
|
143 | - } |
|
144 | - if ($num <= 0xFFFF) { |
|
145 | - return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
146 | - } |
|
147 | - if ($num <= 0x1FFFFF) { |
|
148 | - return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) |
|
149 | - . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
150 | - } |
|
151 | - throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); |
|
152 | - } |
|
153 | - |
|
154 | - public function getType() : string { |
|
155 | - return 'Scalar_String'; |
|
156 | - } |
|
10 | + /* For use in "kind" attribute */ |
|
11 | + const KIND_SINGLE_QUOTED = 1; |
|
12 | + const KIND_DOUBLE_QUOTED = 2; |
|
13 | + const KIND_HEREDOC = 3; |
|
14 | + const KIND_NOWDOC = 4; |
|
15 | + |
|
16 | + /** @var string String value */ |
|
17 | + public $value; |
|
18 | + |
|
19 | + protected static $replacements = [ |
|
20 | + '\\' => '\\', |
|
21 | + '$' => '$', |
|
22 | + 'n' => "\n", |
|
23 | + 'r' => "\r", |
|
24 | + 't' => "\t", |
|
25 | + 'f' => "\f", |
|
26 | + 'v' => "\v", |
|
27 | + 'e' => "\x1B", |
|
28 | + ]; |
|
29 | + |
|
30 | + /** |
|
31 | + * Constructs a string scalar node. |
|
32 | + * |
|
33 | + * @param string $value Value of the string |
|
34 | + * @param array $attributes Additional attributes |
|
35 | + */ |
|
36 | + public function __construct(string $value, array $attributes = []) { |
|
37 | + $this->attributes = $attributes; |
|
38 | + $this->value = $value; |
|
39 | + } |
|
40 | + |
|
41 | + public function getSubNodeNames() : array { |
|
42 | + return ['value']; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
47 | + */ |
|
48 | + public static function fromString(string $str, array $attributes = [], bool $parseUnicodeEscape = true): self |
|
49 | + { |
|
50 | + $attributes['kind'] = ($str[0] === "'" || ($str[1] === "'" && ($str[0] === 'b' || $str[0] === 'B'))) |
|
51 | + ? Scalar\String_::KIND_SINGLE_QUOTED |
|
52 | + : Scalar\String_::KIND_DOUBLE_QUOTED; |
|
53 | + |
|
54 | + $attributes['rawValue'] = $str; |
|
55 | + |
|
56 | + $string = self::parse($str, $parseUnicodeEscape); |
|
57 | + |
|
58 | + return new self($string, $attributes); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @internal |
|
63 | + * |
|
64 | + * Parses a string token. |
|
65 | + * |
|
66 | + * @param string $str String token content |
|
67 | + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
68 | + * |
|
69 | + * @return string The parsed string |
|
70 | + */ |
|
71 | + public static function parse(string $str, bool $parseUnicodeEscape = true) : string { |
|
72 | + $bLength = 0; |
|
73 | + if ('b' === $str[0] || 'B' === $str[0]) { |
|
74 | + $bLength = 1; |
|
75 | + } |
|
76 | + |
|
77 | + if ('\'' === $str[$bLength]) { |
|
78 | + return str_replace( |
|
79 | + ['\\\\', '\\\''], |
|
80 | + ['\\', '\''], |
|
81 | + substr($str, $bLength + 1, -1) |
|
82 | + ); |
|
83 | + } else { |
|
84 | + return self::parseEscapeSequences( |
|
85 | + substr($str, $bLength + 1, -1), '"', $parseUnicodeEscape |
|
86 | + ); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * @internal |
|
92 | + * |
|
93 | + * Parses escape sequences in strings (all string types apart from single quoted). |
|
94 | + * |
|
95 | + * @param string $str String without quotes |
|
96 | + * @param null|string $quote Quote type |
|
97 | + * @param bool $parseUnicodeEscape Whether to parse PHP 7 \u escapes |
|
98 | + * |
|
99 | + * @return string String with escape sequences parsed |
|
100 | + */ |
|
101 | + public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { |
|
102 | + if (null !== $quote) { |
|
103 | + $str = str_replace('\\' . $quote, $quote, $str); |
|
104 | + } |
|
105 | + |
|
106 | + $extra = ''; |
|
107 | + if ($parseUnicodeEscape) { |
|
108 | + $extra = '|u\{([0-9a-fA-F]+)\}'; |
|
109 | + } |
|
110 | + |
|
111 | + return preg_replace_callback( |
|
112 | + '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', |
|
113 | + function($matches) { |
|
114 | + $str = $matches[1]; |
|
115 | + |
|
116 | + if (isset(self::$replacements[$str])) { |
|
117 | + return self::$replacements[$str]; |
|
118 | + } elseif ('x' === $str[0] || 'X' === $str[0]) { |
|
119 | + return chr(hexdec(substr($str, 1))); |
|
120 | + } elseif ('u' === $str[0]) { |
|
121 | + return self::codePointToUtf8(hexdec($matches[2])); |
|
122 | + } else { |
|
123 | + return chr(octdec($str)); |
|
124 | + } |
|
125 | + }, |
|
126 | + $str |
|
127 | + ); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Converts a Unicode code point to its UTF-8 encoded representation. |
|
132 | + * |
|
133 | + * @param int $num Code point |
|
134 | + * |
|
135 | + * @return string UTF-8 representation of code point |
|
136 | + */ |
|
137 | + private static function codePointToUtf8(int $num) : string { |
|
138 | + if ($num <= 0x7F) { |
|
139 | + return chr($num); |
|
140 | + } |
|
141 | + if ($num <= 0x7FF) { |
|
142 | + return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); |
|
143 | + } |
|
144 | + if ($num <= 0xFFFF) { |
|
145 | + return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
146 | + } |
|
147 | + if ($num <= 0x1FFFFF) { |
|
148 | + return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) |
|
149 | + . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
150 | + } |
|
151 | + throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); |
|
152 | + } |
|
153 | + |
|
154 | + public function getType() : string { |
|
155 | + return 'Scalar_String'; |
|
156 | + } |
|
157 | 157 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public static function parseEscapeSequences(string $str, $quote, bool $parseUnicodeEscape = true) : string { |
102 | 102 | if (null !== $quote) { |
103 | - $str = str_replace('\\' . $quote, $quote, $str); |
|
103 | + $str = str_replace('\\'.$quote, $quote, $str); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | $extra = ''; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | } |
110 | 110 | |
111 | 111 | return preg_replace_callback( |
112 | - '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}' . $extra . ')~', |
|
112 | + '~\\\\([\\\\$nrtfve]|[xX][0-9a-fA-F]{1,2}|[0-7]{1,3}'.$extra.')~', |
|
113 | 113 | function($matches) { |
114 | 114 | $str = $matches[1]; |
115 | 115 | |
@@ -139,14 +139,14 @@ discard block |
||
139 | 139 | return chr($num); |
140 | 140 | } |
141 | 141 | if ($num <= 0x7FF) { |
142 | - return chr(($num>>6) + 0xC0) . chr(($num&0x3F) + 0x80); |
|
142 | + return chr(($num >> 6) + 0xC0).chr(($num&0x3F) + 0x80); |
|
143 | 143 | } |
144 | 144 | if ($num <= 0xFFFF) { |
145 | - return chr(($num>>12) + 0xE0) . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
145 | + return chr(($num >> 12) + 0xE0).chr((($num >> 6)&0x3F) + 0x80).chr(($num&0x3F) + 0x80); |
|
146 | 146 | } |
147 | 147 | if ($num <= 0x1FFFFF) { |
148 | - return chr(($num>>18) + 0xF0) . chr((($num>>12)&0x3F) + 0x80) |
|
149 | - . chr((($num>>6)&0x3F) + 0x80) . chr(($num&0x3F) + 0x80); |
|
148 | + return chr(($num >> 18) + 0xF0).chr((($num >> 12)&0x3F) + 0x80) |
|
149 | + . chr((($num >> 6)&0x3F) + 0x80).chr(($num&0x3F) + 0x80); |
|
150 | 150 | } |
151 | 151 | throw new Error('Invalid UTF-8 codepoint escape sequence: Codepoint too large'); |
152 | 152 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Error; |
6 | 6 | use PhpParser\Node\Scalar; |
7 | 7 | |
8 | -class String_ extends Scalar |
|
9 | -{ |
|
8 | +class String_ extends Scalar { |
|
10 | 9 | /* For use in "kind" attribute */ |
11 | 10 | const KIND_SINGLE_QUOTED = 1; |
12 | 11 | const KIND_DOUBLE_QUOTED = 2; |
@@ -6,23 +6,23 @@ |
||
6 | 6 | |
7 | 7 | abstract class MagicConst extends Scalar |
8 | 8 | { |
9 | - /** |
|
10 | - * Constructs a magic constant node. |
|
11 | - * |
|
12 | - * @param array $attributes Additional attributes |
|
13 | - */ |
|
14 | - public function __construct(array $attributes = []) { |
|
15 | - $this->attributes = $attributes; |
|
16 | - } |
|
9 | + /** |
|
10 | + * Constructs a magic constant node. |
|
11 | + * |
|
12 | + * @param array $attributes Additional attributes |
|
13 | + */ |
|
14 | + public function __construct(array $attributes = []) { |
|
15 | + $this->attributes = $attributes; |
|
16 | + } |
|
17 | 17 | |
18 | - public function getSubNodeNames() : array { |
|
19 | - return []; |
|
20 | - } |
|
18 | + public function getSubNodeNames() : array { |
|
19 | + return []; |
|
20 | + } |
|
21 | 21 | |
22 | - /** |
|
23 | - * Get name of magic constant. |
|
24 | - * |
|
25 | - * @return string Name of magic constant |
|
26 | - */ |
|
27 | - abstract public function getName() : string; |
|
22 | + /** |
|
23 | + * Get name of magic constant. |
|
24 | + * |
|
25 | + * @return string Name of magic constant |
|
26 | + */ |
|
27 | + abstract public function getName() : string; |
|
28 | 28 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar; |
6 | 6 | |
7 | -abstract class MagicConst extends Scalar |
|
8 | -{ |
|
7 | +abstract class MagicConst extends Scalar { |
|
9 | 8 | /** |
10 | 9 | * Constructs a magic constant node. |
11 | 10 | * |
@@ -7,25 +7,25 @@ |
||
7 | 7 | |
8 | 8 | class Encapsed extends Scalar |
9 | 9 | { |
10 | - /** @var Expr[] list of string parts */ |
|
11 | - public $parts; |
|
10 | + /** @var Expr[] list of string parts */ |
|
11 | + public $parts; |
|
12 | 12 | |
13 | - /** |
|
14 | - * Constructs an encapsed string node. |
|
15 | - * |
|
16 | - * @param Expr[] $parts Encaps list |
|
17 | - * @param array $attributes Additional attributes |
|
18 | - */ |
|
19 | - public function __construct(array $parts, array $attributes = []) { |
|
20 | - $this->attributes = $attributes; |
|
21 | - $this->parts = $parts; |
|
22 | - } |
|
13 | + /** |
|
14 | + * Constructs an encapsed string node. |
|
15 | + * |
|
16 | + * @param Expr[] $parts Encaps list |
|
17 | + * @param array $attributes Additional attributes |
|
18 | + */ |
|
19 | + public function __construct(array $parts, array $attributes = []) { |
|
20 | + $this->attributes = $attributes; |
|
21 | + $this->parts = $parts; |
|
22 | + } |
|
23 | 23 | |
24 | - public function getSubNodeNames() : array { |
|
25 | - return ['parts']; |
|
26 | - } |
|
24 | + public function getSubNodeNames() : array { |
|
25 | + return ['parts']; |
|
26 | + } |
|
27 | 27 | |
28 | - public function getType() : string { |
|
29 | - return 'Scalar_Encapsed'; |
|
30 | - } |
|
28 | + public function getType() : string { |
|
29 | + return 'Scalar_Encapsed'; |
|
30 | + } |
|
31 | 31 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Node\Expr; |
6 | 6 | use PhpParser\Node\Scalar; |
7 | 7 | |
8 | -class Encapsed extends Scalar |
|
9 | -{ |
|
8 | +class Encapsed extends Scalar { |
|
10 | 9 | /** @var Expr[] list of string parts */ |
11 | 10 | public $parts; |
12 | 11 |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class EncapsedStringPart extends Scalar |
8 | 8 | { |
9 | - /** @var string String value */ |
|
10 | - public $value; |
|
9 | + /** @var string String value */ |
|
10 | + public $value; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a node representing a string part of an encapsed string. |
|
14 | - * |
|
15 | - * @param string $value String value |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(string $value, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->value = $value; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a node representing a string part of an encapsed string. |
|
14 | + * |
|
15 | + * @param string $value String value |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(string $value, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->value = $value; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['value']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['value']; |
|
25 | + } |
|
26 | 26 | |
27 | - public function getType() : string { |
|
28 | - return 'Scalar_EncapsedStringPart'; |
|
29 | - } |
|
27 | + public function getType() : string { |
|
28 | + return 'Scalar_EncapsedStringPart'; |
|
29 | + } |
|
30 | 30 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar; |
6 | 6 | |
7 | -class EncapsedStringPart extends Scalar |
|
8 | -{ |
|
7 | +class EncapsedStringPart extends Scalar { |
|
9 | 8 | /** @var string String value */ |
10 | 9 | public $value; |
11 | 10 |
@@ -7,74 +7,74 @@ |
||
7 | 7 | |
8 | 8 | class LNumber extends Scalar |
9 | 9 | { |
10 | - /* For use in "kind" attribute */ |
|
11 | - const KIND_BIN = 2; |
|
12 | - const KIND_OCT = 8; |
|
13 | - const KIND_DEC = 10; |
|
14 | - const KIND_HEX = 16; |
|
10 | + /* For use in "kind" attribute */ |
|
11 | + const KIND_BIN = 2; |
|
12 | + const KIND_OCT = 8; |
|
13 | + const KIND_DEC = 10; |
|
14 | + const KIND_HEX = 16; |
|
15 | 15 | |
16 | - /** @var int Number value */ |
|
17 | - public $value; |
|
16 | + /** @var int Number value */ |
|
17 | + public $value; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructs an integer number scalar node. |
|
21 | - * |
|
22 | - * @param int $value Value of the number |
|
23 | - * @param array $attributes Additional attributes |
|
24 | - */ |
|
25 | - public function __construct(int $value, array $attributes = []) { |
|
26 | - $this->attributes = $attributes; |
|
27 | - $this->value = $value; |
|
28 | - } |
|
19 | + /** |
|
20 | + * Constructs an integer number scalar node. |
|
21 | + * |
|
22 | + * @param int $value Value of the number |
|
23 | + * @param array $attributes Additional attributes |
|
24 | + */ |
|
25 | + public function __construct(int $value, array $attributes = []) { |
|
26 | + $this->attributes = $attributes; |
|
27 | + $this->value = $value; |
|
28 | + } |
|
29 | 29 | |
30 | - public function getSubNodeNames() : array { |
|
31 | - return ['value']; |
|
32 | - } |
|
30 | + public function getSubNodeNames() : array { |
|
31 | + return ['value']; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructs an LNumber node from a string number literal. |
|
36 | - * |
|
37 | - * @param string $str String number literal (decimal, octal, hex or binary) |
|
38 | - * @param array $attributes Additional attributes |
|
39 | - * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) |
|
40 | - * |
|
41 | - * @return LNumber The constructed LNumber, including kind attribute |
|
42 | - */ |
|
43 | - public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { |
|
44 | - $attributes['rawValue'] = $str; |
|
34 | + /** |
|
35 | + * Constructs an LNumber node from a string number literal. |
|
36 | + * |
|
37 | + * @param string $str String number literal (decimal, octal, hex or binary) |
|
38 | + * @param array $attributes Additional attributes |
|
39 | + * @param bool $allowInvalidOctal Whether to allow invalid octal numbers (PHP 5) |
|
40 | + * |
|
41 | + * @return LNumber The constructed LNumber, including kind attribute |
|
42 | + */ |
|
43 | + public static function fromString(string $str, array $attributes = [], bool $allowInvalidOctal = false) : LNumber { |
|
44 | + $attributes['rawValue'] = $str; |
|
45 | 45 | |
46 | - $str = str_replace('_', '', $str); |
|
46 | + $str = str_replace('_', '', $str); |
|
47 | 47 | |
48 | - if ('0' !== $str[0] || '0' === $str) { |
|
49 | - $attributes['kind'] = LNumber::KIND_DEC; |
|
50 | - return new LNumber((int) $str, $attributes); |
|
51 | - } |
|
48 | + if ('0' !== $str[0] || '0' === $str) { |
|
49 | + $attributes['kind'] = LNumber::KIND_DEC; |
|
50 | + return new LNumber((int) $str, $attributes); |
|
51 | + } |
|
52 | 52 | |
53 | - if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | - $attributes['kind'] = LNumber::KIND_HEX; |
|
55 | - return new LNumber(hexdec($str), $attributes); |
|
56 | - } |
|
53 | + if ('x' === $str[1] || 'X' === $str[1]) { |
|
54 | + $attributes['kind'] = LNumber::KIND_HEX; |
|
55 | + return new LNumber(hexdec($str), $attributes); |
|
56 | + } |
|
57 | 57 | |
58 | - if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | - $attributes['kind'] = LNumber::KIND_BIN; |
|
60 | - return new LNumber(bindec($str), $attributes); |
|
61 | - } |
|
58 | + if ('b' === $str[1] || 'B' === $str[1]) { |
|
59 | + $attributes['kind'] = LNumber::KIND_BIN; |
|
60 | + return new LNumber(bindec($str), $attributes); |
|
61 | + } |
|
62 | 62 | |
63 | - if (!$allowInvalidOctal && strpbrk($str, '89')) { |
|
64 | - throw new Error('Invalid numeric literal', $attributes); |
|
65 | - } |
|
63 | + if (!$allowInvalidOctal && strpbrk($str, '89')) { |
|
64 | + throw new Error('Invalid numeric literal', $attributes); |
|
65 | + } |
|
66 | 66 | |
67 | - // Strip optional explicit octal prefix. |
|
68 | - if ('o' === $str[1] || 'O' === $str[1]) { |
|
69 | - $str = substr($str, 2); |
|
70 | - } |
|
67 | + // Strip optional explicit octal prefix. |
|
68 | + if ('o' === $str[1] || 'O' === $str[1]) { |
|
69 | + $str = substr($str, 2); |
|
70 | + } |
|
71 | 71 | |
72 | - // use intval instead of octdec to get proper cutting behavior with malformed numbers |
|
73 | - $attributes['kind'] = LNumber::KIND_OCT; |
|
74 | - return new LNumber(intval($str, 8), $attributes); |
|
75 | - } |
|
72 | + // use intval instead of octdec to get proper cutting behavior with malformed numbers |
|
73 | + $attributes['kind'] = LNumber::KIND_OCT; |
|
74 | + return new LNumber(intval($str, 8), $attributes); |
|
75 | + } |
|
76 | 76 | |
77 | - public function getType() : string { |
|
78 | - return 'Scalar_LNumber'; |
|
79 | - } |
|
77 | + public function getType() : string { |
|
78 | + return 'Scalar_LNumber'; |
|
79 | + } |
|
80 | 80 | } |
@@ -47,7 +47,7 @@ |
||
47 | 47 | |
48 | 48 | if ('0' !== $str[0] || '0' === $str) { |
49 | 49 | $attributes['kind'] = LNumber::KIND_DEC; |
50 | - return new LNumber((int) $str, $attributes); |
|
50 | + return new LNumber((int)$str, $attributes); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | if ('x' === $str[1] || 'X' === $str[1]) { |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Error; |
6 | 6 | use PhpParser\Node\Scalar; |
7 | 7 | |
8 | -class LNumber extends Scalar |
|
9 | -{ |
|
8 | +class LNumber extends Scalar { |
|
10 | 9 | /* For use in "kind" attribute */ |
11 | 10 | const KIND_BIN = 2; |
12 | 11 | const KIND_OCT = 8; |
@@ -6,11 +6,11 @@ |
||
6 | 6 | |
7 | 7 | class Function_ extends MagicConst |
8 | 8 | { |
9 | - public function getName() : string { |
|
10 | - return '__FUNCTION__'; |
|
11 | - } |
|
9 | + public function getName() : string { |
|
10 | + return '__FUNCTION__'; |
|
11 | + } |
|
12 | 12 | |
13 | - public function getType() : string { |
|
14 | - return 'Scalar_MagicConst_Function'; |
|
15 | - } |
|
13 | + public function getType() : string { |
|
14 | + return 'Scalar_MagicConst_Function'; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar\MagicConst; |
6 | 6 | |
7 | -class Function_ extends MagicConst |
|
8 | -{ |
|
7 | +class Function_ extends MagicConst { |
|
9 | 8 | public function getName() : string { |
10 | 9 | return '__FUNCTION__'; |
11 | 10 | } |
@@ -6,11 +6,11 @@ |
||
6 | 6 | |
7 | 7 | class File extends MagicConst |
8 | 8 | { |
9 | - public function getName() : string { |
|
10 | - return '__FILE__'; |
|
11 | - } |
|
9 | + public function getName() : string { |
|
10 | + return '__FILE__'; |
|
11 | + } |
|
12 | 12 | |
13 | - public function getType() : string { |
|
14 | - return 'Scalar_MagicConst_File'; |
|
15 | - } |
|
13 | + public function getType() : string { |
|
14 | + return 'Scalar_MagicConst_File'; |
|
15 | + } |
|
16 | 16 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\Node\Scalar\MagicConst; |
6 | 6 | |
7 | -class File extends MagicConst |
|
8 | -{ |
|
7 | +class File extends MagicConst { |
|
9 | 8 | public function getName() : string { |
10 | 9 | return '__FILE__'; |
11 | 10 | } |