@@ -9,278 +9,278 @@ |
||
9 | 9 | */ |
10 | 10 | class TokenStream |
11 | 11 | { |
12 | - /** @var array Tokens (in token_get_all format) */ |
|
13 | - private $tokens; |
|
14 | - /** @var int[] Map from position to indentation */ |
|
15 | - private $indentMap; |
|
12 | + /** @var array Tokens (in token_get_all format) */ |
|
13 | + private $tokens; |
|
14 | + /** @var int[] Map from position to indentation */ |
|
15 | + private $indentMap; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Create token stream instance. |
|
19 | - * |
|
20 | - * @param array $tokens Tokens in token_get_all() format |
|
21 | - */ |
|
22 | - public function __construct(array $tokens) { |
|
23 | - $this->tokens = $tokens; |
|
24 | - $this->indentMap = $this->calcIndentMap(); |
|
25 | - } |
|
17 | + /** |
|
18 | + * Create token stream instance. |
|
19 | + * |
|
20 | + * @param array $tokens Tokens in token_get_all() format |
|
21 | + */ |
|
22 | + public function __construct(array $tokens) { |
|
23 | + $this->tokens = $tokens; |
|
24 | + $this->indentMap = $this->calcIndentMap(); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * Whether the given position is immediately surrounded by parenthesis. |
|
29 | - * |
|
30 | - * @param int $startPos Start position |
|
31 | - * @param int $endPos End position |
|
32 | - * |
|
33 | - * @return bool |
|
34 | - */ |
|
35 | - public function haveParens(int $startPos, int $endPos) : bool { |
|
36 | - return $this->haveTokenImmediatelyBefore($startPos, '(') |
|
37 | - && $this->haveTokenImmediatelyAfter($endPos, ')'); |
|
38 | - } |
|
27 | + /** |
|
28 | + * Whether the given position is immediately surrounded by parenthesis. |
|
29 | + * |
|
30 | + * @param int $startPos Start position |
|
31 | + * @param int $endPos End position |
|
32 | + * |
|
33 | + * @return bool |
|
34 | + */ |
|
35 | + public function haveParens(int $startPos, int $endPos) : bool { |
|
36 | + return $this->haveTokenImmediatelyBefore($startPos, '(') |
|
37 | + && $this->haveTokenImmediatelyAfter($endPos, ')'); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Whether the given position is immediately surrounded by braces. |
|
42 | - * |
|
43 | - * @param int $startPos Start position |
|
44 | - * @param int $endPos End position |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public function haveBraces(int $startPos, int $endPos) : bool { |
|
49 | - return ($this->haveTokenImmediatelyBefore($startPos, '{') |
|
50 | - || $this->haveTokenImmediatelyBefore($startPos, T_CURLY_OPEN)) |
|
51 | - && $this->haveTokenImmediatelyAfter($endPos, '}'); |
|
52 | - } |
|
40 | + /** |
|
41 | + * Whether the given position is immediately surrounded by braces. |
|
42 | + * |
|
43 | + * @param int $startPos Start position |
|
44 | + * @param int $endPos End position |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public function haveBraces(int $startPos, int $endPos) : bool { |
|
49 | + return ($this->haveTokenImmediatelyBefore($startPos, '{') |
|
50 | + || $this->haveTokenImmediatelyBefore($startPos, T_CURLY_OPEN)) |
|
51 | + && $this->haveTokenImmediatelyAfter($endPos, '}'); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Check whether the position is directly preceded by a certain token type. |
|
56 | - * |
|
57 | - * During this check whitespace and comments are skipped. |
|
58 | - * |
|
59 | - * @param int $pos Position before which the token should occur |
|
60 | - * @param int|string $expectedTokenType Token to check for |
|
61 | - * |
|
62 | - * @return bool Whether the expected token was found |
|
63 | - */ |
|
64 | - public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType) : bool { |
|
65 | - $tokens = $this->tokens; |
|
66 | - $pos--; |
|
67 | - for (; $pos >= 0; $pos--) { |
|
68 | - $tokenType = $tokens[$pos][0]; |
|
69 | - if ($tokenType === $expectedTokenType) { |
|
70 | - return true; |
|
71 | - } |
|
72 | - if ($tokenType !== \T_WHITESPACE |
|
73 | - && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) { |
|
74 | - break; |
|
75 | - } |
|
76 | - } |
|
77 | - return false; |
|
78 | - } |
|
54 | + /** |
|
55 | + * Check whether the position is directly preceded by a certain token type. |
|
56 | + * |
|
57 | + * During this check whitespace and comments are skipped. |
|
58 | + * |
|
59 | + * @param int $pos Position before which the token should occur |
|
60 | + * @param int|string $expectedTokenType Token to check for |
|
61 | + * |
|
62 | + * @return bool Whether the expected token was found |
|
63 | + */ |
|
64 | + public function haveTokenImmediatelyBefore(int $pos, $expectedTokenType) : bool { |
|
65 | + $tokens = $this->tokens; |
|
66 | + $pos--; |
|
67 | + for (; $pos >= 0; $pos--) { |
|
68 | + $tokenType = $tokens[$pos][0]; |
|
69 | + if ($tokenType === $expectedTokenType) { |
|
70 | + return true; |
|
71 | + } |
|
72 | + if ($tokenType !== \T_WHITESPACE |
|
73 | + && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) { |
|
74 | + break; |
|
75 | + } |
|
76 | + } |
|
77 | + return false; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Check whether the position is directly followed by a certain token type. |
|
82 | - * |
|
83 | - * During this check whitespace and comments are skipped. |
|
84 | - * |
|
85 | - * @param int $pos Position after which the token should occur |
|
86 | - * @param int|string $expectedTokenType Token to check for |
|
87 | - * |
|
88 | - * @return bool Whether the expected token was found |
|
89 | - */ |
|
90 | - public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType) : bool { |
|
91 | - $tokens = $this->tokens; |
|
92 | - $pos++; |
|
93 | - for (; $pos < \count($tokens); $pos++) { |
|
94 | - $tokenType = $tokens[$pos][0]; |
|
95 | - if ($tokenType === $expectedTokenType) { |
|
96 | - return true; |
|
97 | - } |
|
98 | - if ($tokenType !== \T_WHITESPACE |
|
99 | - && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) { |
|
100 | - break; |
|
101 | - } |
|
102 | - } |
|
103 | - return false; |
|
104 | - } |
|
80 | + /** |
|
81 | + * Check whether the position is directly followed by a certain token type. |
|
82 | + * |
|
83 | + * During this check whitespace and comments are skipped. |
|
84 | + * |
|
85 | + * @param int $pos Position after which the token should occur |
|
86 | + * @param int|string $expectedTokenType Token to check for |
|
87 | + * |
|
88 | + * @return bool Whether the expected token was found |
|
89 | + */ |
|
90 | + public function haveTokenImmediatelyAfter(int $pos, $expectedTokenType) : bool { |
|
91 | + $tokens = $this->tokens; |
|
92 | + $pos++; |
|
93 | + for (; $pos < \count($tokens); $pos++) { |
|
94 | + $tokenType = $tokens[$pos][0]; |
|
95 | + if ($tokenType === $expectedTokenType) { |
|
96 | + return true; |
|
97 | + } |
|
98 | + if ($tokenType !== \T_WHITESPACE |
|
99 | + && $tokenType !== \T_COMMENT && $tokenType !== \T_DOC_COMMENT) { |
|
100 | + break; |
|
101 | + } |
|
102 | + } |
|
103 | + return false; |
|
104 | + } |
|
105 | 105 | |
106 | - public function skipLeft(int $pos, $skipTokenType) { |
|
107 | - $tokens = $this->tokens; |
|
106 | + public function skipLeft(int $pos, $skipTokenType) { |
|
107 | + $tokens = $this->tokens; |
|
108 | 108 | |
109 | - $pos = $this->skipLeftWhitespace($pos); |
|
110 | - if ($skipTokenType === \T_WHITESPACE) { |
|
111 | - return $pos; |
|
112 | - } |
|
109 | + $pos = $this->skipLeftWhitespace($pos); |
|
110 | + if ($skipTokenType === \T_WHITESPACE) { |
|
111 | + return $pos; |
|
112 | + } |
|
113 | 113 | |
114 | - if ($tokens[$pos][0] !== $skipTokenType) { |
|
115 | - // Shouldn't happen. The skip token MUST be there |
|
116 | - throw new \Exception('Encountered unexpected token'); |
|
117 | - } |
|
118 | - $pos--; |
|
114 | + if ($tokens[$pos][0] !== $skipTokenType) { |
|
115 | + // Shouldn't happen. The skip token MUST be there |
|
116 | + throw new \Exception('Encountered unexpected token'); |
|
117 | + } |
|
118 | + $pos--; |
|
119 | 119 | |
120 | - return $this->skipLeftWhitespace($pos); |
|
121 | - } |
|
120 | + return $this->skipLeftWhitespace($pos); |
|
121 | + } |
|
122 | 122 | |
123 | - public function skipRight(int $pos, $skipTokenType) { |
|
124 | - $tokens = $this->tokens; |
|
123 | + public function skipRight(int $pos, $skipTokenType) { |
|
124 | + $tokens = $this->tokens; |
|
125 | 125 | |
126 | - $pos = $this->skipRightWhitespace($pos); |
|
127 | - if ($skipTokenType === \T_WHITESPACE) { |
|
128 | - return $pos; |
|
129 | - } |
|
126 | + $pos = $this->skipRightWhitespace($pos); |
|
127 | + if ($skipTokenType === \T_WHITESPACE) { |
|
128 | + return $pos; |
|
129 | + } |
|
130 | 130 | |
131 | - if ($tokens[$pos][0] !== $skipTokenType) { |
|
132 | - // Shouldn't happen. The skip token MUST be there |
|
133 | - throw new \Exception('Encountered unexpected token'); |
|
134 | - } |
|
135 | - $pos++; |
|
131 | + if ($tokens[$pos][0] !== $skipTokenType) { |
|
132 | + // Shouldn't happen. The skip token MUST be there |
|
133 | + throw new \Exception('Encountered unexpected token'); |
|
134 | + } |
|
135 | + $pos++; |
|
136 | 136 | |
137 | - return $this->skipRightWhitespace($pos); |
|
138 | - } |
|
137 | + return $this->skipRightWhitespace($pos); |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Return first non-whitespace token position smaller or equal to passed position. |
|
142 | - * |
|
143 | - * @param int $pos Token position |
|
144 | - * @return int Non-whitespace token position |
|
145 | - */ |
|
146 | - public function skipLeftWhitespace(int $pos) { |
|
147 | - $tokens = $this->tokens; |
|
148 | - for (; $pos >= 0; $pos--) { |
|
149 | - $type = $tokens[$pos][0]; |
|
150 | - if ($type !== \T_WHITESPACE && $type !== \T_COMMENT && $type !== \T_DOC_COMMENT) { |
|
151 | - break; |
|
152 | - } |
|
153 | - } |
|
154 | - return $pos; |
|
155 | - } |
|
140 | + /** |
|
141 | + * Return first non-whitespace token position smaller or equal to passed position. |
|
142 | + * |
|
143 | + * @param int $pos Token position |
|
144 | + * @return int Non-whitespace token position |
|
145 | + */ |
|
146 | + public function skipLeftWhitespace(int $pos) { |
|
147 | + $tokens = $this->tokens; |
|
148 | + for (; $pos >= 0; $pos--) { |
|
149 | + $type = $tokens[$pos][0]; |
|
150 | + if ($type !== \T_WHITESPACE && $type !== \T_COMMENT && $type !== \T_DOC_COMMENT) { |
|
151 | + break; |
|
152 | + } |
|
153 | + } |
|
154 | + return $pos; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Return first non-whitespace position greater or equal to passed position. |
|
159 | - * |
|
160 | - * @param int $pos Token position |
|
161 | - * @return int Non-whitespace token position |
|
162 | - */ |
|
163 | - public function skipRightWhitespace(int $pos) { |
|
164 | - $tokens = $this->tokens; |
|
165 | - for ($count = \count($tokens); $pos < $count; $pos++) { |
|
166 | - $type = $tokens[$pos][0]; |
|
167 | - if ($type !== \T_WHITESPACE && $type !== \T_COMMENT && $type !== \T_DOC_COMMENT) { |
|
168 | - break; |
|
169 | - } |
|
170 | - } |
|
171 | - return $pos; |
|
172 | - } |
|
157 | + /** |
|
158 | + * Return first non-whitespace position greater or equal to passed position. |
|
159 | + * |
|
160 | + * @param int $pos Token position |
|
161 | + * @return int Non-whitespace token position |
|
162 | + */ |
|
163 | + public function skipRightWhitespace(int $pos) { |
|
164 | + $tokens = $this->tokens; |
|
165 | + for ($count = \count($tokens); $pos < $count; $pos++) { |
|
166 | + $type = $tokens[$pos][0]; |
|
167 | + if ($type !== \T_WHITESPACE && $type !== \T_COMMENT && $type !== \T_DOC_COMMENT) { |
|
168 | + break; |
|
169 | + } |
|
170 | + } |
|
171 | + return $pos; |
|
172 | + } |
|
173 | 173 | |
174 | - public function findRight(int $pos, $findTokenType) { |
|
175 | - $tokens = $this->tokens; |
|
176 | - for ($count = \count($tokens); $pos < $count; $pos++) { |
|
177 | - $type = $tokens[$pos][0]; |
|
178 | - if ($type === $findTokenType) { |
|
179 | - return $pos; |
|
180 | - } |
|
181 | - } |
|
182 | - return -1; |
|
183 | - } |
|
174 | + public function findRight(int $pos, $findTokenType) { |
|
175 | + $tokens = $this->tokens; |
|
176 | + for ($count = \count($tokens); $pos < $count; $pos++) { |
|
177 | + $type = $tokens[$pos][0]; |
|
178 | + if ($type === $findTokenType) { |
|
179 | + return $pos; |
|
180 | + } |
|
181 | + } |
|
182 | + return -1; |
|
183 | + } |
|
184 | 184 | |
185 | - /** |
|
186 | - * Whether the given position range contains a certain token type. |
|
187 | - * |
|
188 | - * @param int $startPos Starting position (inclusive) |
|
189 | - * @param int $endPos Ending position (exclusive) |
|
190 | - * @param int|string $tokenType Token type to look for |
|
191 | - * @return bool Whether the token occurs in the given range |
|
192 | - */ |
|
193 | - public function haveTokenInRange(int $startPos, int $endPos, $tokenType) { |
|
194 | - $tokens = $this->tokens; |
|
195 | - for ($pos = $startPos; $pos < $endPos; $pos++) { |
|
196 | - if ($tokens[$pos][0] === $tokenType) { |
|
197 | - return true; |
|
198 | - } |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
185 | + /** |
|
186 | + * Whether the given position range contains a certain token type. |
|
187 | + * |
|
188 | + * @param int $startPos Starting position (inclusive) |
|
189 | + * @param int $endPos Ending position (exclusive) |
|
190 | + * @param int|string $tokenType Token type to look for |
|
191 | + * @return bool Whether the token occurs in the given range |
|
192 | + */ |
|
193 | + public function haveTokenInRange(int $startPos, int $endPos, $tokenType) { |
|
194 | + $tokens = $this->tokens; |
|
195 | + for ($pos = $startPos; $pos < $endPos; $pos++) { |
|
196 | + if ($tokens[$pos][0] === $tokenType) { |
|
197 | + return true; |
|
198 | + } |
|
199 | + } |
|
200 | + return false; |
|
201 | + } |
|
202 | 202 | |
203 | - public function haveBracesInRange(int $startPos, int $endPos) { |
|
204 | - return $this->haveTokenInRange($startPos, $endPos, '{') |
|
205 | - || $this->haveTokenInRange($startPos, $endPos, T_CURLY_OPEN) |
|
206 | - || $this->haveTokenInRange($startPos, $endPos, '}'); |
|
207 | - } |
|
203 | + public function haveBracesInRange(int $startPos, int $endPos) { |
|
204 | + return $this->haveTokenInRange($startPos, $endPos, '{') |
|
205 | + || $this->haveTokenInRange($startPos, $endPos, T_CURLY_OPEN) |
|
206 | + || $this->haveTokenInRange($startPos, $endPos, '}'); |
|
207 | + } |
|
208 | 208 | |
209 | - public function haveTagInRange(int $startPos, int $endPos): bool { |
|
210 | - return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG) |
|
211 | - || $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG); |
|
212 | - } |
|
209 | + public function haveTagInRange(int $startPos, int $endPos): bool { |
|
210 | + return $this->haveTokenInRange($startPos, $endPos, \T_OPEN_TAG) |
|
211 | + || $this->haveTokenInRange($startPos, $endPos, \T_CLOSE_TAG); |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Get indentation before token position. |
|
216 | - * |
|
217 | - * @param int $pos Token position |
|
218 | - * |
|
219 | - * @return int Indentation depth (in spaces) |
|
220 | - */ |
|
221 | - public function getIndentationBefore(int $pos) : int { |
|
222 | - return $this->indentMap[$pos]; |
|
223 | - } |
|
214 | + /** |
|
215 | + * Get indentation before token position. |
|
216 | + * |
|
217 | + * @param int $pos Token position |
|
218 | + * |
|
219 | + * @return int Indentation depth (in spaces) |
|
220 | + */ |
|
221 | + public function getIndentationBefore(int $pos) : int { |
|
222 | + return $this->indentMap[$pos]; |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * Get the code corresponding to a token offset range, optionally adjusted for indentation. |
|
227 | - * |
|
228 | - * @param int $from Token start position (inclusive) |
|
229 | - * @param int $to Token end position (exclusive) |
|
230 | - * @param int $indent By how much the code should be indented (can be negative as well) |
|
231 | - * |
|
232 | - * @return string Code corresponding to token range, adjusted for indentation |
|
233 | - */ |
|
234 | - public function getTokenCode(int $from, int $to, int $indent) : string { |
|
235 | - $tokens = $this->tokens; |
|
236 | - $result = ''; |
|
237 | - for ($pos = $from; $pos < $to; $pos++) { |
|
238 | - $token = $tokens[$pos]; |
|
239 | - if (\is_array($token)) { |
|
240 | - $type = $token[0]; |
|
241 | - $content = $token[1]; |
|
242 | - if ($type === \T_CONSTANT_ENCAPSED_STRING || $type === \T_ENCAPSED_AND_WHITESPACE) { |
|
243 | - $result .= $content; |
|
244 | - } else { |
|
245 | - // TODO Handle non-space indentation |
|
246 | - if ($indent < 0) { |
|
247 | - $result .= str_replace("\n" . str_repeat(" ", -$indent), "\n", $content); |
|
248 | - } elseif ($indent > 0) { |
|
249 | - $result .= str_replace("\n", "\n" . str_repeat(" ", $indent), $content); |
|
250 | - } else { |
|
251 | - $result .= $content; |
|
252 | - } |
|
253 | - } |
|
254 | - } else { |
|
255 | - $result .= $token; |
|
256 | - } |
|
257 | - } |
|
258 | - return $result; |
|
259 | - } |
|
225 | + /** |
|
226 | + * Get the code corresponding to a token offset range, optionally adjusted for indentation. |
|
227 | + * |
|
228 | + * @param int $from Token start position (inclusive) |
|
229 | + * @param int $to Token end position (exclusive) |
|
230 | + * @param int $indent By how much the code should be indented (can be negative as well) |
|
231 | + * |
|
232 | + * @return string Code corresponding to token range, adjusted for indentation |
|
233 | + */ |
|
234 | + public function getTokenCode(int $from, int $to, int $indent) : string { |
|
235 | + $tokens = $this->tokens; |
|
236 | + $result = ''; |
|
237 | + for ($pos = $from; $pos < $to; $pos++) { |
|
238 | + $token = $tokens[$pos]; |
|
239 | + if (\is_array($token)) { |
|
240 | + $type = $token[0]; |
|
241 | + $content = $token[1]; |
|
242 | + if ($type === \T_CONSTANT_ENCAPSED_STRING || $type === \T_ENCAPSED_AND_WHITESPACE) { |
|
243 | + $result .= $content; |
|
244 | + } else { |
|
245 | + // TODO Handle non-space indentation |
|
246 | + if ($indent < 0) { |
|
247 | + $result .= str_replace("\n" . str_repeat(" ", -$indent), "\n", $content); |
|
248 | + } elseif ($indent > 0) { |
|
249 | + $result .= str_replace("\n", "\n" . str_repeat(" ", $indent), $content); |
|
250 | + } else { |
|
251 | + $result .= $content; |
|
252 | + } |
|
253 | + } |
|
254 | + } else { |
|
255 | + $result .= $token; |
|
256 | + } |
|
257 | + } |
|
258 | + return $result; |
|
259 | + } |
|
260 | 260 | |
261 | - /** |
|
262 | - * Precalculate the indentation at every token position. |
|
263 | - * |
|
264 | - * @return int[] Token position to indentation map |
|
265 | - */ |
|
266 | - private function calcIndentMap() { |
|
267 | - $indentMap = []; |
|
268 | - $indent = 0; |
|
269 | - foreach ($this->tokens as $token) { |
|
270 | - $indentMap[] = $indent; |
|
261 | + /** |
|
262 | + * Precalculate the indentation at every token position. |
|
263 | + * |
|
264 | + * @return int[] Token position to indentation map |
|
265 | + */ |
|
266 | + private function calcIndentMap() { |
|
267 | + $indentMap = []; |
|
268 | + $indent = 0; |
|
269 | + foreach ($this->tokens as $token) { |
|
270 | + $indentMap[] = $indent; |
|
271 | 271 | |
272 | - if ($token[0] === \T_WHITESPACE) { |
|
273 | - $content = $token[1]; |
|
274 | - $newlinePos = \strrpos($content, "\n"); |
|
275 | - if (false !== $newlinePos) { |
|
276 | - $indent = \strlen($content) - $newlinePos - 1; |
|
277 | - } |
|
278 | - } |
|
279 | - } |
|
272 | + if ($token[0] === \T_WHITESPACE) { |
|
273 | + $content = $token[1]; |
|
274 | + $newlinePos = \strrpos($content, "\n"); |
|
275 | + if (false !== $newlinePos) { |
|
276 | + $indent = \strlen($content) - $newlinePos - 1; |
|
277 | + } |
|
278 | + } |
|
279 | + } |
|
280 | 280 | |
281 | - // Add a sentinel for one past end of the file |
|
282 | - $indentMap[] = $indent; |
|
281 | + // Add a sentinel for one past end of the file |
|
282 | + $indentMap[] = $indent; |
|
283 | 283 | |
284 | - return $indentMap; |
|
285 | - } |
|
284 | + return $indentMap; |
|
285 | + } |
|
286 | 286 | } |
@@ -244,9 +244,9 @@ |
||
244 | 244 | } else { |
245 | 245 | // TODO Handle non-space indentation |
246 | 246 | if ($indent < 0) { |
247 | - $result .= str_replace("\n" . str_repeat(" ", -$indent), "\n", $content); |
|
247 | + $result .= str_replace("\n".str_repeat(" ", -$indent), "\n", $content); |
|
248 | 248 | } elseif ($indent > 0) { |
249 | - $result .= str_replace("\n", "\n" . str_repeat(" ", $indent), $content); |
|
249 | + $result .= str_replace("\n", "\n".str_repeat(" ", $indent), $content); |
|
250 | 250 | } else { |
251 | 251 | $result .= $content; |
252 | 252 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | * |
8 | 8 | * @internal |
9 | 9 | */ |
10 | -class TokenStream |
|
11 | -{ |
|
10 | +class TokenStream { |
|
12 | 11 | /** @var array Tokens (in token_get_all format) */ |
13 | 12 | private $tokens; |
14 | 13 | /** @var int[] Map from position to indentation */ |
@@ -7,21 +7,21 @@ |
||
7 | 7 | */ |
8 | 8 | class DiffElem |
9 | 9 | { |
10 | - const TYPE_KEEP = 0; |
|
11 | - const TYPE_REMOVE = 1; |
|
12 | - const TYPE_ADD = 2; |
|
13 | - const TYPE_REPLACE = 3; |
|
10 | + const TYPE_KEEP = 0; |
|
11 | + const TYPE_REMOVE = 1; |
|
12 | + const TYPE_ADD = 2; |
|
13 | + const TYPE_REPLACE = 3; |
|
14 | 14 | |
15 | - /** @var int One of the TYPE_* constants */ |
|
16 | - public $type; |
|
17 | - /** @var mixed Is null for add operations */ |
|
18 | - public $old; |
|
19 | - /** @var mixed Is null for remove operations */ |
|
20 | - public $new; |
|
15 | + /** @var int One of the TYPE_* constants */ |
|
16 | + public $type; |
|
17 | + /** @var mixed Is null for add operations */ |
|
18 | + public $old; |
|
19 | + /** @var mixed Is null for remove operations */ |
|
20 | + public $new; |
|
21 | 21 | |
22 | - public function __construct(int $type, $old, $new) { |
|
23 | - $this->type = $type; |
|
24 | - $this->old = $old; |
|
25 | - $this->new = $new; |
|
26 | - } |
|
22 | + public function __construct(int $type, $old, $new) { |
|
23 | + $this->type = $type; |
|
24 | + $this->old = $old; |
|
25 | + $this->new = $new; |
|
26 | + } |
|
27 | 27 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | /** |
6 | 6 | * @internal |
7 | 7 | */ |
8 | -class DiffElem |
|
9 | -{ |
|
8 | +class DiffElem { |
|
10 | 9 | const TYPE_KEEP = 0; |
11 | 10 | const TYPE_REMOVE = 1; |
12 | 11 | const TYPE_ADD = 2; |
@@ -7,40 +7,40 @@ |
||
7 | 7 | |
8 | 8 | class Arg extends NodeAbstract |
9 | 9 | { |
10 | - /** @var Identifier|null Parameter name (for named parameters) */ |
|
11 | - public $name; |
|
12 | - /** @var Expr Value to pass */ |
|
13 | - public $value; |
|
14 | - /** @var bool Whether to pass by ref */ |
|
15 | - public $byRef; |
|
16 | - /** @var bool Whether to unpack the argument */ |
|
17 | - public $unpack; |
|
10 | + /** @var Identifier|null Parameter name (for named parameters) */ |
|
11 | + public $name; |
|
12 | + /** @var Expr Value to pass */ |
|
13 | + public $value; |
|
14 | + /** @var bool Whether to pass by ref */ |
|
15 | + public $byRef; |
|
16 | + /** @var bool Whether to unpack the argument */ |
|
17 | + public $unpack; |
|
18 | 18 | |
19 | - /** |
|
20 | - * Constructs a function call argument node. |
|
21 | - * |
|
22 | - * @param Expr $value Value to pass |
|
23 | - * @param bool $byRef Whether to pass by ref |
|
24 | - * @param bool $unpack Whether to unpack the argument |
|
25 | - * @param array $attributes Additional attributes |
|
26 | - * @param Identifier|null $name Parameter name (for named parameters) |
|
27 | - */ |
|
28 | - public function __construct( |
|
29 | - Expr $value, bool $byRef = false, bool $unpack = false, array $attributes = [], |
|
30 | - ?Identifier $name = null |
|
31 | - ) { |
|
32 | - $this->attributes = $attributes; |
|
33 | - $this->name = $name; |
|
34 | - $this->value = $value; |
|
35 | - $this->byRef = $byRef; |
|
36 | - $this->unpack = $unpack; |
|
37 | - } |
|
19 | + /** |
|
20 | + * Constructs a function call argument node. |
|
21 | + * |
|
22 | + * @param Expr $value Value to pass |
|
23 | + * @param bool $byRef Whether to pass by ref |
|
24 | + * @param bool $unpack Whether to unpack the argument |
|
25 | + * @param array $attributes Additional attributes |
|
26 | + * @param Identifier|null $name Parameter name (for named parameters) |
|
27 | + */ |
|
28 | + public function __construct( |
|
29 | + Expr $value, bool $byRef = false, bool $unpack = false, array $attributes = [], |
|
30 | + ?Identifier $name = null |
|
31 | + ) { |
|
32 | + $this->attributes = $attributes; |
|
33 | + $this->name = $name; |
|
34 | + $this->value = $value; |
|
35 | + $this->byRef = $byRef; |
|
36 | + $this->unpack = $unpack; |
|
37 | + } |
|
38 | 38 | |
39 | - public function getSubNodeNames() : array { |
|
40 | - return ['name', 'value', 'byRef', 'unpack']; |
|
41 | - } |
|
39 | + public function getSubNodeNames() : array { |
|
40 | + return ['name', 'value', 'byRef', 'unpack']; |
|
41 | + } |
|
42 | 42 | |
43 | - public function getType() : string { |
|
44 | - return 'Arg'; |
|
45 | - } |
|
43 | + public function getType() : string { |
|
44 | + return 'Arg'; |
|
45 | + } |
|
46 | 46 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | use PhpParser\Node\VariadicPlaceholder; |
6 | 6 | use PhpParser\NodeAbstract; |
7 | 7 | |
8 | -class Arg extends NodeAbstract |
|
9 | -{ |
|
8 | +class Arg extends NodeAbstract { |
|
10 | 9 | /** @var Identifier|null Parameter name (for named parameters) */ |
11 | 10 | public $name; |
12 | 11 | /** @var Expr Value to pass */ |
@@ -6,32 +6,32 @@ |
||
6 | 6 | |
7 | 7 | class Const_ extends NodeAbstract |
8 | 8 | { |
9 | - /** @var Identifier Name */ |
|
10 | - public $name; |
|
11 | - /** @var Expr Value */ |
|
12 | - public $value; |
|
9 | + /** @var Identifier Name */ |
|
10 | + public $name; |
|
11 | + /** @var Expr Value */ |
|
12 | + public $value; |
|
13 | 13 | |
14 | - /** @var Name|null Namespaced name (if using NameResolver) */ |
|
15 | - public $namespacedName; |
|
14 | + /** @var Name|null Namespaced name (if using NameResolver) */ |
|
15 | + public $namespacedName; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Constructs a const node for use in class const and const statements. |
|
19 | - * |
|
20 | - * @param string|Identifier $name Name |
|
21 | - * @param Expr $value Value |
|
22 | - * @param array $attributes Additional attributes |
|
23 | - */ |
|
24 | - public function __construct($name, Expr $value, array $attributes = []) { |
|
25 | - $this->attributes = $attributes; |
|
26 | - $this->name = \is_string($name) ? new Identifier($name) : $name; |
|
27 | - $this->value = $value; |
|
28 | - } |
|
17 | + /** |
|
18 | + * Constructs a const node for use in class const and const statements. |
|
19 | + * |
|
20 | + * @param string|Identifier $name Name |
|
21 | + * @param Expr $value Value |
|
22 | + * @param array $attributes Additional attributes |
|
23 | + */ |
|
24 | + public function __construct($name, Expr $value, array $attributes = []) { |
|
25 | + $this->attributes = $attributes; |
|
26 | + $this->name = \is_string($name) ? new Identifier($name) : $name; |
|
27 | + $this->value = $value; |
|
28 | + } |
|
29 | 29 | |
30 | - public function getSubNodeNames() : array { |
|
31 | - return ['name', 'value']; |
|
32 | - } |
|
30 | + public function getSubNodeNames() : array { |
|
31 | + return ['name', 'value']; |
|
32 | + } |
|
33 | 33 | |
34 | - public function getType() : string { |
|
35 | - return 'Const'; |
|
36 | - } |
|
34 | + public function getType() : string { |
|
35 | + return 'Const'; |
|
36 | + } |
|
37 | 37 | } |
@@ -4,8 +4,7 @@ |
||
4 | 4 | |
5 | 5 | use PhpParser\NodeAbstract; |
6 | 6 | |
7 | -class Const_ extends NodeAbstract |
|
8 | -{ |
|
7 | +class Const_ extends NodeAbstract { |
|
9 | 8 | /** @var Identifier Name */ |
10 | 9 | public $name; |
11 | 10 | /** @var Expr Value */ |
@@ -4,25 +4,25 @@ |
||
4 | 4 | |
5 | 5 | class NullableType extends ComplexType |
6 | 6 | { |
7 | - /** @var Identifier|Name Type */ |
|
8 | - public $type; |
|
7 | + /** @var Identifier|Name Type */ |
|
8 | + public $type; |
|
9 | 9 | |
10 | - /** |
|
11 | - * Constructs a nullable type (wrapping another type). |
|
12 | - * |
|
13 | - * @param string|Identifier|Name $type Type |
|
14 | - * @param array $attributes Additional attributes |
|
15 | - */ |
|
16 | - public function __construct($type, array $attributes = []) { |
|
17 | - $this->attributes = $attributes; |
|
18 | - $this->type = \is_string($type) ? new Identifier($type) : $type; |
|
19 | - } |
|
10 | + /** |
|
11 | + * Constructs a nullable type (wrapping another type). |
|
12 | + * |
|
13 | + * @param string|Identifier|Name $type Type |
|
14 | + * @param array $attributes Additional attributes |
|
15 | + */ |
|
16 | + public function __construct($type, array $attributes = []) { |
|
17 | + $this->attributes = $attributes; |
|
18 | + $this->type = \is_string($type) ? new Identifier($type) : $type; |
|
19 | + } |
|
20 | 20 | |
21 | - public function getSubNodeNames() : array { |
|
22 | - return ['type']; |
|
23 | - } |
|
21 | + public function getSubNodeNames() : array { |
|
22 | + return ['type']; |
|
23 | + } |
|
24 | 24 | |
25 | - public function getType() : string { |
|
26 | - return 'NullableType'; |
|
27 | - } |
|
25 | + public function getType() : string { |
|
26 | + return 'NullableType'; |
|
27 | + } |
|
28 | 28 | } |
@@ -2,8 +2,7 @@ |
||
2 | 2 | |
3 | 3 | namespace PhpParser\Node; |
4 | 4 | |
5 | -class NullableType extends ComplexType |
|
6 | -{ |
|
5 | +class NullableType extends ComplexType { |
|
7 | 6 | /** @var Identifier|Name Type */ |
8 | 7 | public $type; |
9 | 8 |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class Break_ extends Node\Stmt |
8 | 8 | { |
9 | - /** @var null|Node\Expr Number of loops to break */ |
|
10 | - public $num; |
|
9 | + /** @var null|Node\Expr Number of loops to break */ |
|
10 | + public $num; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a break node. |
|
14 | - * |
|
15 | - * @param null|Node\Expr $num Number of loops to break |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(?Node\Expr $num = null, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->num = $num; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a break node. |
|
14 | + * |
|
15 | + * @param null|Node\Expr $num Number of loops to break |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(?Node\Expr $num = null, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->num = $num; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['num']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['num']; |
|
25 | + } |
|
26 | 26 | |
27 | - public function getType() : string { |
|
28 | - return 'Stmt_Break'; |
|
29 | - } |
|
27 | + public function getType() : string { |
|
28 | + return 'Stmt_Break'; |
|
29 | + } |
|
30 | 30 | } |
@@ -7,71 +7,71 @@ |
||
7 | 7 | |
8 | 8 | class Function_ extends Node\Stmt implements FunctionLike |
9 | 9 | { |
10 | - /** @var bool Whether function returns by reference */ |
|
11 | - public $byRef; |
|
12 | - /** @var Node\Identifier Name */ |
|
13 | - public $name; |
|
14 | - /** @var Node\Param[] Parameters */ |
|
15 | - public $params; |
|
16 | - /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ |
|
17 | - public $returnType; |
|
18 | - /** @var Node\Stmt[] Statements */ |
|
19 | - public $stmts; |
|
20 | - /** @var Node\AttributeGroup[] PHP attribute groups */ |
|
21 | - public $attrGroups; |
|
10 | + /** @var bool Whether function returns by reference */ |
|
11 | + public $byRef; |
|
12 | + /** @var Node\Identifier Name */ |
|
13 | + public $name; |
|
14 | + /** @var Node\Param[] Parameters */ |
|
15 | + public $params; |
|
16 | + /** @var null|Node\Identifier|Node\Name|Node\ComplexType Return type */ |
|
17 | + public $returnType; |
|
18 | + /** @var Node\Stmt[] Statements */ |
|
19 | + public $stmts; |
|
20 | + /** @var Node\AttributeGroup[] PHP attribute groups */ |
|
21 | + public $attrGroups; |
|
22 | 22 | |
23 | - /** @var Node\Name|null Namespaced name (if using NameResolver) */ |
|
24 | - public $namespacedName; |
|
23 | + /** @var Node\Name|null Namespaced name (if using NameResolver) */ |
|
24 | + public $namespacedName; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructs a function node. |
|
28 | - * |
|
29 | - * @param string|Node\Identifier $name Name |
|
30 | - * @param array $subNodes Array of the following optional subnodes: |
|
31 | - * 'byRef' => false : Whether to return by reference |
|
32 | - * 'params' => array(): Parameters |
|
33 | - * 'returnType' => null : Return type |
|
34 | - * 'stmts' => array(): Statements |
|
35 | - * 'attrGroups' => array(): PHP attribute groups |
|
36 | - * @param array $attributes Additional attributes |
|
37 | - */ |
|
38 | - public function __construct($name, array $subNodes = [], array $attributes = []) { |
|
39 | - $this->attributes = $attributes; |
|
40 | - $this->byRef = $subNodes['byRef'] ?? false; |
|
41 | - $this->name = \is_string($name) ? new Node\Identifier($name) : $name; |
|
42 | - $this->params = $subNodes['params'] ?? []; |
|
43 | - $returnType = $subNodes['returnType'] ?? null; |
|
44 | - $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; |
|
45 | - $this->stmts = $subNodes['stmts'] ?? []; |
|
46 | - $this->attrGroups = $subNodes['attrGroups'] ?? []; |
|
47 | - } |
|
26 | + /** |
|
27 | + * Constructs a function node. |
|
28 | + * |
|
29 | + * @param string|Node\Identifier $name Name |
|
30 | + * @param array $subNodes Array of the following optional subnodes: |
|
31 | + * 'byRef' => false : Whether to return by reference |
|
32 | + * 'params' => array(): Parameters |
|
33 | + * 'returnType' => null : Return type |
|
34 | + * 'stmts' => array(): Statements |
|
35 | + * 'attrGroups' => array(): PHP attribute groups |
|
36 | + * @param array $attributes Additional attributes |
|
37 | + */ |
|
38 | + public function __construct($name, array $subNodes = [], array $attributes = []) { |
|
39 | + $this->attributes = $attributes; |
|
40 | + $this->byRef = $subNodes['byRef'] ?? false; |
|
41 | + $this->name = \is_string($name) ? new Node\Identifier($name) : $name; |
|
42 | + $this->params = $subNodes['params'] ?? []; |
|
43 | + $returnType = $subNodes['returnType'] ?? null; |
|
44 | + $this->returnType = \is_string($returnType) ? new Node\Identifier($returnType) : $returnType; |
|
45 | + $this->stmts = $subNodes['stmts'] ?? []; |
|
46 | + $this->attrGroups = $subNodes['attrGroups'] ?? []; |
|
47 | + } |
|
48 | 48 | |
49 | - public function getSubNodeNames() : array { |
|
50 | - return ['attrGroups', 'byRef', 'name', 'params', 'returnType', 'stmts']; |
|
51 | - } |
|
49 | + public function getSubNodeNames() : array { |
|
50 | + return ['attrGroups', 'byRef', 'name', 'params', 'returnType', 'stmts']; |
|
51 | + } |
|
52 | 52 | |
53 | - public function returnsByRef() : bool { |
|
54 | - return $this->byRef; |
|
55 | - } |
|
53 | + public function returnsByRef() : bool { |
|
54 | + return $this->byRef; |
|
55 | + } |
|
56 | 56 | |
57 | - public function getParams() : array { |
|
58 | - return $this->params; |
|
59 | - } |
|
57 | + public function getParams() : array { |
|
58 | + return $this->params; |
|
59 | + } |
|
60 | 60 | |
61 | - public function getReturnType() { |
|
62 | - return $this->returnType; |
|
63 | - } |
|
61 | + public function getReturnType() { |
|
62 | + return $this->returnType; |
|
63 | + } |
|
64 | 64 | |
65 | - public function getAttrGroups() : array { |
|
66 | - return $this->attrGroups; |
|
67 | - } |
|
65 | + public function getAttrGroups() : array { |
|
66 | + return $this->attrGroups; |
|
67 | + } |
|
68 | 68 | |
69 | - /** @return Node\Stmt[] */ |
|
70 | - public function getStmts() : array { |
|
71 | - return $this->stmts; |
|
72 | - } |
|
69 | + /** @return Node\Stmt[] */ |
|
70 | + public function getStmts() : array { |
|
71 | + return $this->stmts; |
|
72 | + } |
|
73 | 73 | |
74 | - public function getType() : string { |
|
75 | - return 'Stmt_Function'; |
|
76 | - } |
|
74 | + public function getType() : string { |
|
75 | + return 'Stmt_Function'; |
|
76 | + } |
|
77 | 77 | } |
@@ -6,25 +6,25 @@ |
||
6 | 6 | |
7 | 7 | class Continue_ extends Node\Stmt |
8 | 8 | { |
9 | - /** @var null|Node\Expr Number of loops to continue */ |
|
10 | - public $num; |
|
9 | + /** @var null|Node\Expr Number of loops to continue */ |
|
10 | + public $num; |
|
11 | 11 | |
12 | - /** |
|
13 | - * Constructs a continue node. |
|
14 | - * |
|
15 | - * @param null|Node\Expr $num Number of loops to continue |
|
16 | - * @param array $attributes Additional attributes |
|
17 | - */ |
|
18 | - public function __construct(?Node\Expr $num = null, array $attributes = []) { |
|
19 | - $this->attributes = $attributes; |
|
20 | - $this->num = $num; |
|
21 | - } |
|
12 | + /** |
|
13 | + * Constructs a continue node. |
|
14 | + * |
|
15 | + * @param null|Node\Expr $num Number of loops to continue |
|
16 | + * @param array $attributes Additional attributes |
|
17 | + */ |
|
18 | + public function __construct(?Node\Expr $num = null, array $attributes = []) { |
|
19 | + $this->attributes = $attributes; |
|
20 | + $this->num = $num; |
|
21 | + } |
|
22 | 22 | |
23 | - public function getSubNodeNames() : array { |
|
24 | - return ['num']; |
|
25 | - } |
|
23 | + public function getSubNodeNames() : array { |
|
24 | + return ['num']; |
|
25 | + } |
|
26 | 26 | |
27 | - public function getType() : string { |
|
28 | - return 'Stmt_Continue'; |
|
29 | - } |
|
27 | + public function getType() : string { |
|
28 | + return 'Stmt_Continue'; |
|
29 | + } |
|
30 | 30 | } |
@@ -6,104 +6,104 @@ |
||
6 | 6 | |
7 | 7 | abstract class ClassLike extends Node\Stmt |
8 | 8 | { |
9 | - /** @var Node\Identifier|null Name */ |
|
10 | - public $name; |
|
11 | - /** @var Node\Stmt[] Statements */ |
|
12 | - public $stmts; |
|
13 | - /** @var Node\AttributeGroup[] PHP attribute groups */ |
|
14 | - public $attrGroups; |
|
9 | + /** @var Node\Identifier|null Name */ |
|
10 | + public $name; |
|
11 | + /** @var Node\Stmt[] Statements */ |
|
12 | + public $stmts; |
|
13 | + /** @var Node\AttributeGroup[] PHP attribute groups */ |
|
14 | + public $attrGroups; |
|
15 | 15 | |
16 | - /** @var Node\Name|null Namespaced name (if using NameResolver) */ |
|
17 | - public $namespacedName; |
|
16 | + /** @var Node\Name|null Namespaced name (if using NameResolver) */ |
|
17 | + public $namespacedName; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @return TraitUse[] |
|
21 | - */ |
|
22 | - public function getTraitUses() : array { |
|
23 | - $traitUses = []; |
|
24 | - foreach ($this->stmts as $stmt) { |
|
25 | - if ($stmt instanceof TraitUse) { |
|
26 | - $traitUses[] = $stmt; |
|
27 | - } |
|
28 | - } |
|
29 | - return $traitUses; |
|
30 | - } |
|
19 | + /** |
|
20 | + * @return TraitUse[] |
|
21 | + */ |
|
22 | + public function getTraitUses() : array { |
|
23 | + $traitUses = []; |
|
24 | + foreach ($this->stmts as $stmt) { |
|
25 | + if ($stmt instanceof TraitUse) { |
|
26 | + $traitUses[] = $stmt; |
|
27 | + } |
|
28 | + } |
|
29 | + return $traitUses; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return ClassConst[] |
|
34 | - */ |
|
35 | - public function getConstants() : array { |
|
36 | - $constants = []; |
|
37 | - foreach ($this->stmts as $stmt) { |
|
38 | - if ($stmt instanceof ClassConst) { |
|
39 | - $constants[] = $stmt; |
|
40 | - } |
|
41 | - } |
|
42 | - return $constants; |
|
43 | - } |
|
32 | + /** |
|
33 | + * @return ClassConst[] |
|
34 | + */ |
|
35 | + public function getConstants() : array { |
|
36 | + $constants = []; |
|
37 | + foreach ($this->stmts as $stmt) { |
|
38 | + if ($stmt instanceof ClassConst) { |
|
39 | + $constants[] = $stmt; |
|
40 | + } |
|
41 | + } |
|
42 | + return $constants; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @return Property[] |
|
47 | - */ |
|
48 | - public function getProperties() : array { |
|
49 | - $properties = []; |
|
50 | - foreach ($this->stmts as $stmt) { |
|
51 | - if ($stmt instanceof Property) { |
|
52 | - $properties[] = $stmt; |
|
53 | - } |
|
54 | - } |
|
55 | - return $properties; |
|
56 | - } |
|
45 | + /** |
|
46 | + * @return Property[] |
|
47 | + */ |
|
48 | + public function getProperties() : array { |
|
49 | + $properties = []; |
|
50 | + foreach ($this->stmts as $stmt) { |
|
51 | + if ($stmt instanceof Property) { |
|
52 | + $properties[] = $stmt; |
|
53 | + } |
|
54 | + } |
|
55 | + return $properties; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Gets property with the given name defined directly in this class/interface/trait. |
|
60 | - * |
|
61 | - * @param string $name Name of the property |
|
62 | - * |
|
63 | - * @return Property|null Property node or null if the property does not exist |
|
64 | - */ |
|
65 | - public function getProperty(string $name) { |
|
66 | - foreach ($this->stmts as $stmt) { |
|
67 | - if ($stmt instanceof Property) { |
|
68 | - foreach ($stmt->props as $prop) { |
|
69 | - if ($prop instanceof PropertyProperty && $name === $prop->name->toString()) { |
|
70 | - return $stmt; |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - return null; |
|
76 | - } |
|
58 | + /** |
|
59 | + * Gets property with the given name defined directly in this class/interface/trait. |
|
60 | + * |
|
61 | + * @param string $name Name of the property |
|
62 | + * |
|
63 | + * @return Property|null Property node or null if the property does not exist |
|
64 | + */ |
|
65 | + public function getProperty(string $name) { |
|
66 | + foreach ($this->stmts as $stmt) { |
|
67 | + if ($stmt instanceof Property) { |
|
68 | + foreach ($stmt->props as $prop) { |
|
69 | + if ($prop instanceof PropertyProperty && $name === $prop->name->toString()) { |
|
70 | + return $stmt; |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + return null; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Gets all methods defined directly in this class/interface/trait |
|
80 | - * |
|
81 | - * @return ClassMethod[] |
|
82 | - */ |
|
83 | - public function getMethods() : array { |
|
84 | - $methods = []; |
|
85 | - foreach ($this->stmts as $stmt) { |
|
86 | - if ($stmt instanceof ClassMethod) { |
|
87 | - $methods[] = $stmt; |
|
88 | - } |
|
89 | - } |
|
90 | - return $methods; |
|
91 | - } |
|
78 | + /** |
|
79 | + * Gets all methods defined directly in this class/interface/trait |
|
80 | + * |
|
81 | + * @return ClassMethod[] |
|
82 | + */ |
|
83 | + public function getMethods() : array { |
|
84 | + $methods = []; |
|
85 | + foreach ($this->stmts as $stmt) { |
|
86 | + if ($stmt instanceof ClassMethod) { |
|
87 | + $methods[] = $stmt; |
|
88 | + } |
|
89 | + } |
|
90 | + return $methods; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Gets method with the given name defined directly in this class/interface/trait. |
|
95 | - * |
|
96 | - * @param string $name Name of the method (compared case-insensitively) |
|
97 | - * |
|
98 | - * @return ClassMethod|null Method node or null if the method does not exist |
|
99 | - */ |
|
100 | - public function getMethod(string $name) { |
|
101 | - $lowerName = strtolower($name); |
|
102 | - foreach ($this->stmts as $stmt) { |
|
103 | - if ($stmt instanceof ClassMethod && $lowerName === $stmt->name->toLowerString()) { |
|
104 | - return $stmt; |
|
105 | - } |
|
106 | - } |
|
107 | - return null; |
|
108 | - } |
|
93 | + /** |
|
94 | + * Gets method with the given name defined directly in this class/interface/trait. |
|
95 | + * |
|
96 | + * @param string $name Name of the method (compared case-insensitively) |
|
97 | + * |
|
98 | + * @return ClassMethod|null Method node or null if the method does not exist |
|
99 | + */ |
|
100 | + public function getMethod(string $name) { |
|
101 | + $lowerName = strtolower($name); |
|
102 | + foreach ($this->stmts as $stmt) { |
|
103 | + if ($stmt instanceof ClassMethod && $lowerName === $stmt->name->toLowerString()) { |
|
104 | + return $stmt; |
|
105 | + } |
|
106 | + } |
|
107 | + return null; |
|
108 | + } |
|
109 | 109 | } |