Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Standard often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Standard, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class Standard extends PrettyPrinterAbstract |
||
| 17 | { |
||
| 18 | // Special nodes |
||
| 19 | |||
| 20 | public function pParam(Node\Param $node) { |
||
| 21 | return ($node->type ? $this->pType($node->type) . ' ' : '') |
||
| 22 | . ($node->byRef ? '&' : '') |
||
| 23 | . ($node->variadic ? '...' : '') |
||
| 24 | . '$' . $node->name |
||
| 25 | . ($node->default ? ' = ' . $this->p($node->default) : ''); |
||
| 26 | } |
||
| 27 | |||
| 28 | public function pArg(Node\Arg $node) { |
||
| 31 | |||
| 32 | public function pConst(Node\Const_ $node) { |
||
| 35 | |||
| 36 | // Names |
||
| 37 | |||
| 38 | public function pName(Name $node) { |
||
| 41 | |||
| 42 | public function pName_FullyQualified(Name\FullyQualified $node) { |
||
| 45 | |||
| 46 | public function pName_Relative(Name\Relative $node) { |
||
| 49 | |||
| 50 | // Magic Constants |
||
| 51 | |||
| 52 | public function pScalar_MagicConst_Class(MagicConst\Class_ $node) { |
||
| 55 | |||
| 56 | public function pScalar_MagicConst_Dir(MagicConst\Dir $node) { |
||
| 59 | |||
| 60 | public function pScalar_MagicConst_File(MagicConst\File $node) { |
||
| 63 | |||
| 64 | public function pScalar_MagicConst_Function(MagicConst\Function_ $node) { |
||
| 67 | |||
| 68 | public function pScalar_MagicConst_Line(MagicConst\Line $node) { |
||
| 71 | |||
| 72 | public function pScalar_MagicConst_Method(MagicConst\Method $node) { |
||
| 75 | |||
| 76 | public function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) { |
||
| 79 | |||
| 80 | public function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) { |
||
| 83 | |||
| 84 | // Scalars |
||
| 85 | |||
| 86 | public function pScalar_String(Scalar\String_ $node) { |
||
| 89 | |||
| 90 | public function pScalar_Encapsed(Scalar\Encapsed $node) { |
||
| 93 | |||
| 94 | public function pScalar_LNumber(Scalar\LNumber $node) { |
||
| 97 | |||
| 98 | public function pScalar_DNumber(Scalar\DNumber $node) { |
||
| 99 | $stringValue = sprintf('%.16G', $node->value); |
||
| 100 | if ($node->value !== (double) $stringValue) { |
||
| 101 | $stringValue = sprintf('%.17G', $node->value); |
||
| 102 | } |
||
| 103 | |||
| 104 | // ensure that number is really printed as float |
||
| 105 | return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; |
||
| 106 | } |
||
| 107 | |||
| 108 | // Assignments |
||
| 109 | |||
| 110 | public function pExpr_Assign(Expr\Assign $node) { |
||
| 113 | |||
| 114 | public function pExpr_AssignRef(Expr\AssignRef $node) { |
||
| 117 | |||
| 118 | public function pExpr_AssignOp_Plus(AssignOp\Plus $node) { |
||
| 121 | |||
| 122 | public function pExpr_AssignOp_Minus(AssignOp\Minus $node) { |
||
| 125 | |||
| 126 | public function pExpr_AssignOp_Mul(AssignOp\Mul $node) { |
||
| 129 | |||
| 130 | public function pExpr_AssignOp_Div(AssignOp\Div $node) { |
||
| 133 | |||
| 134 | public function pExpr_AssignOp_Concat(AssignOp\Concat $node) { |
||
| 137 | |||
| 138 | public function pExpr_AssignOp_Mod(AssignOp\Mod $node) { |
||
| 141 | |||
| 142 | public function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) { |
||
| 145 | |||
| 146 | public function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) { |
||
| 149 | |||
| 150 | public function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) { |
||
| 153 | |||
| 154 | public function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) { |
||
| 157 | |||
| 158 | public function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) { |
||
| 161 | |||
| 162 | public function pExpr_AssignOp_Pow(AssignOp\Pow $node) { |
||
| 165 | |||
| 166 | // Binary expressions |
||
| 167 | |||
| 168 | public function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) { |
||
| 171 | |||
| 172 | public function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) { |
||
| 175 | |||
| 176 | public function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) { |
||
| 179 | |||
| 180 | public function pExpr_BinaryOp_Div(BinaryOp\Div $node) { |
||
| 183 | |||
| 184 | public function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) { |
||
| 187 | |||
| 188 | public function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) { |
||
| 191 | |||
| 192 | public function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) { |
||
| 195 | |||
| 196 | public function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) { |
||
| 199 | |||
| 200 | public function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) { |
||
| 203 | |||
| 204 | public function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) { |
||
| 207 | |||
| 208 | public function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) { |
||
| 211 | |||
| 212 | public function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) { |
||
| 215 | |||
| 216 | public function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) { |
||
| 219 | |||
| 220 | public function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) { |
||
| 223 | |||
| 224 | public function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) { |
||
| 227 | |||
| 228 | public function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) { |
||
| 231 | |||
| 232 | public function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) { |
||
| 235 | |||
| 236 | public function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) { |
||
| 239 | |||
| 240 | public function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) { |
||
| 243 | |||
| 244 | public function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) { |
||
| 247 | |||
| 248 | public function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) { |
||
| 251 | |||
| 252 | public function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) { |
||
| 255 | |||
| 256 | public function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) { |
||
| 259 | |||
| 260 | public function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) { |
||
| 263 | |||
| 264 | public function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) { |
||
| 267 | |||
| 268 | public function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) { |
||
| 271 | |||
| 272 | public function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) { |
||
| 275 | |||
| 276 | public function pExpr_Instanceof(Expr\Instanceof_ $node) { |
||
| 279 | |||
| 280 | // Unary expressions |
||
| 281 | |||
| 282 | public function pExpr_BooleanNot(Expr\BooleanNot $node) { |
||
| 285 | |||
| 286 | public function pExpr_BitwiseNot(Expr\BitwiseNot $node) { |
||
| 289 | |||
| 290 | public function pExpr_UnaryMinus(Expr\UnaryMinus $node) { |
||
| 293 | |||
| 294 | public function pExpr_UnaryPlus(Expr\UnaryPlus $node) { |
||
| 297 | |||
| 298 | public function pExpr_PreInc(Expr\PreInc $node) { |
||
| 301 | |||
| 302 | public function pExpr_PreDec(Expr\PreDec $node) { |
||
| 305 | |||
| 306 | public function pExpr_PostInc(Expr\PostInc $node) { |
||
| 309 | |||
| 310 | public function pExpr_PostDec(Expr\PostDec $node) { |
||
| 313 | |||
| 314 | public function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) { |
||
| 317 | |||
| 318 | public function pExpr_YieldFrom(Expr\YieldFrom $node) { |
||
| 321 | |||
| 322 | public function pExpr_Print(Expr\Print_ $node) { |
||
| 325 | |||
| 326 | // Casts |
||
| 327 | |||
| 328 | public function pExpr_Cast_Int(Cast\Int_ $node) { |
||
| 331 | |||
| 332 | public function pExpr_Cast_Double(Cast\Double $node) { |
||
| 335 | |||
| 336 | public function pExpr_Cast_String(Cast\String_ $node) { |
||
| 339 | |||
| 340 | public function pExpr_Cast_Array(Cast\Array_ $node) { |
||
| 343 | |||
| 344 | public function pExpr_Cast_Object(Cast\Object_ $node) { |
||
| 347 | |||
| 348 | public function pExpr_Cast_Bool(Cast\Bool_ $node) { |
||
| 351 | |||
| 352 | public function pExpr_Cast_Unset(Cast\Unset_ $node) { |
||
| 355 | |||
| 356 | // Function calls and similar constructs |
||
| 357 | |||
| 358 | public function pExpr_FuncCall(Expr\FuncCall $node) { |
||
| 362 | |||
| 363 | public function pExpr_MethodCall(Expr\MethodCall $node) { |
||
| 367 | |||
| 368 | public function pExpr_StaticCall(Expr\StaticCall $node) { |
||
| 369 | return $this->pDereferenceLhs($node->class) . '::' |
||
| 370 | . ($node->name instanceof Expr |
||
| 371 | ? ($node->name instanceof Expr\Variable |
||
| 372 | ? $this->p($node->name) |
||
| 373 | : '{' . $this->p($node->name) . '}') |
||
| 374 | : $node->name) |
||
| 375 | . '(' . $this->pCommaSeparated($node->args) . ')'; |
||
| 376 | } |
||
| 377 | |||
| 378 | public function pExpr_Empty(Expr\Empty_ $node) { |
||
| 381 | |||
| 382 | public function pExpr_Isset(Expr\Isset_ $node) { |
||
| 385 | |||
| 386 | public function pExpr_Eval(Expr\Eval_ $node) { |
||
| 389 | |||
| 390 | public function pExpr_Include(Expr\Include_ $node) { |
||
| 391 | static $map = array( |
||
| 392 | Expr\Include_::TYPE_INCLUDE => 'include', |
||
| 393 | Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once', |
||
| 394 | Expr\Include_::TYPE_REQUIRE => 'require', |
||
| 395 | Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', |
||
| 396 | ); |
||
| 397 | |||
| 398 | return $map[$node->type] . ' ' . $this->p($node->expr); |
||
| 399 | } |
||
| 400 | |||
| 401 | public function pExpr_List(Expr\List_ $node) { |
||
| 402 | $pList = array(); |
||
| 403 | foreach ($node->vars as $var) { |
||
| 404 | if (null === $var) { |
||
| 405 | $pList[] = ''; |
||
| 406 | } else { |
||
| 407 | $pList[] = $this->p($var); |
||
| 408 | } |
||
| 409 | } |
||
| 410 | |||
| 411 | return 'list(' . implode(', ', $pList) . ')'; |
||
| 412 | } |
||
| 413 | |||
| 414 | // Other |
||
| 415 | |||
| 416 | public function pExpr_Variable(Expr\Variable $node) { |
||
| 417 | if ($node->name instanceof Expr) { |
||
| 418 | return '${' . $this->p($node->name) . '}'; |
||
| 419 | } else { |
||
| 420 | return '$' . $node->name; |
||
| 421 | } |
||
| 422 | } |
||
| 423 | |||
| 424 | public function pExpr_Array(Expr\Array_ $node) { |
||
| 425 | if ($this->options['shortArraySyntax']) { |
||
| 426 | return '[' . $this->pCommaSeparated($node->items) . ']'; |
||
| 427 | } else { |
||
| 428 | return 'array(' . $this->pCommaSeparated($node->items) . ')'; |
||
| 429 | } |
||
| 430 | } |
||
| 431 | |||
| 432 | public function pExpr_ArrayItem(Expr\ArrayItem $node) { |
||
| 436 | |||
| 437 | public function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) { |
||
| 441 | |||
| 442 | public function pExpr_ConstFetch(Expr\ConstFetch $node) { |
||
| 445 | |||
| 446 | public function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) { |
||
| 449 | |||
| 450 | public function pExpr_PropertyFetch(Expr\PropertyFetch $node) { |
||
| 453 | |||
| 454 | public function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) { |
||
| 457 | |||
| 458 | public function pExpr_ShellExec(Expr\ShellExec $node) { |
||
| 461 | |||
| 462 | public function pExpr_Closure(Expr\Closure $node) { |
||
| 463 | return ($node->static ? 'static ' : '') |
||
| 464 | . 'function ' . ($node->byRef ? '&' : '') |
||
| 465 | . '(' . $this->pCommaSeparated($node->params) . ')' |
||
| 466 | . (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')': '') |
||
| 467 | . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
||
| 468 | . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 469 | } |
||
| 470 | |||
| 471 | public function pExpr_ClosureUse(Expr\ClosureUse $node) { |
||
| 474 | |||
| 475 | public function pExpr_New(Expr\New_ $node) { |
||
| 476 | if ($node->class instanceof Stmt\Class_) { |
||
| 477 | $args = $node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : ''; |
||
| 478 | return 'new ' . $this->pClassCommon($node->class, $args); |
||
| 479 | } |
||
| 480 | return 'new ' . $this->p($node->class) . '(' . $this->pCommaSeparated($node->args) . ')'; |
||
| 481 | } |
||
| 482 | |||
| 483 | public function pExpr_Clone(Expr\Clone_ $node) { |
||
| 486 | |||
| 487 | public function pExpr_Ternary(Expr\Ternary $node) { |
||
| 488 | // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. |
||
| 489 | // this is okay because the part between ? and : never needs parentheses. |
||
| 490 | return $this->pInfixOp('Expr_Ternary', |
||
| 491 | $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else |
||
| 492 | ); |
||
| 493 | } |
||
| 494 | |||
| 495 | public function pExpr_Exit(Expr\Exit_ $node) { |
||
| 498 | |||
| 499 | public function pExpr_Yield(Expr\Yield_ $node) { |
||
| 500 | if ($node->value === null) { |
||
| 501 | return 'yield'; |
||
| 502 | } else { |
||
| 503 | // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary |
||
| 504 | return '(yield ' |
||
| 505 | . ($node->key !== null ? $this->p($node->key) . ' => ' : '') |
||
| 506 | . $this->p($node->value) |
||
| 507 | . ')'; |
||
| 508 | } |
||
| 509 | } |
||
| 510 | |||
| 511 | // Declarations |
||
| 512 | |||
| 513 | public function pStmt_Namespace(Stmt\Namespace_ $node) { |
||
| 514 | if ($this->canUseSemicolonNamespaces) { |
||
| 515 | return 'namespace ' . $this->p($node->name) . ';' . "\n" . $this->pStmts($node->stmts, false); |
||
| 516 | } else { |
||
| 517 | return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') |
||
| 518 | . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 519 | } |
||
| 520 | } |
||
| 521 | |||
| 522 | public function pStmt_Use(Stmt\Use_ $node) { |
||
| 526 | |||
| 527 | public function pStmt_GroupUse(Stmt\GroupUse $node) { |
||
| 531 | |||
| 532 | public function pStmt_UseUse(Stmt\UseUse $node) { |
||
| 536 | |||
| 537 | private function pUseType($type) { |
||
| 541 | |||
| 542 | public function pStmt_Interface(Stmt\Interface_ $node) { |
||
| 543 | return 'interface ' . $node->name |
||
| 544 | . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') |
||
| 545 | . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 546 | } |
||
| 547 | |||
| 548 | public function pStmt_Class(Stmt\Class_ $node) { |
||
| 551 | |||
| 552 | public function pStmt_Trait(Stmt\Trait_ $node) { |
||
| 556 | |||
| 557 | public function pStmt_TraitUse(Stmt\TraitUse $node) { |
||
| 558 | return 'use ' . $this->pCommaSeparated($node->traits) |
||
| 559 | . (empty($node->adaptations) |
||
| 560 | ? ';' |
||
| 561 | : ' {' . $this->pStmts($node->adaptations) . "\n" . '}'); |
||
| 562 | } |
||
| 563 | |||
| 564 | public function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { |
||
| 568 | |||
| 569 | public function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) { |
||
| 576 | |||
| 577 | public function pStmt_Property(Stmt\Property $node) { |
||
| 580 | |||
| 581 | public function pStmt_PropertyProperty(Stmt\PropertyProperty $node) { |
||
| 585 | |||
| 586 | public function pStmt_ClassMethod(Stmt\ClassMethod $node) { |
||
| 595 | |||
| 596 | public function pStmt_ClassConst(Stmt\ClassConst $node) { |
||
| 599 | |||
| 600 | public function pStmt_Function(Stmt\Function_ $node) { |
||
| 601 | return 'function ' . ($node->byRef ? '&' : '') . $node->name |
||
| 602 | . '(' . $this->pCommaSeparated($node->params) . ')' |
||
| 603 | . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
||
| 604 | . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 605 | } |
||
| 606 | |||
| 607 | public function pStmt_Const(Stmt\Const_ $node) { |
||
| 610 | |||
| 611 | public function pStmt_Declare(Stmt\Declare_ $node) { |
||
| 612 | return 'declare (' . $this->pCommaSeparated($node->declares) . ')' |
||
| 613 | . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . "\n" . '}' : ';'); |
||
| 614 | } |
||
| 615 | |||
| 616 | public function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { |
||
| 619 | |||
| 620 | // Control flow |
||
| 621 | |||
| 622 | public function pStmt_If(Stmt\If_ $node) { |
||
| 623 | return 'if (' . $this->p($node->cond) . ') {' |
||
| 624 | . $this->pStmts($node->stmts) . "\n" . '}' |
||
| 625 | . $this->pImplode($node->elseifs) |
||
| 626 | . (null !== $node->else ? $this->p($node->else) : ''); |
||
| 627 | } |
||
| 628 | |||
| 629 | public function pStmt_ElseIf(Stmt\ElseIf_ $node) { |
||
| 633 | |||
| 634 | public function pStmt_Else(Stmt\Else_ $node) { |
||
| 637 | |||
| 638 | View Code Duplication | public function pStmt_For(Stmt\For_ $node) { |
|
| 639 | return 'for (' |
||
| 640 | . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') |
||
| 641 | . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') |
||
| 642 | . $this->pCommaSeparated($node->loop) |
||
| 643 | . ') {' . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 644 | } |
||
| 645 | |||
| 646 | public function pStmt_Foreach(Stmt\Foreach_ $node) { |
||
| 647 | return 'foreach (' . $this->p($node->expr) . ' as ' |
||
| 648 | . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') |
||
| 649 | . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' |
||
| 650 | . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 651 | } |
||
| 652 | |||
| 653 | public function pStmt_While(Stmt\While_ $node) { |
||
| 657 | |||
| 658 | public function pStmt_Do(Stmt\Do_ $node) { |
||
| 662 | |||
| 663 | public function pStmt_Switch(Stmt\Switch_ $node) { |
||
| 667 | |||
| 668 | public function pStmt_Case(Stmt\Case_ $node) { |
||
| 672 | |||
| 673 | public function pStmt_TryCatch(Stmt\TryCatch $node) { |
||
| 674 | return 'try {' . $this->pStmts($node->stmts) . "\n" . '}' |
||
| 675 | . $this->pImplode($node->catches) |
||
| 676 | . ($node->finallyStmts !== null |
||
| 677 | ? ' finally {' . $this->pStmts($node->finallyStmts) . "\n" . '}' |
||
| 678 | : ''); |
||
| 679 | } |
||
| 680 | |||
| 681 | public function pStmt_Catch(Stmt\Catch_ $node) { |
||
| 685 | |||
| 686 | public function pStmt_Break(Stmt\Break_ $node) { |
||
| 689 | |||
| 690 | public function pStmt_Continue(Stmt\Continue_ $node) { |
||
| 693 | |||
| 694 | public function pStmt_Return(Stmt\Return_ $node) { |
||
| 697 | |||
| 698 | public function pStmt_Throw(Stmt\Throw_ $node) { |
||
| 701 | |||
| 702 | public function pStmt_Label(Stmt\Label $node) { |
||
| 705 | |||
| 706 | public function pStmt_Goto(Stmt\Goto_ $node) { |
||
| 709 | |||
| 710 | // Other |
||
| 711 | |||
| 712 | public function pStmt_Echo(Stmt\Echo_ $node) { |
||
| 715 | |||
| 716 | public function pStmt_Static(Stmt\Static_ $node) { |
||
| 719 | |||
| 720 | public function pStmt_Global(Stmt\Global_ $node) { |
||
| 723 | |||
| 724 | public function pStmt_StaticVar(Stmt\StaticVar $node) { |
||
| 728 | |||
| 729 | public function pStmt_Unset(Stmt\Unset_ $node) { |
||
| 732 | |||
| 733 | public function pStmt_InlineHTML(Stmt\InlineHTML $node) { |
||
| 736 | |||
| 737 | public function pStmt_HaltCompiler(Stmt\HaltCompiler $node) { |
||
| 740 | |||
| 741 | // Helpers |
||
| 742 | |||
| 743 | protected function pType($node) { |
||
| 746 | |||
| 747 | View Code Duplication | protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { |
|
| 748 | return $this->pModifiers($node->type) |
||
| 749 | . 'class' . $afterClassToken |
||
| 750 | . (null !== $node->extends ? ' extends ' . $this->p($node->extends) : '') |
||
| 751 | . (!empty($node->implements) ? ' implements ' . $this->pCommaSeparated($node->implements) : '') |
||
| 752 | . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
||
| 753 | } |
||
| 754 | |||
| 755 | protected function pObjectProperty($node) { |
||
| 756 | if ($node instanceof Expr) { |
||
| 757 | return '{' . $this->p($node) . '}'; |
||
| 758 | } else { |
||
| 759 | return $node; |
||
| 760 | } |
||
| 761 | } |
||
| 762 | |||
| 763 | protected function pModifiers($modifiers) { |
||
| 764 | return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
||
| 765 | . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '') |
||
| 766 | . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '') |
||
| 767 | . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '') |
||
| 768 | . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '') |
||
| 771 | |||
| 772 | protected function pEncapsList(array $encapsList, $quote) { |
||
| 784 | |||
| 785 | protected function pDereferenceLhs(Node $node) { |
||
| 804 | |||
| 805 | protected function pCallLhs(Node $node) { |
||
| 819 | } |
||
| 820 |