Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php @ 13:5fb285c0d0e3
Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've
been lucky to get away with this so far, as we don't support self-registration
which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5
was vulnerable to.
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:33:26 +0100 |
parents | 7a779792577d |
children | c2387f117808 |
comparison
equal
deleted
inserted
replaced
12:7a779792577d | 13:5fb285c0d0e3 |
---|---|
1 <?php | 1 <?php declare(strict_types=1); |
2 | 2 |
3 namespace PhpParser\PrettyPrinter; | 3 namespace PhpParser\PrettyPrinter; |
4 | 4 |
5 use PhpParser\Node; | 5 use PhpParser\Node; |
6 use PhpParser\Node\Expr; | 6 use PhpParser\Node\Expr; |
16 class Standard extends PrettyPrinterAbstract | 16 class Standard extends PrettyPrinterAbstract |
17 { | 17 { |
18 // Special nodes | 18 // Special nodes |
19 | 19 |
20 protected function pParam(Node\Param $node) { | 20 protected function pParam(Node\Param $node) { |
21 return ($node->type ? $this->pType($node->type) . ' ' : '') | 21 return ($node->type ? $this->p($node->type) . ' ' : '') |
22 . ($node->byRef ? '&' : '') | 22 . ($node->byRef ? '&' : '') |
23 . ($node->variadic ? '...' : '') | 23 . ($node->variadic ? '...' : '') |
24 . '$' . $node->name | 24 . $this->p($node->var) |
25 . ($node->default ? ' = ' . $this->p($node->default) : ''); | 25 . ($node->default ? ' = ' . $this->p($node->default) : ''); |
26 } | 26 } |
27 | 27 |
28 protected function pArg(Node\Arg $node) { | 28 protected function pArg(Node\Arg $node) { |
29 return ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); | 29 return ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value); |
32 protected function pConst(Node\Const_ $node) { | 32 protected function pConst(Node\Const_ $node) { |
33 return $node->name . ' = ' . $this->p($node->value); | 33 return $node->name . ' = ' . $this->p($node->value); |
34 } | 34 } |
35 | 35 |
36 protected function pNullableType(Node\NullableType $node) { | 36 protected function pNullableType(Node\NullableType $node) { |
37 return '?' . $this->pType($node->type); | 37 return '?' . $this->p($node->type); |
38 } | |
39 | |
40 protected function pIdentifier(Node\Identifier $node) { | |
41 return $node->name; | |
42 } | |
43 | |
44 protected function pVarLikeIdentifier(Node\VarLikeIdentifier $node) { | |
45 return '$' . $node->name; | |
38 } | 46 } |
39 | 47 |
40 // Names | 48 // Names |
41 | 49 |
42 protected function pName(Name $node) { | 50 protected function pName(Name $node) { |
92 switch ($kind) { | 100 switch ($kind) { |
93 case Scalar\String_::KIND_NOWDOC: | 101 case Scalar\String_::KIND_NOWDOC: |
94 $label = $node->getAttribute('docLabel'); | 102 $label = $node->getAttribute('docLabel'); |
95 if ($label && !$this->containsEndLabel($node->value, $label)) { | 103 if ($label && !$this->containsEndLabel($node->value, $label)) { |
96 if ($node->value === '') { | 104 if ($node->value === '') { |
97 return $this->pNoIndent("<<<'$label'\n$label") . $this->docStringEndToken; | 105 return "<<<'$label'\n$label" . $this->docStringEndToken; |
98 } | 106 } |
99 | 107 |
100 return $this->pNoIndent("<<<'$label'\n$node->value\n$label") | 108 return "<<<'$label'\n$node->value\n$label" |
101 . $this->docStringEndToken; | 109 . $this->docStringEndToken; |
102 } | 110 } |
103 /* break missing intentionally */ | 111 /* break missing intentionally */ |
104 case Scalar\String_::KIND_SINGLE_QUOTED: | 112 case Scalar\String_::KIND_SINGLE_QUOTED: |
105 return '\'' . $this->pNoIndent(addcslashes($node->value, '\'\\')) . '\''; | 113 return $this->pSingleQuotedString($node->value); |
106 case Scalar\String_::KIND_HEREDOC: | 114 case Scalar\String_::KIND_HEREDOC: |
107 $label = $node->getAttribute('docLabel'); | 115 $label = $node->getAttribute('docLabel'); |
108 if ($label && !$this->containsEndLabel($node->value, $label)) { | 116 if ($label && !$this->containsEndLabel($node->value, $label)) { |
109 if ($node->value === '') { | 117 if ($node->value === '') { |
110 return $this->pNoIndent("<<<$label\n$label") . $this->docStringEndToken; | 118 return "<<<$label\n$label" . $this->docStringEndToken; |
111 } | 119 } |
112 | 120 |
113 $escaped = $this->escapeString($node->value, null); | 121 $escaped = $this->escapeString($node->value, null); |
114 return $this->pNoIndent("<<<$label\n" . $escaped ."\n$label") | 122 return "<<<$label\n" . $escaped . "\n$label" |
115 . $this->docStringEndToken; | 123 . $this->docStringEndToken; |
116 } | 124 } |
117 /* break missing intentionally */ | 125 /* break missing intentionally */ |
118 case Scalar\String_::KIND_DOUBLE_QUOTED: | 126 case Scalar\String_::KIND_DOUBLE_QUOTED: |
119 return '"' . $this->escapeString($node->value, '"') . '"'; | 127 return '"' . $this->escapeString($node->value, '"') . '"'; |
127 if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) { | 135 if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) { |
128 if (count($node->parts) === 1 | 136 if (count($node->parts) === 1 |
129 && $node->parts[0] instanceof Scalar\EncapsedStringPart | 137 && $node->parts[0] instanceof Scalar\EncapsedStringPart |
130 && $node->parts[0]->value === '' | 138 && $node->parts[0]->value === '' |
131 ) { | 139 ) { |
132 return $this->pNoIndent("<<<$label\n$label") . $this->docStringEndToken; | 140 return "<<<$label\n$label" . $this->docStringEndToken; |
133 } | 141 } |
134 | 142 |
135 return $this->pNoIndent( | 143 return "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label" |
136 "<<<$label\n" . $this->pEncapsList($node->parts, null) . "\n$label" | 144 . $this->docStringEndToken; |
137 ) . $this->docStringEndToken; | |
138 } | 145 } |
139 } | 146 } |
140 return '"' . $this->pEncapsList($node->parts, '"') . '"'; | 147 return '"' . $this->pEncapsList($node->parts, '"') . '"'; |
141 } | 148 } |
142 | 149 |
192 } | 199 } |
193 | 200 |
194 // Assignments | 201 // Assignments |
195 | 202 |
196 protected function pExpr_Assign(Expr\Assign $node) { | 203 protected function pExpr_Assign(Expr\Assign $node) { |
197 return $this->pInfixOp('Expr_Assign', $node->var, ' = ', $node->expr); | 204 return $this->pInfixOp(Expr\Assign::class, $node->var, ' = ', $node->expr); |
198 } | 205 } |
199 | 206 |
200 protected function pExpr_AssignRef(Expr\AssignRef $node) { | 207 protected function pExpr_AssignRef(Expr\AssignRef $node) { |
201 return $this->pInfixOp('Expr_AssignRef', $node->var, ' =& ', $node->expr); | 208 return $this->pInfixOp(Expr\AssignRef::class, $node->var, ' =& ', $node->expr); |
202 } | 209 } |
203 | 210 |
204 protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) { | 211 protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) { |
205 return $this->pInfixOp('Expr_AssignOp_Plus', $node->var, ' += ', $node->expr); | 212 return $this->pInfixOp(AssignOp\Plus::class, $node->var, ' += ', $node->expr); |
206 } | 213 } |
207 | 214 |
208 protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) { | 215 protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) { |
209 return $this->pInfixOp('Expr_AssignOp_Minus', $node->var, ' -= ', $node->expr); | 216 return $this->pInfixOp(AssignOp\Minus::class, $node->var, ' -= ', $node->expr); |
210 } | 217 } |
211 | 218 |
212 protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) { | 219 protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) { |
213 return $this->pInfixOp('Expr_AssignOp_Mul', $node->var, ' *= ', $node->expr); | 220 return $this->pInfixOp(AssignOp\Mul::class, $node->var, ' *= ', $node->expr); |
214 } | 221 } |
215 | 222 |
216 protected function pExpr_AssignOp_Div(AssignOp\Div $node) { | 223 protected function pExpr_AssignOp_Div(AssignOp\Div $node) { |
217 return $this->pInfixOp('Expr_AssignOp_Div', $node->var, ' /= ', $node->expr); | 224 return $this->pInfixOp(AssignOp\Div::class, $node->var, ' /= ', $node->expr); |
218 } | 225 } |
219 | 226 |
220 protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) { | 227 protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) { |
221 return $this->pInfixOp('Expr_AssignOp_Concat', $node->var, ' .= ', $node->expr); | 228 return $this->pInfixOp(AssignOp\Concat::class, $node->var, ' .= ', $node->expr); |
222 } | 229 } |
223 | 230 |
224 protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) { | 231 protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) { |
225 return $this->pInfixOp('Expr_AssignOp_Mod', $node->var, ' %= ', $node->expr); | 232 return $this->pInfixOp(AssignOp\Mod::class, $node->var, ' %= ', $node->expr); |
226 } | 233 } |
227 | 234 |
228 protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) { | 235 protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) { |
229 return $this->pInfixOp('Expr_AssignOp_BitwiseAnd', $node->var, ' &= ', $node->expr); | 236 return $this->pInfixOp(AssignOp\BitwiseAnd::class, $node->var, ' &= ', $node->expr); |
230 } | 237 } |
231 | 238 |
232 protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) { | 239 protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) { |
233 return $this->pInfixOp('Expr_AssignOp_BitwiseOr', $node->var, ' |= ', $node->expr); | 240 return $this->pInfixOp(AssignOp\BitwiseOr::class, $node->var, ' |= ', $node->expr); |
234 } | 241 } |
235 | 242 |
236 protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) { | 243 protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) { |
237 return $this->pInfixOp('Expr_AssignOp_BitwiseXor', $node->var, ' ^= ', $node->expr); | 244 return $this->pInfixOp(AssignOp\BitwiseXor::class, $node->var, ' ^= ', $node->expr); |
238 } | 245 } |
239 | 246 |
240 protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) { | 247 protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) { |
241 return $this->pInfixOp('Expr_AssignOp_ShiftLeft', $node->var, ' <<= ', $node->expr); | 248 return $this->pInfixOp(AssignOp\ShiftLeft::class, $node->var, ' <<= ', $node->expr); |
242 } | 249 } |
243 | 250 |
244 protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) { | 251 protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) { |
245 return $this->pInfixOp('Expr_AssignOp_ShiftRight', $node->var, ' >>= ', $node->expr); | 252 return $this->pInfixOp(AssignOp\ShiftRight::class, $node->var, ' >>= ', $node->expr); |
246 } | 253 } |
247 | 254 |
248 protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) { | 255 protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) { |
249 return $this->pInfixOp('Expr_AssignOp_Pow', $node->var, ' **= ', $node->expr); | 256 return $this->pInfixOp(AssignOp\Pow::class, $node->var, ' **= ', $node->expr); |
250 } | 257 } |
251 | 258 |
252 // Binary expressions | 259 // Binary expressions |
253 | 260 |
254 protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) { | 261 protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) { |
255 return $this->pInfixOp('Expr_BinaryOp_Plus', $node->left, ' + ', $node->right); | 262 return $this->pInfixOp(BinaryOp\Plus::class, $node->left, ' + ', $node->right); |
256 } | 263 } |
257 | 264 |
258 protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) { | 265 protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) { |
259 return $this->pInfixOp('Expr_BinaryOp_Minus', $node->left, ' - ', $node->right); | 266 return $this->pInfixOp(BinaryOp\Minus::class, $node->left, ' - ', $node->right); |
260 } | 267 } |
261 | 268 |
262 protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) { | 269 protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) { |
263 return $this->pInfixOp('Expr_BinaryOp_Mul', $node->left, ' * ', $node->right); | 270 return $this->pInfixOp(BinaryOp\Mul::class, $node->left, ' * ', $node->right); |
264 } | 271 } |
265 | 272 |
266 protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) { | 273 protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) { |
267 return $this->pInfixOp('Expr_BinaryOp_Div', $node->left, ' / ', $node->right); | 274 return $this->pInfixOp(BinaryOp\Div::class, $node->left, ' / ', $node->right); |
268 } | 275 } |
269 | 276 |
270 protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) { | 277 protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) { |
271 return $this->pInfixOp('Expr_BinaryOp_Concat', $node->left, ' . ', $node->right); | 278 return $this->pInfixOp(BinaryOp\Concat::class, $node->left, ' . ', $node->right); |
272 } | 279 } |
273 | 280 |
274 protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) { | 281 protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) { |
275 return $this->pInfixOp('Expr_BinaryOp_Mod', $node->left, ' % ', $node->right); | 282 return $this->pInfixOp(BinaryOp\Mod::class, $node->left, ' % ', $node->right); |
276 } | 283 } |
277 | 284 |
278 protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) { | 285 protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) { |
279 return $this->pInfixOp('Expr_BinaryOp_BooleanAnd', $node->left, ' && ', $node->right); | 286 return $this->pInfixOp(BinaryOp\BooleanAnd::class, $node->left, ' && ', $node->right); |
280 } | 287 } |
281 | 288 |
282 protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) { | 289 protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) { |
283 return $this->pInfixOp('Expr_BinaryOp_BooleanOr', $node->left, ' || ', $node->right); | 290 return $this->pInfixOp(BinaryOp\BooleanOr::class, $node->left, ' || ', $node->right); |
284 } | 291 } |
285 | 292 |
286 protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) { | 293 protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) { |
287 return $this->pInfixOp('Expr_BinaryOp_BitwiseAnd', $node->left, ' & ', $node->right); | 294 return $this->pInfixOp(BinaryOp\BitwiseAnd::class, $node->left, ' & ', $node->right); |
288 } | 295 } |
289 | 296 |
290 protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) { | 297 protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) { |
291 return $this->pInfixOp('Expr_BinaryOp_BitwiseOr', $node->left, ' | ', $node->right); | 298 return $this->pInfixOp(BinaryOp\BitwiseOr::class, $node->left, ' | ', $node->right); |
292 } | 299 } |
293 | 300 |
294 protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) { | 301 protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) { |
295 return $this->pInfixOp('Expr_BinaryOp_BitwiseXor', $node->left, ' ^ ', $node->right); | 302 return $this->pInfixOp(BinaryOp\BitwiseXor::class, $node->left, ' ^ ', $node->right); |
296 } | 303 } |
297 | 304 |
298 protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) { | 305 protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) { |
299 return $this->pInfixOp('Expr_BinaryOp_ShiftLeft', $node->left, ' << ', $node->right); | 306 return $this->pInfixOp(BinaryOp\ShiftLeft::class, $node->left, ' << ', $node->right); |
300 } | 307 } |
301 | 308 |
302 protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) { | 309 protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) { |
303 return $this->pInfixOp('Expr_BinaryOp_ShiftRight', $node->left, ' >> ', $node->right); | 310 return $this->pInfixOp(BinaryOp\ShiftRight::class, $node->left, ' >> ', $node->right); |
304 } | 311 } |
305 | 312 |
306 protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) { | 313 protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) { |
307 return $this->pInfixOp('Expr_BinaryOp_Pow', $node->left, ' ** ', $node->right); | 314 return $this->pInfixOp(BinaryOp\Pow::class, $node->left, ' ** ', $node->right); |
308 } | 315 } |
309 | 316 |
310 protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) { | 317 protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) { |
311 return $this->pInfixOp('Expr_BinaryOp_LogicalAnd', $node->left, ' and ', $node->right); | 318 return $this->pInfixOp(BinaryOp\LogicalAnd::class, $node->left, ' and ', $node->right); |
312 } | 319 } |
313 | 320 |
314 protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) { | 321 protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) { |
315 return $this->pInfixOp('Expr_BinaryOp_LogicalOr', $node->left, ' or ', $node->right); | 322 return $this->pInfixOp(BinaryOp\LogicalOr::class, $node->left, ' or ', $node->right); |
316 } | 323 } |
317 | 324 |
318 protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) { | 325 protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) { |
319 return $this->pInfixOp('Expr_BinaryOp_LogicalXor', $node->left, ' xor ', $node->right); | 326 return $this->pInfixOp(BinaryOp\LogicalXor::class, $node->left, ' xor ', $node->right); |
320 } | 327 } |
321 | 328 |
322 protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) { | 329 protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) { |
323 return $this->pInfixOp('Expr_BinaryOp_Equal', $node->left, ' == ', $node->right); | 330 return $this->pInfixOp(BinaryOp\Equal::class, $node->left, ' == ', $node->right); |
324 } | 331 } |
325 | 332 |
326 protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) { | 333 protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) { |
327 return $this->pInfixOp('Expr_BinaryOp_NotEqual', $node->left, ' != ', $node->right); | 334 return $this->pInfixOp(BinaryOp\NotEqual::class, $node->left, ' != ', $node->right); |
328 } | 335 } |
329 | 336 |
330 protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) { | 337 protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) { |
331 return $this->pInfixOp('Expr_BinaryOp_Identical', $node->left, ' === ', $node->right); | 338 return $this->pInfixOp(BinaryOp\Identical::class, $node->left, ' === ', $node->right); |
332 } | 339 } |
333 | 340 |
334 protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) { | 341 protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) { |
335 return $this->pInfixOp('Expr_BinaryOp_NotIdentical', $node->left, ' !== ', $node->right); | 342 return $this->pInfixOp(BinaryOp\NotIdentical::class, $node->left, ' !== ', $node->right); |
336 } | 343 } |
337 | 344 |
338 protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) { | 345 protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) { |
339 return $this->pInfixOp('Expr_BinaryOp_Spaceship', $node->left, ' <=> ', $node->right); | 346 return $this->pInfixOp(BinaryOp\Spaceship::class, $node->left, ' <=> ', $node->right); |
340 } | 347 } |
341 | 348 |
342 protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) { | 349 protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) { |
343 return $this->pInfixOp('Expr_BinaryOp_Greater', $node->left, ' > ', $node->right); | 350 return $this->pInfixOp(BinaryOp\Greater::class, $node->left, ' > ', $node->right); |
344 } | 351 } |
345 | 352 |
346 protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) { | 353 protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) { |
347 return $this->pInfixOp('Expr_BinaryOp_GreaterOrEqual', $node->left, ' >= ', $node->right); | 354 return $this->pInfixOp(BinaryOp\GreaterOrEqual::class, $node->left, ' >= ', $node->right); |
348 } | 355 } |
349 | 356 |
350 protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) { | 357 protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) { |
351 return $this->pInfixOp('Expr_BinaryOp_Smaller', $node->left, ' < ', $node->right); | 358 return $this->pInfixOp(BinaryOp\Smaller::class, $node->left, ' < ', $node->right); |
352 } | 359 } |
353 | 360 |
354 protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) { | 361 protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) { |
355 return $this->pInfixOp('Expr_BinaryOp_SmallerOrEqual', $node->left, ' <= ', $node->right); | 362 return $this->pInfixOp(BinaryOp\SmallerOrEqual::class, $node->left, ' <= ', $node->right); |
356 } | 363 } |
357 | 364 |
358 protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) { | 365 protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) { |
359 return $this->pInfixOp('Expr_BinaryOp_Coalesce', $node->left, ' ?? ', $node->right); | 366 return $this->pInfixOp(BinaryOp\Coalesce::class, $node->left, ' ?? ', $node->right); |
360 } | 367 } |
361 | 368 |
362 protected function pExpr_Instanceof(Expr\Instanceof_ $node) { | 369 protected function pExpr_Instanceof(Expr\Instanceof_ $node) { |
363 return $this->pInfixOp('Expr_Instanceof', $node->expr, ' instanceof ', $node->class); | 370 return $this->pInfixOp(Expr\Instanceof_::class, $node->expr, ' instanceof ', $node->class); |
364 } | 371 } |
365 | 372 |
366 // Unary expressions | 373 // Unary expressions |
367 | 374 |
368 protected function pExpr_BooleanNot(Expr\BooleanNot $node) { | 375 protected function pExpr_BooleanNot(Expr\BooleanNot $node) { |
369 return $this->pPrefixOp('Expr_BooleanNot', '!', $node->expr); | 376 return $this->pPrefixOp(Expr\BooleanNot::class, '!', $node->expr); |
370 } | 377 } |
371 | 378 |
372 protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) { | 379 protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) { |
373 return $this->pPrefixOp('Expr_BitwiseNot', '~', $node->expr); | 380 return $this->pPrefixOp(Expr\BitwiseNot::class, '~', $node->expr); |
374 } | 381 } |
375 | 382 |
376 protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) { | 383 protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) { |
377 if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) { | 384 if ($node->expr instanceof Expr\UnaryMinus || $node->expr instanceof Expr\PreDec) { |
378 // Enforce -(-$expr) instead of --$expr | 385 // Enforce -(-$expr) instead of --$expr |
379 return '-(' . $this->p($node->expr) . ')'; | 386 return '-(' . $this->p($node->expr) . ')'; |
380 } | 387 } |
381 return $this->pPrefixOp('Expr_UnaryMinus', '-', $node->expr); | 388 return $this->pPrefixOp(Expr\UnaryMinus::class, '-', $node->expr); |
382 } | 389 } |
383 | 390 |
384 protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) { | 391 protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) { |
385 if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) { | 392 if ($node->expr instanceof Expr\UnaryPlus || $node->expr instanceof Expr\PreInc) { |
386 // Enforce +(+$expr) instead of ++$expr | 393 // Enforce +(+$expr) instead of ++$expr |
387 return '+(' . $this->p($node->expr) . ')'; | 394 return '+(' . $this->p($node->expr) . ')'; |
388 } | 395 } |
389 return $this->pPrefixOp('Expr_UnaryPlus', '+', $node->expr); | 396 return $this->pPrefixOp(Expr\UnaryPlus::class, '+', $node->expr); |
390 } | 397 } |
391 | 398 |
392 protected function pExpr_PreInc(Expr\PreInc $node) { | 399 protected function pExpr_PreInc(Expr\PreInc $node) { |
393 return $this->pPrefixOp('Expr_PreInc', '++', $node->var); | 400 return $this->pPrefixOp(Expr\PreInc::class, '++', $node->var); |
394 } | 401 } |
395 | 402 |
396 protected function pExpr_PreDec(Expr\PreDec $node) { | 403 protected function pExpr_PreDec(Expr\PreDec $node) { |
397 return $this->pPrefixOp('Expr_PreDec', '--', $node->var); | 404 return $this->pPrefixOp(Expr\PreDec::class, '--', $node->var); |
398 } | 405 } |
399 | 406 |
400 protected function pExpr_PostInc(Expr\PostInc $node) { | 407 protected function pExpr_PostInc(Expr\PostInc $node) { |
401 return $this->pPostfixOp('Expr_PostInc', $node->var, '++'); | 408 return $this->pPostfixOp(Expr\PostInc::class, $node->var, '++'); |
402 } | 409 } |
403 | 410 |
404 protected function pExpr_PostDec(Expr\PostDec $node) { | 411 protected function pExpr_PostDec(Expr\PostDec $node) { |
405 return $this->pPostfixOp('Expr_PostDec', $node->var, '--'); | 412 return $this->pPostfixOp(Expr\PostDec::class, $node->var, '--'); |
406 } | 413 } |
407 | 414 |
408 protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) { | 415 protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) { |
409 return $this->pPrefixOp('Expr_ErrorSuppress', '@', $node->expr); | 416 return $this->pPrefixOp(Expr\ErrorSuppress::class, '@', $node->expr); |
410 } | 417 } |
411 | 418 |
412 protected function pExpr_YieldFrom(Expr\YieldFrom $node) { | 419 protected function pExpr_YieldFrom(Expr\YieldFrom $node) { |
413 return $this->pPrefixOp('Expr_YieldFrom', 'yield from ', $node->expr); | 420 return $this->pPrefixOp(Expr\YieldFrom::class, 'yield from ', $node->expr); |
414 } | 421 } |
415 | 422 |
416 protected function pExpr_Print(Expr\Print_ $node) { | 423 protected function pExpr_Print(Expr\Print_ $node) { |
417 return $this->pPrefixOp('Expr_Print', 'print ', $node->expr); | 424 return $this->pPrefixOp(Expr\Print_::class, 'print ', $node->expr); |
418 } | 425 } |
419 | 426 |
420 // Casts | 427 // Casts |
421 | 428 |
422 protected function pExpr_Cast_Int(Cast\Int_ $node) { | 429 protected function pExpr_Cast_Int(Cast\Int_ $node) { |
423 return $this->pPrefixOp('Expr_Cast_Int', '(int) ', $node->expr); | 430 return $this->pPrefixOp(Cast\Int_::class, '(int) ', $node->expr); |
424 } | 431 } |
425 | 432 |
426 protected function pExpr_Cast_Double(Cast\Double $node) { | 433 protected function pExpr_Cast_Double(Cast\Double $node) { |
427 return $this->pPrefixOp('Expr_Cast_Double', '(double) ', $node->expr); | 434 return $this->pPrefixOp(Cast\Double::class, '(double) ', $node->expr); |
428 } | 435 } |
429 | 436 |
430 protected function pExpr_Cast_String(Cast\String_ $node) { | 437 protected function pExpr_Cast_String(Cast\String_ $node) { |
431 return $this->pPrefixOp('Expr_Cast_String', '(string) ', $node->expr); | 438 return $this->pPrefixOp(Cast\String_::class, '(string) ', $node->expr); |
432 } | 439 } |
433 | 440 |
434 protected function pExpr_Cast_Array(Cast\Array_ $node) { | 441 protected function pExpr_Cast_Array(Cast\Array_ $node) { |
435 return $this->pPrefixOp('Expr_Cast_Array', '(array) ', $node->expr); | 442 return $this->pPrefixOp(Cast\Array_::class, '(array) ', $node->expr); |
436 } | 443 } |
437 | 444 |
438 protected function pExpr_Cast_Object(Cast\Object_ $node) { | 445 protected function pExpr_Cast_Object(Cast\Object_ $node) { |
439 return $this->pPrefixOp('Expr_Cast_Object', '(object) ', $node->expr); | 446 return $this->pPrefixOp(Cast\Object_::class, '(object) ', $node->expr); |
440 } | 447 } |
441 | 448 |
442 protected function pExpr_Cast_Bool(Cast\Bool_ $node) { | 449 protected function pExpr_Cast_Bool(Cast\Bool_ $node) { |
443 return $this->pPrefixOp('Expr_Cast_Bool', '(bool) ', $node->expr); | 450 return $this->pPrefixOp(Cast\Bool_::class, '(bool) ', $node->expr); |
444 } | 451 } |
445 | 452 |
446 protected function pExpr_Cast_Unset(Cast\Unset_ $node) { | 453 protected function pExpr_Cast_Unset(Cast\Unset_ $node) { |
447 return $this->pPrefixOp('Expr_Cast_Unset', '(unset) ', $node->expr); | 454 return $this->pPrefixOp(Cast\Unset_::class, '(unset) ', $node->expr); |
448 } | 455 } |
449 | 456 |
450 // Function calls and similar constructs | 457 // Function calls and similar constructs |
451 | 458 |
452 protected function pExpr_FuncCall(Expr\FuncCall $node) { | 459 protected function pExpr_FuncCall(Expr\FuncCall $node) { |
480 protected function pExpr_Eval(Expr\Eval_ $node) { | 487 protected function pExpr_Eval(Expr\Eval_ $node) { |
481 return 'eval(' . $this->p($node->expr) . ')'; | 488 return 'eval(' . $this->p($node->expr) . ')'; |
482 } | 489 } |
483 | 490 |
484 protected function pExpr_Include(Expr\Include_ $node) { | 491 protected function pExpr_Include(Expr\Include_ $node) { |
485 static $map = array( | 492 static $map = [ |
486 Expr\Include_::TYPE_INCLUDE => 'include', | 493 Expr\Include_::TYPE_INCLUDE => 'include', |
487 Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', | 494 Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', |
488 Expr\Include_::TYPE_REQUIRE => 'require', | 495 Expr\Include_::TYPE_REQUIRE => 'require', |
489 Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', | 496 Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', |
490 ); | 497 ]; |
491 | 498 |
492 return $map[$node->type] . ' ' . $this->p($node->expr); | 499 return $map[$node->type] . ' ' . $this->p($node->expr); |
493 } | 500 } |
494 | 501 |
495 protected function pExpr_List(Expr\List_ $node) { | 502 protected function pExpr_List(Expr\List_ $node) { |
533 protected function pExpr_ConstFetch(Expr\ConstFetch $node) { | 540 protected function pExpr_ConstFetch(Expr\ConstFetch $node) { |
534 return $this->p($node->name); | 541 return $this->p($node->name); |
535 } | 542 } |
536 | 543 |
537 protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) { | 544 protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) { |
538 return $this->p($node->class) . '::' | 545 return $this->p($node->class) . '::' . $this->p($node->name); |
539 . (is_string($node->name) ? $node->name : $this->p($node->name)); | |
540 } | 546 } |
541 | 547 |
542 protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) { | 548 protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) { |
543 return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name); | 549 return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name); |
544 } | 550 } |
553 | 559 |
554 protected function pExpr_Closure(Expr\Closure $node) { | 560 protected function pExpr_Closure(Expr\Closure $node) { |
555 return ($node->static ? 'static ' : '') | 561 return ($node->static ? 'static ' : '') |
556 . 'function ' . ($node->byRef ? '&' : '') | 562 . 'function ' . ($node->byRef ? '&' : '') |
557 . '(' . $this->pCommaSeparated($node->params) . ')' | 563 . '(' . $this->pCommaSeparated($node->params) . ')' |
558 . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')': '') | 564 . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')' : '') |
559 . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') | 565 . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') |
560 . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; | 566 . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; |
561 } | 567 } |
562 | 568 |
563 protected function pExpr_ClosureUse(Expr\ClosureUse $node) { | 569 protected function pExpr_ClosureUse(Expr\ClosureUse $node) { |
564 return ($node->byRef ? '&' : '') . '$' . $node->var; | 570 return ($node->byRef ? '&' : '') . $this->p($node->var); |
565 } | 571 } |
566 | 572 |
567 protected function pExpr_New(Expr\New_ $node) { | 573 protected function pExpr_New(Expr\New_ $node) { |
568 if ($node->class instanceof Stmt\Class_) { | 574 if ($node->class instanceof Stmt\Class_) { |
569 $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : ''; | 575 $args = $node->args ? '(' . $this->pMaybeMultiline($node->args) . ')' : ''; |
577 } | 583 } |
578 | 584 |
579 protected function pExpr_Ternary(Expr\Ternary $node) { | 585 protected function pExpr_Ternary(Expr\Ternary $node) { |
580 // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. | 586 // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. |
581 // this is okay because the part between ? and : never needs parentheses. | 587 // this is okay because the part between ? and : never needs parentheses. |
582 return $this->pInfixOp('Expr_Ternary', | 588 return $this->pInfixOp(Expr\Ternary::class, |
583 $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else | 589 $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else |
584 ); | 590 ); |
585 } | 591 } |
586 | 592 |
587 protected function pExpr_Exit(Expr\Exit_ $node) { | 593 protected function pExpr_Exit(Expr\Exit_ $node) { |
604 | 610 |
605 // Declarations | 611 // Declarations |
606 | 612 |
607 protected function pStmt_Namespace(Stmt\Namespace_ $node) { | 613 protected function pStmt_Namespace(Stmt\Namespace_ $node) { |
608 if ($this->canUseSemicolonNamespaces) { | 614 if ($this->canUseSemicolonNamespaces) { |
609 return 'namespace ' . $this->p($node->name) . ';' . "\n" . $this->pStmts($node->stmts, false); | 615 return 'namespace ' . $this->p($node->name) . ';' |
616 . $this->nl . $this->pStmts($node->stmts, false); | |
610 } else { | 617 } else { |
611 return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') | 618 return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') |
612 . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; | 619 . ' {' . $this->pStmts($node->stmts) . $this->nl . '}'; |
613 } | 620 } |
614 } | 621 } |
615 | 622 |
616 protected function pStmt_Use(Stmt\Use_ $node) { | 623 protected function pStmt_Use(Stmt\Use_ $node) { |
617 return 'use ' . $this->pUseType($node->type) | 624 return 'use ' . $this->pUseType($node->type) |
623 . '\{' . $this->pCommaSeparated($node->uses) . '};'; | 630 . '\{' . $this->pCommaSeparated($node->uses) . '};'; |
624 } | 631 } |
625 | 632 |
626 protected function pStmt_UseUse(Stmt\UseUse $node) { | 633 protected function pStmt_UseUse(Stmt\UseUse $node) { |
627 return $this->pUseType($node->type) . $this->p($node->name) | 634 return $this->pUseType($node->type) . $this->p($node->name) |
628 . ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : ''); | 635 . (null !== $node->alias ? ' as ' . $node->alias : ''); |
629 } | 636 } |
630 | 637 |
631 protected function pUseType($type) { | 638 protected function pUseType($type) { |
632 return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' | 639 return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' |
633 : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); | 640 : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); |
634 } | 641 } |
635 | 642 |
636 protected function pStmt_Interface(Stmt\Interface_ $node) { | 643 protected function pStmt_Interface(Stmt\Interface_ $node) { |
637 return 'interface ' . $node->name | 644 return 'interface ' . $node->name |
638 . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') | 645 . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') |
639 . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; | 646 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; |
640 } | 647 } |
641 | 648 |
642 protected function pStmt_Class(Stmt\Class_ $node) { | 649 protected function pStmt_Class(Stmt\Class_ $node) { |
643 return $this->pClassCommon($node, ' ' . $node->name); | 650 return $this->pClassCommon($node, ' ' . $node->name); |
644 } | 651 } |
645 | 652 |
646 protected function pStmt_Trait(Stmt\Trait_ $node) { | 653 protected function pStmt_Trait(Stmt\Trait_ $node) { |
647 return 'trait ' . $node->name | 654 return 'trait ' . $node->name |
648 . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; | 655 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; |
649 } | 656 } |
650 | 657 |
651 protected function pStmt_TraitUse(Stmt\TraitUse $node) { | 658 protected function pStmt_TraitUse(Stmt\TraitUse $node) { |
652 return 'use ' . $this->pCommaSeparated($node->traits) | 659 return 'use ' . $this->pCommaSeparated($node->traits) |
653 . (empty($node->adaptations) | 660 . (empty($node->adaptations) |
654 ? ';' | 661 ? ';' |
655 : ' {' . $this->pStmts($node->adaptations) . "\n" . '}'); | 662 : ' {' . $this->pStmts($node->adaptations) . $this->nl . '}'); |
656 } | 663 } |
657 | 664 |
658 protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { | 665 protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { |
659 return $this->p($node->trait) . '::' . $node->method | 666 return $this->p($node->trait) . '::' . $node->method |
660 . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; | 667 . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; |
679 | 686 |
680 protected function pStmt_ClassMethod(Stmt\ClassMethod $node) { | 687 protected function pStmt_ClassMethod(Stmt\ClassMethod $node) { |
681 return $this->pModifiers($node->flags) | 688 return $this->pModifiers($node->flags) |
682 . 'function ' . ($node->byRef ? '&' : '') . $node->name | 689 . 'function ' . ($node->byRef ? '&' : '') . $node->name |
683 . '(' . $this->pCommaSeparated($node->params) . ')' | 690 . '(' . $this->pCommaSeparated($node->params) . ')' |
684 . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') | 691 . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') |
685 . (null !== $node->stmts | 692 . (null !== $node->stmts |
686 ? "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}' | 693 ? $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}' |
687 : ';'); | 694 : ';'); |
688 } | 695 } |
689 | 696 |
690 protected function pStmt_ClassConst(Stmt\ClassConst $node) { | 697 protected function pStmt_ClassConst(Stmt\ClassConst $node) { |
691 return $this->pModifiers($node->flags) | 698 return $this->pModifiers($node->flags) |
693 } | 700 } |
694 | 701 |
695 protected function pStmt_Function(Stmt\Function_ $node) { | 702 protected function pStmt_Function(Stmt\Function_ $node) { |
696 return 'function ' . ($node->byRef ? '&' : '') . $node->name | 703 return 'function ' . ($node->byRef ? '&' : '') . $node->name |
697 . '(' . $this->pCommaSeparated($node->params) . ')' | 704 . '(' . $this->pCommaSeparated($node->params) . ')' |
698 . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') | 705 . (null !== $node->returnType ? ' : ' . $this->p($node->returnType) : '') |
699 . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; | 706 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; |
700 } | 707 } |
701 | 708 |
702 protected function pStmt_Const(Stmt\Const_ $node) { | 709 protected function pStmt_Const(Stmt\Const_ $node) { |
703 return 'const ' . $this->pCommaSeparated($node->consts) . ';'; | 710 return 'const ' . $this->pCommaSeparated($node->consts) . ';'; |
704 } | 711 } |
705 | 712 |
706 protected function pStmt_Declare(Stmt\Declare_ $node) { | 713 protected function pStmt_Declare(Stmt\Declare_ $node) { |
707 return 'declare (' . $this->pCommaSeparated($node->declares) . ')' | 714 return 'declare (' . $this->pCommaSeparated($node->declares) . ')' |
708 . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . "\n" . '}' : ';'); | 715 . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . $this->nl . '}' : ';'); |
709 } | 716 } |
710 | 717 |
711 protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { | 718 protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { |
712 return $node->key . '=' . $this->p($node->value); | 719 return $node->key . '=' . $this->p($node->value); |
713 } | 720 } |
714 | 721 |
715 // Control flow | 722 // Control flow |
716 | 723 |
717 protected function pStmt_If(Stmt\If_ $node) { | 724 protected function pStmt_If(Stmt\If_ $node) { |
718 return 'if (' . $this->p($node->cond) . ') {' | 725 return 'if (' . $this->p($node->cond) . ') {' |
719 . $this->pStmts($node->stmts) . "\n" . '}' | 726 . $this->pStmts($node->stmts) . $this->nl . '}' |
720 . $this->pImplode($node->elseifs) | 727 . ($node->elseifs ? ' ' . $this->pImplode($node->elseifs, ' ') : '') |
721 . (null !== $node->else ? $this->p($node->else) : ''); | 728 . (null !== $node->else ? ' ' . $this->p($node->else) : ''); |
722 } | 729 } |
723 | 730 |
724 protected function pStmt_ElseIf(Stmt\ElseIf_ $node) { | 731 protected function pStmt_ElseIf(Stmt\ElseIf_ $node) { |
725 return ' elseif (' . $this->p($node->cond) . ') {' | 732 return 'elseif (' . $this->p($node->cond) . ') {' |
726 . $this->pStmts($node->stmts) . "\n" . '}'; | 733 . $this->pStmts($node->stmts) . $this->nl . '}'; |
727 } | 734 } |
728 | 735 |
729 protected function pStmt_Else(Stmt\Else_ $node) { | 736 protected function pStmt_Else(Stmt\Else_ $node) { |
730 return ' else {' . $this->pStmts($node->stmts) . "\n" . '}'; | 737 return 'else {' . $this->pStmts($node->stmts) . $this->nl . '}'; |
731 } | 738 } |
732 | 739 |
733 protected function pStmt_For(Stmt\For_ $node) { | 740 protected function pStmt_For(Stmt\For_ $node) { |
734 return 'for (' | 741 return 'for (' |
735 . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') | 742 . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') |
736 . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') | 743 . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') |
737 . $this->pCommaSeparated($node->loop) | 744 . $this->pCommaSeparated($node->loop) |
738 . ') {' . $this->pStmts($node->stmts) . "\n" . '}'; | 745 . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; |
739 } | 746 } |
740 | 747 |
741 protected function pStmt_Foreach(Stmt\Foreach_ $node) { | 748 protected function pStmt_Foreach(Stmt\Foreach_ $node) { |
742 return 'foreach (' . $this->p($node->expr) . ' as ' | 749 return 'foreach (' . $this->p($node->expr) . ' as ' |
743 . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') | 750 . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') |
744 . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' | 751 . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' |
745 . $this->pStmts($node->stmts) . "\n" . '}'; | 752 . $this->pStmts($node->stmts) . $this->nl . '}'; |
746 } | 753 } |
747 | 754 |
748 protected function pStmt_While(Stmt\While_ $node) { | 755 protected function pStmt_While(Stmt\While_ $node) { |
749 return 'while (' . $this->p($node->cond) . ') {' | 756 return 'while (' . $this->p($node->cond) . ') {' |
750 . $this->pStmts($node->stmts) . "\n" . '}'; | 757 . $this->pStmts($node->stmts) . $this->nl . '}'; |
751 } | 758 } |
752 | 759 |
753 protected function pStmt_Do(Stmt\Do_ $node) { | 760 protected function pStmt_Do(Stmt\Do_ $node) { |
754 return 'do {' . $this->pStmts($node->stmts) . "\n" | 761 return 'do {' . $this->pStmts($node->stmts) . $this->nl |
755 . '} while (' . $this->p($node->cond) . ');'; | 762 . '} while (' . $this->p($node->cond) . ');'; |
756 } | 763 } |
757 | 764 |
758 protected function pStmt_Switch(Stmt\Switch_ $node) { | 765 protected function pStmt_Switch(Stmt\Switch_ $node) { |
759 return 'switch (' . $this->p($node->cond) . ') {' | 766 return 'switch (' . $this->p($node->cond) . ') {' |
760 . $this->pStmts($node->cases) . "\n" . '}'; | 767 . $this->pStmts($node->cases) . $this->nl . '}'; |
761 } | 768 } |
762 | 769 |
763 protected function pStmt_Case(Stmt\Case_ $node) { | 770 protected function pStmt_Case(Stmt\Case_ $node) { |
764 return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' | 771 return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' |
765 . $this->pStmts($node->stmts); | 772 . $this->pStmts($node->stmts); |
766 } | 773 } |
767 | 774 |
768 protected function pStmt_TryCatch(Stmt\TryCatch $node) { | 775 protected function pStmt_TryCatch(Stmt\TryCatch $node) { |
769 return 'try {' . $this->pStmts($node->stmts) . "\n" . '}' | 776 return 'try {' . $this->pStmts($node->stmts) . $this->nl . '}' |
770 . $this->pImplode($node->catches) | 777 . ($node->catches ? ' ' . $this->pImplode($node->catches, ' ') : '') |
771 . ($node->finally !== null ? $this->p($node->finally) : ''); | 778 . ($node->finally !== null ? ' ' . $this->p($node->finally) : ''); |
772 } | 779 } |
773 | 780 |
774 protected function pStmt_Catch(Stmt\Catch_ $node) { | 781 protected function pStmt_Catch(Stmt\Catch_ $node) { |
775 return ' catch (' . $this->pImplode($node->types, '|') . ' $' . $node->var . ') {' | 782 return 'catch (' . $this->pImplode($node->types, '|') . ' ' |
776 . $this->pStmts($node->stmts) . "\n" . '}'; | 783 . $this->p($node->var) |
784 . ') {' . $this->pStmts($node->stmts) . $this->nl . '}'; | |
777 } | 785 } |
778 | 786 |
779 protected function pStmt_Finally(Stmt\Finally_ $node) { | 787 protected function pStmt_Finally(Stmt\Finally_ $node) { |
780 return ' finally {' . $this->pStmts($node->stmts) . "\n" . '}'; | 788 return 'finally {' . $this->pStmts($node->stmts) . $this->nl . '}'; |
781 } | 789 } |
782 | 790 |
783 protected function pStmt_Break(Stmt\Break_ $node) { | 791 protected function pStmt_Break(Stmt\Break_ $node) { |
784 return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; | 792 return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; |
785 } | 793 } |
804 return 'goto ' . $node->name . ';'; | 812 return 'goto ' . $node->name . ';'; |
805 } | 813 } |
806 | 814 |
807 // Other | 815 // Other |
808 | 816 |
817 protected function pStmt_Expression(Stmt\Expression $node) { | |
818 return $this->p($node->expr) . ';'; | |
819 } | |
820 | |
809 protected function pStmt_Echo(Stmt\Echo_ $node) { | 821 protected function pStmt_Echo(Stmt\Echo_ $node) { |
810 return 'echo ' . $this->pCommaSeparated($node->exprs) . ';'; | 822 return 'echo ' . $this->pCommaSeparated($node->exprs) . ';'; |
811 } | 823 } |
812 | 824 |
813 protected function pStmt_Static(Stmt\Static_ $node) { | 825 protected function pStmt_Static(Stmt\Static_ $node) { |
817 protected function pStmt_Global(Stmt\Global_ $node) { | 829 protected function pStmt_Global(Stmt\Global_ $node) { |
818 return 'global ' . $this->pCommaSeparated($node->vars) . ';'; | 830 return 'global ' . $this->pCommaSeparated($node->vars) . ';'; |
819 } | 831 } |
820 | 832 |
821 protected function pStmt_StaticVar(Stmt\StaticVar $node) { | 833 protected function pStmt_StaticVar(Stmt\StaticVar $node) { |
822 return '$' . $node->name | 834 return $this->p($node->var) |
823 . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); | 835 . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
824 } | 836 } |
825 | 837 |
826 protected function pStmt_Unset(Stmt\Unset_ $node) { | 838 protected function pStmt_Unset(Stmt\Unset_ $node) { |
827 return 'unset(' . $this->pCommaSeparated($node->vars) . ');'; | 839 return 'unset(' . $this->pCommaSeparated($node->vars) . ');'; |
828 } | 840 } |
829 | 841 |
830 protected function pStmt_InlineHTML(Stmt\InlineHTML $node) { | 842 protected function pStmt_InlineHTML(Stmt\InlineHTML $node) { |
831 $newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : ''; | 843 $newline = $node->getAttribute('hasLeadingNewline', true) ? "\n" : ''; |
832 return '?>' . $this->pNoIndent($newline . $node->value) . '<?php '; | 844 return '?>' . $newline . $node->value . '<?php '; |
833 } | 845 } |
834 | 846 |
835 protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) { | 847 protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) { |
836 return '__halt_compiler();' . $node->remaining; | 848 return '__halt_compiler();' . $node->remaining; |
837 } | 849 } |
839 protected function pStmt_Nop(Stmt\Nop $node) { | 851 protected function pStmt_Nop(Stmt\Nop $node) { |
840 return ''; | 852 return ''; |
841 } | 853 } |
842 | 854 |
843 // Helpers | 855 // Helpers |
844 | |
845 protected function pType($node) { | |
846 return is_string($node) ? $node : $this->p($node); | |
847 } | |
848 | 856 |
849 protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { | 857 protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { |
850 return $this->pModifiers($node->flags) | 858 return $this->pModifiers($node->flags) |
851 . 'class' . $afterClassToken | 859 . 'class' . $afterClassToken |
852 . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '') | 860 . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '') |
853 . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') | 861 . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') |
854 . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; | 862 . $this->nl . '{' . $this->pStmts($node->stmts) . $this->nl . '}'; |
855 } | 863 } |
856 | 864 |
857 protected function pObjectProperty($node) { | 865 protected function pObjectProperty($node) { |
858 if ($node instanceof Expr) { | 866 if ($node instanceof Expr) { |
859 return '{' . $this->p($node) . '}'; | 867 return '{' . $this->p($node) . '}'; |
860 } else { | 868 } else { |
861 return $node; | 869 return $node; |
862 } | 870 } |
863 } | |
864 | |
865 protected function pModifiers($modifiers) { | |
866 return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') | |
867 . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '') | |
868 . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '') | |
869 . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '') | |
870 . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '') | |
871 . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); | |
872 } | 871 } |
873 | 872 |
874 protected function pEncapsList(array $encapsList, $quote) { | 873 protected function pEncapsList(array $encapsList, $quote) { |
875 $return = ''; | 874 $return = ''; |
876 foreach ($encapsList as $element) { | 875 foreach ($encapsList as $element) { |
882 } | 881 } |
883 | 882 |
884 return $return; | 883 return $return; |
885 } | 884 } |
886 | 885 |
886 protected function pSingleQuotedString(string $string) { | |
887 return '\'' . addcslashes($string, '\'\\') . '\''; | |
888 } | |
889 | |
887 protected function escapeString($string, $quote) { | 890 protected function escapeString($string, $quote) { |
888 if (null === $quote) { | 891 if (null === $quote) { |
889 // For doc strings, don't escape newlines | 892 // For doc strings, don't escape newlines |
890 $escaped = addcslashes($string, "\t\f\v$\\"); | 893 $escaped = addcslashes($string, "\t\f\v$\\"); |
891 } else { | 894 } else { |
895 // Escape other control characters | 898 // Escape other control characters |
896 return preg_replace_callback('/([\0-\10\16-\37])(?=([0-7]?))/', function ($matches) { | 899 return preg_replace_callback('/([\0-\10\16-\37])(?=([0-7]?))/', function ($matches) { |
897 $oct = decoct(ord($matches[1])); | 900 $oct = decoct(ord($matches[1])); |
898 if ($matches[2] !== '') { | 901 if ($matches[2] !== '') { |
899 // If there is a trailing digit, use the full three character form | 902 // If there is a trailing digit, use the full three character form |
900 return '\\' . str_pad($oct, 3, '0', STR_PAD_LEFT); | 903 return '\\' . str_pad($oct, 3, '0', \STR_PAD_LEFT); |
901 } | 904 } |
902 return '\\' . $oct; | 905 return '\\' . $oct; |
903 }, $escaped); | 906 }, $escaped); |
904 } | 907 } |
905 | 908 |
922 } | 925 } |
923 return false; | 926 return false; |
924 } | 927 } |
925 | 928 |
926 protected function pDereferenceLhs(Node $node) { | 929 protected function pDereferenceLhs(Node $node) { |
927 if ($node instanceof Expr\Variable | 930 if (!$this->dereferenceLhsRequiresParens($node)) { |
928 || $node instanceof Name | |
929 || $node instanceof Expr\ArrayDimFetch | |
930 || $node instanceof Expr\PropertyFetch | |
931 || $node instanceof Expr\StaticPropertyFetch | |
932 || $node instanceof Expr\FuncCall | |
933 || $node instanceof Expr\MethodCall | |
934 || $node instanceof Expr\StaticCall | |
935 || $node instanceof Expr\Array_ | |
936 || $node instanceof Scalar\String_ | |
937 || $node instanceof Expr\ConstFetch | |
938 || $node instanceof Expr\ClassConstFetch | |
939 ) { | |
940 return $this->p($node); | 931 return $this->p($node); |
941 } else { | 932 } else { |
942 return '(' . $this->p($node) . ')'; | 933 return '(' . $this->p($node) . ')'; |
943 } | 934 } |
944 } | 935 } |
945 | 936 |
946 protected function pCallLhs(Node $node) { | 937 protected function pCallLhs(Node $node) { |
947 if ($node instanceof Name | 938 if (!$this->callLhsRequiresParens($node)) { |
948 || $node instanceof Expr\Variable | |
949 || $node instanceof Expr\ArrayDimFetch | |
950 || $node instanceof Expr\FuncCall | |
951 || $node instanceof Expr\MethodCall | |
952 || $node instanceof Expr\StaticCall | |
953 || $node instanceof Expr\Array_ | |
954 ) { | |
955 return $this->p($node); | 939 return $this->p($node); |
956 } else { | 940 } else { |
957 return '(' . $this->p($node) . ')'; | 941 return '(' . $this->p($node) . ')'; |
958 } | 942 } |
959 } | 943 } |
960 | 944 |
945 /** | |
946 * @param Node[] $nodes | |
947 * @return bool | |
948 */ | |
961 private function hasNodeWithComments(array $nodes) { | 949 private function hasNodeWithComments(array $nodes) { |
962 foreach ($nodes as $node) { | 950 foreach ($nodes as $node) { |
963 if ($node && $node->getAttribute('comments')) { | 951 if ($node && $node->getComments()) { |
964 return true; | 952 return true; |
965 } | 953 } |
966 } | 954 } |
967 return false; | 955 return false; |
968 } | 956 } |
969 | 957 |
970 private function pMaybeMultiline(array $nodes, $trailingComma = false) { | 958 private function pMaybeMultiline(array $nodes, $trailingComma = false) { |
971 if (!$this->hasNodeWithComments($nodes)) { | 959 if (!$this->hasNodeWithComments($nodes)) { |
972 return $this->pCommaSeparated($nodes); | 960 return $this->pCommaSeparated($nodes); |
973 } else { | 961 } else { |
974 return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . "\n"; | 962 return $this->pCommaSeparatedMultiline($nodes, $trailingComma) . $this->nl; |
975 } | 963 } |
976 } | 964 } |
977 } | 965 } |