@@ -110,6 +110,9 @@ |
||
| 110 | 110 | ); |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | + /** |
|
| 114 | + * @param Name $type |
|
| 115 | + */ |
|
| 113 | 116 | protected function addAlias(Stmt\UseUse $use, $type, Name $prefix = null) { |
| 114 | 117 | // Add prefix for group uses |
| 115 | 118 | $name = $prefix ? Name::concat($prefix, $use->name) : $use->name; |
@@ -51,6 +51,9 @@ |
||
| 51 | 51 | return $this->errors; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | + /** |
|
| 55 | + * @param string $code |
|
| 56 | + */ |
|
| 54 | 57 | private function tryParse(Parser $parser, $code) { |
| 55 | 58 | $stmts = null; |
| 56 | 59 | $error = null; |
@@ -534,6 +534,9 @@ discard block |
||
| 534 | 534 | . ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : ''); |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | + /** |
|
| 538 | + * @param integer $type |
|
| 539 | + */ |
|
| 537 | 540 | private function pUseType($type) { |
| 538 | 541 | return $type === Stmt\Use_::TYPE_FUNCTION ? 'function ' |
| 539 | 542 | : ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : ''); |
@@ -744,6 +747,9 @@ discard block |
||
| 744 | 747 | return is_string($node) ? $node : $this->p($node); |
| 745 | 748 | } |
| 746 | 749 | |
| 750 | + /** |
|
| 751 | + * @param string $afterClassToken |
|
| 752 | + */ |
|
| 747 | 753 | protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { |
| 748 | 754 | return $this->pModifiers($node->type) |
| 749 | 755 | . 'class' . $afterClassToken |
@@ -760,6 +766,9 @@ discard block |
||
| 760 | 766 | } |
| 761 | 767 | } |
| 762 | 768 | |
| 769 | + /** |
|
| 770 | + * @param integer $modifiers |
|
| 771 | + */ |
|
| 763 | 772 | protected function pModifiers($modifiers) { |
| 764 | 773 | return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
| 765 | 774 | . ($modifiers & Stmt\Class_::MODIFIER_PROTECTED ? 'protected ' : '') |
@@ -769,6 +778,9 @@ discard block |
||
| 769 | 778 | . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
| 770 | 779 | } |
| 771 | 780 | |
| 781 | + /** |
|
| 782 | + * @param string $quote |
|
| 783 | + */ |
|
| 772 | 784 | protected function pEncapsList(array $encapsList, $quote) { |
| 773 | 785 | $return = ''; |
| 774 | 786 | foreach ($encapsList as $element) { |
@@ -19,10 +19,10 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function pParam(Node\Param $node) { |
| 21 | 21 | return ($node->type ? $this->pType($node->type) . ' ' : '') |
| 22 | - . ($node->byRef ? '&' : '') |
|
| 23 | - . ($node->variadic ? '...' : '') |
|
| 24 | - . '$' . $node->name |
|
| 25 | - . ($node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 22 | + . ($node->byRef ? '&' : '') |
|
| 23 | + . ($node->variadic ? '...' : '') |
|
| 24 | + . '$' . $node->name |
|
| 25 | + . ($node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public function pArg(Node\Arg $node) { |
@@ -357,22 +357,22 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | public function pExpr_FuncCall(Expr\FuncCall $node) { |
| 359 | 359 | return $this->pCallLhs($node->name) |
| 360 | - . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 360 | + . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | public function pExpr_MethodCall(Expr\MethodCall $node) { |
| 364 | 364 | return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name) |
| 365 | - . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 365 | + . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | public function pExpr_StaticCall(Expr\StaticCall $node) { |
| 369 | 369 | return $this->pDereferenceLhs($node->class) . '::' |
| 370 | - . ($node->name instanceof Expr |
|
| 370 | + . ($node->name instanceof Expr |
|
| 371 | 371 | ? ($node->name instanceof Expr\Variable |
| 372 | 372 | ? $this->p($node->name) |
| 373 | 373 | : '{' . $this->p($node->name) . '}') |
| 374 | 374 | : $node->name) |
| 375 | - . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 375 | + . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | public function pExpr_Empty(Expr\Empty_ $node) { |
@@ -431,12 +431,12 @@ discard block |
||
| 431 | 431 | |
| 432 | 432 | public function pExpr_ArrayItem(Expr\ArrayItem $node) { |
| 433 | 433 | return (null !== $node->key ? $this->p($node->key) . ' => ' : '') |
| 434 | - . ($node->byRef ? '&' : '') . $this->p($node->value); |
|
| 434 | + . ($node->byRef ? '&' : '') . $this->p($node->value); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | public function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) { |
| 438 | 438 | return $this->pDereferenceLhs($node->var) |
| 439 | - . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']'; |
|
| 439 | + . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']'; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | public function pExpr_ConstFetch(Expr\ConstFetch $node) { |
@@ -461,11 +461,11 @@ discard block |
||
| 461 | 461 | |
| 462 | 462 | public function pExpr_Closure(Expr\Closure $node) { |
| 463 | 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" . '}'; |
|
| 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 | 469 | } |
| 470 | 470 | |
| 471 | 471 | public function pExpr_ClosureUse(Expr\ClosureUse $node) { |
@@ -502,9 +502,9 @@ discard block |
||
| 502 | 502 | } else { |
| 503 | 503 | // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary |
| 504 | 504 | return '(yield ' |
| 505 | - . ($node->key !== null ? $this->p($node->key) . ' => ' : '') |
|
| 506 | - . $this->p($node->value) |
|
| 507 | - . ')'; |
|
| 505 | + . ($node->key !== null ? $this->p($node->key) . ' => ' : '') |
|
| 506 | + . $this->p($node->value) |
|
| 507 | + . ')'; |
|
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | |
@@ -515,23 +515,23 @@ discard block |
||
| 515 | 515 | return 'namespace ' . $this->p($node->name) . ';' . "\n" . $this->pStmts($node->stmts, false); |
| 516 | 516 | } else { |
| 517 | 517 | return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') |
| 518 | - . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 518 | + . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 519 | 519 | } |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | public function pStmt_Use(Stmt\Use_ $node) { |
| 523 | 523 | return 'use ' . $this->pUseType($node->type) |
| 524 | - . $this->pCommaSeparated($node->uses) . ';'; |
|
| 524 | + . $this->pCommaSeparated($node->uses) . ';'; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | public function pStmt_GroupUse(Stmt\GroupUse $node) { |
| 528 | 528 | return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix) |
| 529 | - . '\{' . $this->pCommaSeparated($node->uses) . '};'; |
|
| 529 | + . '\{' . $this->pCommaSeparated($node->uses) . '};'; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | public function pStmt_UseUse(Stmt\UseUse $node) { |
| 533 | 533 | return $this->pUseType($node->type) . $this->p($node->name) |
| 534 | - . ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : ''); |
|
| 534 | + . ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : ''); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | private function pUseType($type) { |
@@ -541,8 +541,8 @@ discard block |
||
| 541 | 541 | |
| 542 | 542 | public function pStmt_Interface(Stmt\Interface_ $node) { |
| 543 | 543 | return 'interface ' . $node->name |
| 544 | - . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') |
|
| 545 | - . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 544 | + . (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '') |
|
| 545 | + . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | public function pStmt_Class(Stmt\Class_ $node) { |
@@ -551,27 +551,27 @@ discard block |
||
| 551 | 551 | |
| 552 | 552 | public function pStmt_Trait(Stmt\Trait_ $node) { |
| 553 | 553 | return 'trait ' . $node->name |
| 554 | - . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 554 | + . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | public function pStmt_TraitUse(Stmt\TraitUse $node) { |
| 558 | 558 | return 'use ' . $this->pCommaSeparated($node->traits) |
| 559 | - . (empty($node->adaptations) |
|
| 559 | + . (empty($node->adaptations) |
|
| 560 | 560 | ? ';' |
| 561 | 561 | : ' {' . $this->pStmts($node->adaptations) . "\n" . '}'); |
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | public function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { |
| 565 | 565 | return $this->p($node->trait) . '::' . $node->method |
| 566 | - . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; |
|
| 566 | + . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | public function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) { |
| 570 | 570 | return (null !== $node->trait ? $this->p($node->trait) . '::' : '') |
| 571 | - . $node->method . ' as' |
|
| 572 | - . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') |
|
| 573 | - . (null !== $node->newName ? ' ' . $node->newName : '') |
|
| 574 | - . ';'; |
|
| 571 | + . $node->method . ' as' |
|
| 572 | + . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') |
|
| 573 | + . (null !== $node->newName ? ' ' . $node->newName : '') |
|
| 574 | + . ';'; |
|
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | public function pStmt_Property(Stmt\Property $node) { |
@@ -580,15 +580,15 @@ discard block |
||
| 580 | 580 | |
| 581 | 581 | public function pStmt_PropertyProperty(Stmt\PropertyProperty $node) { |
| 582 | 582 | return '$' . $node->name |
| 583 | - . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 583 | + . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | public function pStmt_ClassMethod(Stmt\ClassMethod $node) { |
| 587 | 587 | return $this->pModifiers($node->type) |
| 588 | - . 'function ' . ($node->byRef ? '&' : '') . $node->name |
|
| 589 | - . '(' . $this->pCommaSeparated($node->params) . ')' |
|
| 590 | - . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
|
| 591 | - . (null !== $node->stmts |
|
| 588 | + . 'function ' . ($node->byRef ? '&' : '') . $node->name |
|
| 589 | + . '(' . $this->pCommaSeparated($node->params) . ')' |
|
| 590 | + . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
|
| 591 | + . (null !== $node->stmts |
|
| 592 | 592 | ? "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}' |
| 593 | 593 | : ';'); |
| 594 | 594 | } |
@@ -599,9 +599,9 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | public function pStmt_Function(Stmt\Function_ $node) { |
| 601 | 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" . '}'; |
|
| 602 | + . '(' . $this->pCommaSeparated($node->params) . ')' |
|
| 603 | + . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
|
| 604 | + . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | public function pStmt_Const(Stmt\Const_ $node) { |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | |
| 611 | 611 | public function pStmt_Declare(Stmt\Declare_ $node) { |
| 612 | 612 | return 'declare (' . $this->pCommaSeparated($node->declares) . ')' |
| 613 | - . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . "\n" . '}' : ';'); |
|
| 613 | + . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . "\n" . '}' : ';'); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | public function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { |
@@ -621,14 +621,14 @@ discard block |
||
| 621 | 621 | |
| 622 | 622 | public function pStmt_If(Stmt\If_ $node) { |
| 623 | 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) : ''); |
|
| 624 | + . $this->pStmts($node->stmts) . "\n" . '}' |
|
| 625 | + . $this->pImplode($node->elseifs) |
|
| 626 | + . (null !== $node->else ? $this->p($node->else) : ''); |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | public function pStmt_ElseIf(Stmt\ElseIf_ $node) { |
| 630 | 630 | return ' elseif (' . $this->p($node->cond) . ') {' |
| 631 | - . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 631 | + . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | public function pStmt_Else(Stmt\Else_ $node) { |
@@ -637,50 +637,50 @@ discard block |
||
| 637 | 637 | |
| 638 | 638 | public function pStmt_For(Stmt\For_ $node) { |
| 639 | 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" . '}'; |
|
| 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 | 644 | } |
| 645 | 645 | |
| 646 | 646 | public function pStmt_Foreach(Stmt\Foreach_ $node) { |
| 647 | 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" . '}'; |
|
| 648 | + . (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '') |
|
| 649 | + . ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {' |
|
| 650 | + . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 651 | 651 | } |
| 652 | 652 | |
| 653 | 653 | public function pStmt_While(Stmt\While_ $node) { |
| 654 | 654 | return 'while (' . $this->p($node->cond) . ') {' |
| 655 | - . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 655 | + . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | public function pStmt_Do(Stmt\Do_ $node) { |
| 659 | 659 | return 'do {' . $this->pStmts($node->stmts) . "\n" |
| 660 | - . '} while (' . $this->p($node->cond) . ');'; |
|
| 660 | + . '} while (' . $this->p($node->cond) . ');'; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | public function pStmt_Switch(Stmt\Switch_ $node) { |
| 664 | 664 | return 'switch (' . $this->p($node->cond) . ') {' |
| 665 | - . $this->pStmts($node->cases) . "\n" . '}'; |
|
| 665 | + . $this->pStmts($node->cases) . "\n" . '}'; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | public function pStmt_Case(Stmt\Case_ $node) { |
| 669 | 669 | return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' |
| 670 | - . $this->pStmts($node->stmts); |
|
| 670 | + . $this->pStmts($node->stmts); |
|
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | public function pStmt_TryCatch(Stmt\TryCatch $node) { |
| 674 | 674 | return 'try {' . $this->pStmts($node->stmts) . "\n" . '}' |
| 675 | - . $this->pImplode($node->catches) |
|
| 676 | - . ($node->finallyStmts !== null |
|
| 675 | + . $this->pImplode($node->catches) |
|
| 676 | + . ($node->finallyStmts !== null |
|
| 677 | 677 | ? ' finally {' . $this->pStmts($node->finallyStmts) . "\n" . '}' |
| 678 | 678 | : ''); |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | public function pStmt_Catch(Stmt\Catch_ $node) { |
| 682 | 682 | return ' catch (' . $this->p($node->type) . ' $' . $node->var . ') {' |
| 683 | - . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 683 | + . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | public function pStmt_Break(Stmt\Break_ $node) { |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | |
| 724 | 724 | public function pStmt_StaticVar(Stmt\StaticVar $node) { |
| 725 | 725 | return '$' . $node->name |
| 726 | - . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 726 | + . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | public function pStmt_Unset(Stmt\Unset_ $node) { |
@@ -762,11 +762,11 @@ discard block |
||
| 762 | 762 | |
| 763 | 763 | protected function pModifiers($modifiers) { |
| 764 | 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 ' : '') |
|
| 769 | - . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
|
| 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 ' : '') |
|
| 769 | + . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | protected function pEncapsList(array $encapsList, $quote) { |
@@ -18,19 +18,19 @@ discard block |
||
| 18 | 18 | // Special nodes |
| 19 | 19 | |
| 20 | 20 | public function pParam(Node\Param $node) { |
| 21 | - return ($node->type ? $this->pType($node->type) . ' ' : '') |
|
| 21 | + return ($node->type ? $this->pType($node->type).' ' : '') |
|
| 22 | 22 | . ($node->byRef ? '&' : '') |
| 23 | 23 | . ($node->variadic ? '...' : '') |
| 24 | - . '$' . $node->name |
|
| 25 | - . ($node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 24 | + . '$'.$node->name |
|
| 25 | + . ($node->default ? ' = '.$this->p($node->default) : ''); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | public 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); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public 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 | 36 | // Names |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function pName_FullyQualified(Name\FullyQualified $node) { |
| 43 | - return '\\' . implode('\\', $node->parts); |
|
| 43 | + return '\\'.implode('\\', $node->parts); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | public function pName_Relative(Name\Relative $node) { |
| 47 | - return 'namespace\\' . implode('\\', $node->parts); |
|
| 47 | + return 'namespace\\'.implode('\\', $node->parts); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // Magic Constants |
@@ -84,11 +84,11 @@ discard block |
||
| 84 | 84 | // Scalars |
| 85 | 85 | |
| 86 | 86 | public function pScalar_String(Scalar\String_ $node) { |
| 87 | - return '\'' . $this->pNoIndent(addcslashes($node->value, '\'\\')) . '\''; |
|
| 87 | + return '\''.$this->pNoIndent(addcslashes($node->value, '\'\\')).'\''; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | public function pScalar_Encapsed(Scalar\Encapsed $node) { |
| 91 | - return '"' . $this->pEncapsList($node->parts, '"') . '"'; |
|
| 91 | + return '"'.$this->pEncapsList($node->parts, '"').'"'; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | public function pScalar_LNumber(Scalar\LNumber $node) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | // ensure that number is really printed as float |
| 105 | - return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue . '.0' : $stringValue; |
|
| 105 | + return preg_match('/^-?[0-9]+$/', $stringValue) ? $stringValue.'.0' : $stringValue; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Assignments |
@@ -357,34 +357,34 @@ discard block |
||
| 357 | 357 | |
| 358 | 358 | public function pExpr_FuncCall(Expr\FuncCall $node) { |
| 359 | 359 | return $this->pCallLhs($node->name) |
| 360 | - . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 360 | + . '('.$this->pCommaSeparated($node->args).')'; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | public function pExpr_MethodCall(Expr\MethodCall $node) { |
| 364 | - return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name) |
|
| 365 | - . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 364 | + return $this->pDereferenceLhs($node->var).'->'.$this->pObjectProperty($node->name) |
|
| 365 | + . '('.$this->pCommaSeparated($node->args).')'; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | public function pExpr_StaticCall(Expr\StaticCall $node) { |
| 369 | - return $this->pDereferenceLhs($node->class) . '::' |
|
| 369 | + return $this->pDereferenceLhs($node->class).'::' |
|
| 370 | 370 | . ($node->name instanceof Expr |
| 371 | 371 | ? ($node->name instanceof Expr\Variable |
| 372 | 372 | ? $this->p($node->name) |
| 373 | - : '{' . $this->p($node->name) . '}') |
|
| 373 | + : '{'.$this->p($node->name).'}') |
|
| 374 | 374 | : $node->name) |
| 375 | - . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 375 | + . '('.$this->pCommaSeparated($node->args).')'; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | public function pExpr_Empty(Expr\Empty_ $node) { |
| 379 | - return 'empty(' . $this->p($node->expr) . ')'; |
|
| 379 | + return 'empty('.$this->p($node->expr).')'; |
|
| 380 | 380 | } |
| 381 | 381 | |
| 382 | 382 | public function pExpr_Isset(Expr\Isset_ $node) { |
| 383 | - return 'isset(' . $this->pCommaSeparated($node->vars) . ')'; |
|
| 383 | + return 'isset('.$this->pCommaSeparated($node->vars).')'; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | public function pExpr_Eval(Expr\Eval_ $node) { |
| 387 | - return 'eval(' . $this->p($node->expr) . ')'; |
|
| 387 | + return 'eval('.$this->p($node->expr).')'; |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | public function pExpr_Include(Expr\Include_ $node) { |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | Expr\Include_::TYPE_REQUIRE_ONCE => 'require_once', |
| 396 | 396 | ); |
| 397 | 397 | |
| 398 | - return $map[$node->type] . ' ' . $this->p($node->expr); |
|
| 398 | + return $map[$node->type].' '.$this->p($node->expr); |
|
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | public function pExpr_List(Expr\List_ $node) { |
@@ -408,35 +408,35 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - return 'list(' . implode(', ', $pList) . ')'; |
|
| 411 | + return 'list('.implode(', ', $pList).')'; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | // Other |
| 415 | 415 | |
| 416 | 416 | public function pExpr_Variable(Expr\Variable $node) { |
| 417 | 417 | if ($node->name instanceof Expr) { |
| 418 | - return '${' . $this->p($node->name) . '}'; |
|
| 418 | + return '${'.$this->p($node->name).'}'; |
|
| 419 | 419 | } else { |
| 420 | - return '$' . $node->name; |
|
| 420 | + return '$'.$node->name; |
|
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | public function pExpr_Array(Expr\Array_ $node) { |
| 425 | 425 | if ($this->options['shortArraySyntax']) { |
| 426 | - return '[' . $this->pCommaSeparated($node->items) . ']'; |
|
| 426 | + return '['.$this->pCommaSeparated($node->items).']'; |
|
| 427 | 427 | } else { |
| 428 | - return 'array(' . $this->pCommaSeparated($node->items) . ')'; |
|
| 428 | + return 'array('.$this->pCommaSeparated($node->items).')'; |
|
| 429 | 429 | } |
| 430 | 430 | } |
| 431 | 431 | |
| 432 | 432 | public function pExpr_ArrayItem(Expr\ArrayItem $node) { |
| 433 | - return (null !== $node->key ? $this->p($node->key) . ' => ' : '') |
|
| 434 | - . ($node->byRef ? '&' : '') . $this->p($node->value); |
|
| 433 | + return (null !== $node->key ? $this->p($node->key).' => ' : '') |
|
| 434 | + . ($node->byRef ? '&' : '').$this->p($node->value); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | public function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) { |
| 438 | 438 | return $this->pDereferenceLhs($node->var) |
| 439 | - . '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']'; |
|
| 439 | + . '['.(null !== $node->dim ? $this->p($node->dim) : '').']'; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | public function pExpr_ConstFetch(Expr\ConstFetch $node) { |
@@ -444,56 +444,56 @@ discard block |
||
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | public function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) { |
| 447 | - return $this->p($node->class) . '::' . $node->name; |
|
| 447 | + return $this->p($node->class).'::'.$node->name; |
|
| 448 | 448 | } |
| 449 | 449 | |
| 450 | 450 | public function pExpr_PropertyFetch(Expr\PropertyFetch $node) { |
| 451 | - return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name); |
|
| 451 | + return $this->pDereferenceLhs($node->var).'->'.$this->pObjectProperty($node->name); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | public function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) { |
| 455 | - return $this->pDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name); |
|
| 455 | + return $this->pDereferenceLhs($node->class).'::$'.$this->pObjectProperty($node->name); |
|
| 456 | 456 | } |
| 457 | 457 | |
| 458 | 458 | public function pExpr_ShellExec(Expr\ShellExec $node) { |
| 459 | - return '`' . $this->pEncapsList($node->parts, '`') . '`'; |
|
| 459 | + return '`'.$this->pEncapsList($node->parts, '`').'`'; |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | public function pExpr_Closure(Expr\Closure $node) { |
| 463 | 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" . '}'; |
|
| 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 | 469 | } |
| 470 | 470 | |
| 471 | 471 | public function pExpr_ClosureUse(Expr\ClosureUse $node) { |
| 472 | - return ($node->byRef ? '&' : '') . '$' . $node->var; |
|
| 472 | + return ($node->byRef ? '&' : '').'$'.$node->var; |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | public function pExpr_New(Expr\New_ $node) { |
| 476 | 476 | if ($node->class instanceof Stmt\Class_) { |
| 477 | - $args = $node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : ''; |
|
| 478 | - return 'new ' . $this->pClassCommon($node->class, $args); |
|
| 477 | + $args = $node->args ? '('.$this->pCommaSeparated($node->args).')' : ''; |
|
| 478 | + return 'new '.$this->pClassCommon($node->class, $args); |
|
| 479 | 479 | } |
| 480 | - return 'new ' . $this->p($node->class) . '(' . $this->pCommaSeparated($node->args) . ')'; |
|
| 480 | + return 'new '.$this->p($node->class).'('.$this->pCommaSeparated($node->args).')'; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | public function pExpr_Clone(Expr\Clone_ $node) { |
| 484 | - return 'clone ' . $this->p($node->expr); |
|
| 484 | + return 'clone '.$this->p($node->expr); |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | public function pExpr_Ternary(Expr\Ternary $node) { |
| 488 | 488 | // a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator. |
| 489 | 489 | // this is okay because the part between ? and : never needs parentheses. |
| 490 | 490 | return $this->pInfixOp('Expr_Ternary', |
| 491 | - $node->cond, ' ?' . (null !== $node->if ? ' ' . $this->p($node->if) . ' ' : '') . ': ', $node->else |
|
| 491 | + $node->cond, ' ?'.(null !== $node->if ? ' '.$this->p($node->if).' ' : '').': ', $node->else |
|
| 492 | 492 | ); |
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | public function pExpr_Exit(Expr\Exit_ $node) { |
| 496 | - return 'die' . (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : ''); |
|
| 496 | + return 'die'.(null !== $node->expr ? '('.$this->p($node->expr).')' : ''); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | public function pExpr_Yield(Expr\Yield_ $node) { |
@@ -502,7 +502,7 @@ discard block |
||
| 502 | 502 | } else { |
| 503 | 503 | // this is a bit ugly, but currently there is no way to detect whether the parentheses are necessary |
| 504 | 504 | return '(yield ' |
| 505 | - . ($node->key !== null ? $this->p($node->key) . ' => ' : '') |
|
| 505 | + . ($node->key !== null ? $this->p($node->key).' => ' : '') |
|
| 506 | 506 | . $this->p($node->value) |
| 507 | 507 | . ')'; |
| 508 | 508 | } |
@@ -512,26 +512,26 @@ discard block |
||
| 512 | 512 | |
| 513 | 513 | public function pStmt_Namespace(Stmt\Namespace_ $node) { |
| 514 | 514 | if ($this->canUseSemicolonNamespaces) { |
| 515 | - return 'namespace ' . $this->p($node->name) . ';' . "\n" . $this->pStmts($node->stmts, false); |
|
| 515 | + return 'namespace '.$this->p($node->name).';'."\n".$this->pStmts($node->stmts, false); |
|
| 516 | 516 | } else { |
| 517 | - return 'namespace' . (null !== $node->name ? ' ' . $this->p($node->name) : '') |
|
| 518 | - . ' {' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 517 | + return 'namespace'.(null !== $node->name ? ' '.$this->p($node->name) : '') |
|
| 518 | + . ' {'.$this->pStmts($node->stmts)."\n".'}'; |
|
| 519 | 519 | } |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | 522 | public function pStmt_Use(Stmt\Use_ $node) { |
| 523 | - return 'use ' . $this->pUseType($node->type) |
|
| 524 | - . $this->pCommaSeparated($node->uses) . ';'; |
|
| 523 | + return 'use '.$this->pUseType($node->type) |
|
| 524 | + . $this->pCommaSeparated($node->uses).';'; |
|
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | public function pStmt_GroupUse(Stmt\GroupUse $node) { |
| 528 | - return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix) |
|
| 529 | - . '\{' . $this->pCommaSeparated($node->uses) . '};'; |
|
| 528 | + return 'use '.$this->pUseType($node->type).$this->pName($node->prefix) |
|
| 529 | + . '\{'.$this->pCommaSeparated($node->uses).'};'; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | public function pStmt_UseUse(Stmt\UseUse $node) { |
| 533 | - return $this->pUseType($node->type) . $this->p($node->name) |
|
| 534 | - . ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : ''); |
|
| 533 | + return $this->pUseType($node->type).$this->p($node->name) |
|
| 534 | + . ($node->name->getLast() !== $node->alias ? ' as '.$node->alias : ''); |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | private function pUseType($type) { |
@@ -540,202 +540,202 @@ discard block |
||
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 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" . '}'; |
|
| 543 | + return 'interface '.$node->name |
|
| 544 | + . (!empty($node->extends) ? ' extends '.$this->pCommaSeparated($node->extends) : '') |
|
| 545 | + . "\n".'{'.$this->pStmts($node->stmts)."\n".'}'; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | public function pStmt_Class(Stmt\Class_ $node) { |
| 549 | - return $this->pClassCommon($node, ' ' . $node->name); |
|
| 549 | + return $this->pClassCommon($node, ' '.$node->name); |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | public function pStmt_Trait(Stmt\Trait_ $node) { |
| 553 | - return 'trait ' . $node->name |
|
| 554 | - . "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 553 | + return 'trait '.$node->name |
|
| 554 | + . "\n".'{'.$this->pStmts($node->stmts)."\n".'}'; |
|
| 555 | 555 | } |
| 556 | 556 | |
| 557 | 557 | public function pStmt_TraitUse(Stmt\TraitUse $node) { |
| 558 | - return 'use ' . $this->pCommaSeparated($node->traits) |
|
| 558 | + return 'use '.$this->pCommaSeparated($node->traits) |
|
| 559 | 559 | . (empty($node->adaptations) |
| 560 | 560 | ? ';' |
| 561 | - : ' {' . $this->pStmts($node->adaptations) . "\n" . '}'); |
|
| 561 | + : ' {'.$this->pStmts($node->adaptations)."\n".'}'); |
|
| 562 | 562 | } |
| 563 | 563 | |
| 564 | 564 | public function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) { |
| 565 | - return $this->p($node->trait) . '::' . $node->method |
|
| 566 | - . ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';'; |
|
| 565 | + return $this->p($node->trait).'::'.$node->method |
|
| 566 | + . ' insteadof '.$this->pCommaSeparated($node->insteadof).';'; |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | public function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) { |
| 570 | - return (null !== $node->trait ? $this->p($node->trait) . '::' : '') |
|
| 571 | - . $node->method . ' as' |
|
| 572 | - . (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '') |
|
| 573 | - . (null !== $node->newName ? ' ' . $node->newName : '') |
|
| 570 | + return (null !== $node->trait ? $this->p($node->trait).'::' : '') |
|
| 571 | + . $node->method.' as' |
|
| 572 | + . (null !== $node->newModifier ? ' '.rtrim($this->pModifiers($node->newModifier), ' ') : '') |
|
| 573 | + . (null !== $node->newName ? ' '.$node->newName : '') |
|
| 574 | 574 | . ';'; |
| 575 | 575 | } |
| 576 | 576 | |
| 577 | 577 | public function pStmt_Property(Stmt\Property $node) { |
| 578 | - return (0 === $node->type ? 'var ' : $this->pModifiers($node->type)) . $this->pCommaSeparated($node->props) . ';'; |
|
| 578 | + return (0 === $node->type ? 'var ' : $this->pModifiers($node->type)).$this->pCommaSeparated($node->props).';'; |
|
| 579 | 579 | } |
| 580 | 580 | |
| 581 | 581 | public function pStmt_PropertyProperty(Stmt\PropertyProperty $node) { |
| 582 | - return '$' . $node->name |
|
| 583 | - . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 582 | + return '$'.$node->name |
|
| 583 | + . (null !== $node->default ? ' = '.$this->p($node->default) : ''); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | public function pStmt_ClassMethod(Stmt\ClassMethod $node) { |
| 587 | 587 | return $this->pModifiers($node->type) |
| 588 | - . 'function ' . ($node->byRef ? '&' : '') . $node->name |
|
| 589 | - . '(' . $this->pCommaSeparated($node->params) . ')' |
|
| 590 | - . (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '') |
|
| 588 | + . 'function '.($node->byRef ? '&' : '').$node->name |
|
| 589 | + . '('.$this->pCommaSeparated($node->params).')' |
|
| 590 | + . (null !== $node->returnType ? ' : '.$this->pType($node->returnType) : '') |
|
| 591 | 591 | . (null !== $node->stmts |
| 592 | - ? "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}' |
|
| 592 | + ? "\n".'{'.$this->pStmts($node->stmts)."\n".'}' |
|
| 593 | 593 | : ';'); |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | public function pStmt_ClassConst(Stmt\ClassConst $node) { |
| 597 | - return 'const ' . $this->pCommaSeparated($node->consts) . ';'; |
|
| 597 | + return 'const '.$this->pCommaSeparated($node->consts).';'; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 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" . '}'; |
|
| 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 | 605 | } |
| 606 | 606 | |
| 607 | 607 | public function pStmt_Const(Stmt\Const_ $node) { |
| 608 | - return 'const ' . $this->pCommaSeparated($node->consts) . ';'; |
|
| 608 | + return 'const '.$this->pCommaSeparated($node->consts).';'; |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | public function pStmt_Declare(Stmt\Declare_ $node) { |
| 612 | - return 'declare (' . $this->pCommaSeparated($node->declares) . ')' |
|
| 613 | - . (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . "\n" . '}' : ';'); |
|
| 612 | + return 'declare ('.$this->pCommaSeparated($node->declares).')' |
|
| 613 | + . (null !== $node->stmts ? ' {'.$this->pStmts($node->stmts)."\n".'}' : ';'); |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | public function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) { |
| 617 | - return $node->key . '=' . $this->p($node->value); |
|
| 617 | + return $node->key.'='.$this->p($node->value); |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | // Control flow |
| 621 | 621 | |
| 622 | 622 | public function pStmt_If(Stmt\If_ $node) { |
| 623 | - return 'if (' . $this->p($node->cond) . ') {' |
|
| 624 | - . $this->pStmts($node->stmts) . "\n" . '}' |
|
| 623 | + return 'if ('.$this->p($node->cond).') {' |
|
| 624 | + . $this->pStmts($node->stmts)."\n".'}' |
|
| 625 | 625 | . $this->pImplode($node->elseifs) |
| 626 | 626 | . (null !== $node->else ? $this->p($node->else) : ''); |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | public function pStmt_ElseIf(Stmt\ElseIf_ $node) { |
| 630 | - return ' elseif (' . $this->p($node->cond) . ') {' |
|
| 631 | - . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 630 | + return ' elseif ('.$this->p($node->cond).') {' |
|
| 631 | + . $this->pStmts($node->stmts)."\n".'}'; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | public function pStmt_Else(Stmt\Else_ $node) { |
| 635 | - return ' else {' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 635 | + return ' else {'.$this->pStmts($node->stmts)."\n".'}'; |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | public function pStmt_For(Stmt\For_ $node) { |
| 639 | 639 | return 'for (' |
| 640 | - . $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '') |
|
| 641 | - . $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '') |
|
| 640 | + . $this->pCommaSeparated($node->init).';'.(!empty($node->cond) ? ' ' : '') |
|
| 641 | + . $this->pCommaSeparated($node->cond).';'.(!empty($node->loop) ? ' ' : '') |
|
| 642 | 642 | . $this->pCommaSeparated($node->loop) |
| 643 | - . ') {' . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 643 | + . ') {'.$this->pStmts($node->stmts)."\n".'}'; |
|
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 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" . '}'; |
|
| 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 | 651 | } |
| 652 | 652 | |
| 653 | 653 | public function pStmt_While(Stmt\While_ $node) { |
| 654 | - return 'while (' . $this->p($node->cond) . ') {' |
|
| 655 | - . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 654 | + return 'while ('.$this->p($node->cond).') {' |
|
| 655 | + . $this->pStmts($node->stmts)."\n".'}'; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | public function pStmt_Do(Stmt\Do_ $node) { |
| 659 | - return 'do {' . $this->pStmts($node->stmts) . "\n" |
|
| 660 | - . '} while (' . $this->p($node->cond) . ');'; |
|
| 659 | + return 'do {'.$this->pStmts($node->stmts)."\n" |
|
| 660 | + . '} while ('.$this->p($node->cond).');'; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | public function pStmt_Switch(Stmt\Switch_ $node) { |
| 664 | - return 'switch (' . $this->p($node->cond) . ') {' |
|
| 665 | - . $this->pStmts($node->cases) . "\n" . '}'; |
|
| 664 | + return 'switch ('.$this->p($node->cond).') {' |
|
| 665 | + . $this->pStmts($node->cases)."\n".'}'; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | public function pStmt_Case(Stmt\Case_ $node) { |
| 669 | - return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':' |
|
| 669 | + return (null !== $node->cond ? 'case '.$this->p($node->cond) : 'default').':' |
|
| 670 | 670 | . $this->pStmts($node->stmts); |
| 671 | 671 | } |
| 672 | 672 | |
| 673 | 673 | public function pStmt_TryCatch(Stmt\TryCatch $node) { |
| 674 | - return 'try {' . $this->pStmts($node->stmts) . "\n" . '}' |
|
| 674 | + return 'try {'.$this->pStmts($node->stmts)."\n".'}' |
|
| 675 | 675 | . $this->pImplode($node->catches) |
| 676 | 676 | . ($node->finallyStmts !== null |
| 677 | - ? ' finally {' . $this->pStmts($node->finallyStmts) . "\n" . '}' |
|
| 677 | + ? ' finally {'.$this->pStmts($node->finallyStmts)."\n".'}' |
|
| 678 | 678 | : ''); |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | public function pStmt_Catch(Stmt\Catch_ $node) { |
| 682 | - return ' catch (' . $this->p($node->type) . ' $' . $node->var . ') {' |
|
| 683 | - . $this->pStmts($node->stmts) . "\n" . '}'; |
|
| 682 | + return ' catch ('.$this->p($node->type).' $'.$node->var.') {' |
|
| 683 | + . $this->pStmts($node->stmts)."\n".'}'; |
|
| 684 | 684 | } |
| 685 | 685 | |
| 686 | 686 | public function pStmt_Break(Stmt\Break_ $node) { |
| 687 | - return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; |
|
| 687 | + return 'break'.($node->num !== null ? ' '.$this->p($node->num) : '').';'; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | public function pStmt_Continue(Stmt\Continue_ $node) { |
| 691 | - return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';'; |
|
| 691 | + return 'continue'.($node->num !== null ? ' '.$this->p($node->num) : '').';'; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | public function pStmt_Return(Stmt\Return_ $node) { |
| 695 | - return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';'; |
|
| 695 | + return 'return'.(null !== $node->expr ? ' '.$this->p($node->expr) : '').';'; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | public function pStmt_Throw(Stmt\Throw_ $node) { |
| 699 | - return 'throw ' . $this->p($node->expr) . ';'; |
|
| 699 | + return 'throw '.$this->p($node->expr).';'; |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | public function pStmt_Label(Stmt\Label $node) { |
| 703 | - return $node->name . ':'; |
|
| 703 | + return $node->name.':'; |
|
| 704 | 704 | } |
| 705 | 705 | |
| 706 | 706 | public function pStmt_Goto(Stmt\Goto_ $node) { |
| 707 | - return 'goto ' . $node->name . ';'; |
|
| 707 | + return 'goto '.$node->name.';'; |
|
| 708 | 708 | } |
| 709 | 709 | |
| 710 | 710 | // Other |
| 711 | 711 | |
| 712 | 712 | public function pStmt_Echo(Stmt\Echo_ $node) { |
| 713 | - return 'echo ' . $this->pCommaSeparated($node->exprs) . ';'; |
|
| 713 | + return 'echo '.$this->pCommaSeparated($node->exprs).';'; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | public function pStmt_Static(Stmt\Static_ $node) { |
| 717 | - return 'static ' . $this->pCommaSeparated($node->vars) . ';'; |
|
| 717 | + return 'static '.$this->pCommaSeparated($node->vars).';'; |
|
| 718 | 718 | } |
| 719 | 719 | |
| 720 | 720 | public function pStmt_Global(Stmt\Global_ $node) { |
| 721 | - return 'global ' . $this->pCommaSeparated($node->vars) . ';'; |
|
| 721 | + return 'global '.$this->pCommaSeparated($node->vars).';'; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | public function pStmt_StaticVar(Stmt\StaticVar $node) { |
| 725 | - return '$' . $node->name |
|
| 726 | - . (null !== $node->default ? ' = ' . $this->p($node->default) : ''); |
|
| 725 | + return '$'.$node->name |
|
| 726 | + . (null !== $node->default ? ' = '.$this->p($node->default) : ''); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | public function pStmt_Unset(Stmt\Unset_ $node) { |
| 730 | - return 'unset(' . $this->pCommaSeparated($node->vars) . ');'; |
|
| 730 | + return 'unset('.$this->pCommaSeparated($node->vars).');'; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | public function pStmt_InlineHTML(Stmt\InlineHTML $node) { |
| 734 | - return '?>' . $this->pNoIndent("\n" . $node->value) . '<?php '; |
|
| 734 | + return '?>'.$this->pNoIndent("\n".$node->value).'<?php '; |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | public function pStmt_HaltCompiler(Stmt\HaltCompiler $node) { |
| 738 | - return '__halt_compiler();' . $node->remaining; |
|
| 738 | + return '__halt_compiler();'.$node->remaining; |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | // Helpers |
@@ -746,36 +746,36 @@ discard block |
||
| 746 | 746 | |
| 747 | 747 | protected function pClassCommon(Stmt\Class_ $node, $afterClassToken) { |
| 748 | 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" . '}'; |
|
| 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 | 753 | } |
| 754 | 754 | |
| 755 | 755 | protected function pObjectProperty($node) { |
| 756 | 756 | if ($node instanceof Expr) { |
| 757 | - return '{' . $this->p($node) . '}'; |
|
| 757 | + return '{'.$this->p($node).'}'; |
|
| 758 | 758 | } else { |
| 759 | 759 | return $node; |
| 760 | 760 | } |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | protected function pModifiers($modifiers) { |
| 764 | - return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
|
| 764 | + return ($modifiers & Stmt\Class_::MODIFIER_PUBLIC ? 'public ' : '') |
|
| 765 | 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 ' : '') |
|
| 769 | - . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
|
| 766 | + . ($modifiers & Stmt\Class_::MODIFIER_PRIVATE ? 'private ' : '') |
|
| 767 | + . ($modifiers & Stmt\Class_::MODIFIER_STATIC ? 'static ' : '') |
|
| 768 | + . ($modifiers & Stmt\Class_::MODIFIER_ABSTRACT ? 'abstract ' : '') |
|
| 769 | + . ($modifiers & Stmt\Class_::MODIFIER_FINAL ? 'final ' : ''); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | protected function pEncapsList(array $encapsList, $quote) { |
| 773 | 773 | $return = ''; |
| 774 | 774 | foreach ($encapsList as $element) { |
| 775 | 775 | if ($element instanceof Scalar\EncapsedStringPart) { |
| 776 | - $return .= addcslashes($element->value, "\n\r\t\f\v$" . $quote . "\\"); |
|
| 776 | + $return .= addcslashes($element->value, "\n\r\t\f\v$".$quote."\\"); |
|
| 777 | 777 | } else { |
| 778 | - $return .= '{' . $this->p($element) . '}'; |
|
| 778 | + $return .= '{'.$this->p($element).'}'; |
|
| 779 | 779 | } |
| 780 | 780 | } |
| 781 | 781 | |
@@ -797,8 +797,8 @@ discard block |
||
| 797 | 797 | || $node instanceof Expr\ClassConstFetch |
| 798 | 798 | ) { |
| 799 | 799 | return $this->p($node); |
| 800 | - } else { |
|
| 801 | - return '(' . $this->p($node) . ')'; |
|
| 800 | + } else { |
|
| 801 | + return '('.$this->p($node).')'; |
|
| 802 | 802 | } |
| 803 | 803 | } |
| 804 | 804 | |
@@ -812,8 +812,8 @@ discard block |
||
| 812 | 812 | || $node instanceof Expr\Array_ |
| 813 | 813 | ) { |
| 814 | 814 | return $this->p($node); |
| 815 | - } else { |
|
| 816 | - return '(' . $this->p($node) . ')'; |
|
| 815 | + } else { |
|
| 816 | + return '('.$this->p($node).')'; |
|
| 817 | 817 | } |
| 818 | 818 | } |
| 819 | 819 | } |
@@ -191,6 +191,10 @@ discard block |
||
| 191 | 191 | return $this->{'p' . $node->getType()}($node); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | + /** |
|
| 195 | + * @param string $type |
|
| 196 | + * @param string $operatorString |
|
| 197 | + */ |
|
| 194 | 198 | protected function pInfixOp($type, Node $leftNode, $operatorString, Node $rightNode) { |
| 195 | 199 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
| 196 | 200 | |
@@ -199,11 +203,19 @@ discard block |
||
| 199 | 203 | . $this->pPrec($rightNode, $precedence, $associativity, 1); |
| 200 | 204 | } |
| 201 | 205 | |
| 206 | + /** |
|
| 207 | + * @param string $type |
|
| 208 | + * @param string $operatorString |
|
| 209 | + */ |
|
| 202 | 210 | protected function pPrefixOp($type, $operatorString, Node $node) { |
| 203 | 211 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
| 204 | 212 | return $operatorString . $this->pPrec($node, $precedence, $associativity, 1); |
| 205 | 213 | } |
| 206 | 214 | |
| 215 | + /** |
|
| 216 | + * @param string $type |
|
| 217 | + * @param string $operatorString |
|
| 218 | + */ |
|
| 207 | 219 | protected function pPostfixOp($type, Node $node, $operatorString) { |
| 208 | 220 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
| 209 | 221 | return $this->pPrec($node, $precedence, $associativity, -1) . $operatorString; |
@@ -195,8 +195,8 @@ |
||
| 195 | 195 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
| 196 | 196 | |
| 197 | 197 | return $this->pPrec($leftNode, $precedence, $associativity, -1) |
| 198 | - . $operatorString |
|
| 199 | - . $this->pPrec($rightNode, $precedence, $associativity, 1); |
|
| 198 | + . $operatorString |
|
| 199 | + . $this->pPrec($rightNode, $precedence, $associativity, 1); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | protected function pPrefixOp($type, $operatorString, Node $node) { |
@@ -9,65 +9,65 @@ discard block |
||
| 9 | 9 | { |
| 10 | 10 | protected $precedenceMap = array( |
| 11 | 11 | // [precedence, associativity] where for the latter -1 is %left, 0 is %nonassoc and 1 is %right |
| 12 | - 'Expr_BinaryOp_Pow' => array( 0, 1), |
|
| 13 | - 'Expr_BitwiseNot' => array( 10, 1), |
|
| 14 | - 'Expr_PreInc' => array( 10, 1), |
|
| 15 | - 'Expr_PreDec' => array( 10, 1), |
|
| 16 | - 'Expr_PostInc' => array( 10, -1), |
|
| 17 | - 'Expr_PostDec' => array( 10, -1), |
|
| 18 | - 'Expr_UnaryPlus' => array( 10, 1), |
|
| 19 | - 'Expr_UnaryMinus' => array( 10, 1), |
|
| 20 | - 'Expr_Cast_Int' => array( 10, 1), |
|
| 21 | - 'Expr_Cast_Double' => array( 10, 1), |
|
| 22 | - 'Expr_Cast_String' => array( 10, 1), |
|
| 23 | - 'Expr_Cast_Array' => array( 10, 1), |
|
| 24 | - 'Expr_Cast_Object' => array( 10, 1), |
|
| 25 | - 'Expr_Cast_Bool' => array( 10, 1), |
|
| 26 | - 'Expr_Cast_Unset' => array( 10, 1), |
|
| 27 | - 'Expr_ErrorSuppress' => array( 10, 1), |
|
| 28 | - 'Expr_Instanceof' => array( 20, 0), |
|
| 29 | - 'Expr_BooleanNot' => array( 30, 1), |
|
| 30 | - 'Expr_BinaryOp_Mul' => array( 40, -1), |
|
| 31 | - 'Expr_BinaryOp_Div' => array( 40, -1), |
|
| 32 | - 'Expr_BinaryOp_Mod' => array( 40, -1), |
|
| 33 | - 'Expr_BinaryOp_Plus' => array( 50, -1), |
|
| 34 | - 'Expr_BinaryOp_Minus' => array( 50, -1), |
|
| 35 | - 'Expr_BinaryOp_Concat' => array( 50, -1), |
|
| 36 | - 'Expr_BinaryOp_ShiftLeft' => array( 60, -1), |
|
| 37 | - 'Expr_BinaryOp_ShiftRight' => array( 60, -1), |
|
| 38 | - 'Expr_BinaryOp_Smaller' => array( 70, 0), |
|
| 39 | - 'Expr_BinaryOp_SmallerOrEqual' => array( 70, 0), |
|
| 40 | - 'Expr_BinaryOp_Greater' => array( 70, 0), |
|
| 41 | - 'Expr_BinaryOp_GreaterOrEqual' => array( 70, 0), |
|
| 42 | - 'Expr_BinaryOp_Equal' => array( 80, 0), |
|
| 43 | - 'Expr_BinaryOp_NotEqual' => array( 80, 0), |
|
| 44 | - 'Expr_BinaryOp_Identical' => array( 80, 0), |
|
| 45 | - 'Expr_BinaryOp_NotIdentical' => array( 80, 0), |
|
| 46 | - 'Expr_BinaryOp_Spaceship' => array( 80, 0), |
|
| 47 | - 'Expr_BinaryOp_BitwiseAnd' => array( 90, -1), |
|
| 12 | + 'Expr_BinaryOp_Pow' => array(0, 1), |
|
| 13 | + 'Expr_BitwiseNot' => array(10, 1), |
|
| 14 | + 'Expr_PreInc' => array(10, 1), |
|
| 15 | + 'Expr_PreDec' => array(10, 1), |
|
| 16 | + 'Expr_PostInc' => array(10, -1), |
|
| 17 | + 'Expr_PostDec' => array(10, -1), |
|
| 18 | + 'Expr_UnaryPlus' => array(10, 1), |
|
| 19 | + 'Expr_UnaryMinus' => array(10, 1), |
|
| 20 | + 'Expr_Cast_Int' => array(10, 1), |
|
| 21 | + 'Expr_Cast_Double' => array(10, 1), |
|
| 22 | + 'Expr_Cast_String' => array(10, 1), |
|
| 23 | + 'Expr_Cast_Array' => array(10, 1), |
|
| 24 | + 'Expr_Cast_Object' => array(10, 1), |
|
| 25 | + 'Expr_Cast_Bool' => array(10, 1), |
|
| 26 | + 'Expr_Cast_Unset' => array(10, 1), |
|
| 27 | + 'Expr_ErrorSuppress' => array(10, 1), |
|
| 28 | + 'Expr_Instanceof' => array(20, 0), |
|
| 29 | + 'Expr_BooleanNot' => array(30, 1), |
|
| 30 | + 'Expr_BinaryOp_Mul' => array(40, -1), |
|
| 31 | + 'Expr_BinaryOp_Div' => array(40, -1), |
|
| 32 | + 'Expr_BinaryOp_Mod' => array(40, -1), |
|
| 33 | + 'Expr_BinaryOp_Plus' => array(50, -1), |
|
| 34 | + 'Expr_BinaryOp_Minus' => array(50, -1), |
|
| 35 | + 'Expr_BinaryOp_Concat' => array(50, -1), |
|
| 36 | + 'Expr_BinaryOp_ShiftLeft' => array(60, -1), |
|
| 37 | + 'Expr_BinaryOp_ShiftRight' => array(60, -1), |
|
| 38 | + 'Expr_BinaryOp_Smaller' => array(70, 0), |
|
| 39 | + 'Expr_BinaryOp_SmallerOrEqual' => array(70, 0), |
|
| 40 | + 'Expr_BinaryOp_Greater' => array(70, 0), |
|
| 41 | + 'Expr_BinaryOp_GreaterOrEqual' => array(70, 0), |
|
| 42 | + 'Expr_BinaryOp_Equal' => array(80, 0), |
|
| 43 | + 'Expr_BinaryOp_NotEqual' => array(80, 0), |
|
| 44 | + 'Expr_BinaryOp_Identical' => array(80, 0), |
|
| 45 | + 'Expr_BinaryOp_NotIdentical' => array(80, 0), |
|
| 46 | + 'Expr_BinaryOp_Spaceship' => array(80, 0), |
|
| 47 | + 'Expr_BinaryOp_BitwiseAnd' => array(90, -1), |
|
| 48 | 48 | 'Expr_BinaryOp_BitwiseXor' => array(100, -1), |
| 49 | 49 | 'Expr_BinaryOp_BitwiseOr' => array(110, -1), |
| 50 | 50 | 'Expr_BinaryOp_BooleanAnd' => array(120, -1), |
| 51 | 51 | 'Expr_BinaryOp_BooleanOr' => array(130, -1), |
| 52 | - 'Expr_BinaryOp_Coalesce' => array(140, 1), |
|
| 52 | + 'Expr_BinaryOp_Coalesce' => array(140, 1), |
|
| 53 | 53 | 'Expr_Ternary' => array(150, -1), |
| 54 | 54 | // parser uses %left for assignments, but they really behave as %right |
| 55 | - 'Expr_Assign' => array(160, 1), |
|
| 56 | - 'Expr_AssignRef' => array(160, 1), |
|
| 57 | - 'Expr_AssignOp_Plus' => array(160, 1), |
|
| 58 | - 'Expr_AssignOp_Minus' => array(160, 1), |
|
| 59 | - 'Expr_AssignOp_Mul' => array(160, 1), |
|
| 60 | - 'Expr_AssignOp_Div' => array(160, 1), |
|
| 61 | - 'Expr_AssignOp_Concat' => array(160, 1), |
|
| 62 | - 'Expr_AssignOp_Mod' => array(160, 1), |
|
| 63 | - 'Expr_AssignOp_BitwiseAnd' => array(160, 1), |
|
| 64 | - 'Expr_AssignOp_BitwiseOr' => array(160, 1), |
|
| 65 | - 'Expr_AssignOp_BitwiseXor' => array(160, 1), |
|
| 66 | - 'Expr_AssignOp_ShiftLeft' => array(160, 1), |
|
| 67 | - 'Expr_AssignOp_ShiftRight' => array(160, 1), |
|
| 68 | - 'Expr_AssignOp_Pow' => array(160, 1), |
|
| 69 | - 'Expr_YieldFrom' => array(165, 1), |
|
| 70 | - 'Expr_Print' => array(168, 1), |
|
| 55 | + 'Expr_Assign' => array(160, 1), |
|
| 56 | + 'Expr_AssignRef' => array(160, 1), |
|
| 57 | + 'Expr_AssignOp_Plus' => array(160, 1), |
|
| 58 | + 'Expr_AssignOp_Minus' => array(160, 1), |
|
| 59 | + 'Expr_AssignOp_Mul' => array(160, 1), |
|
| 60 | + 'Expr_AssignOp_Div' => array(160, 1), |
|
| 61 | + 'Expr_AssignOp_Concat' => array(160, 1), |
|
| 62 | + 'Expr_AssignOp_Mod' => array(160, 1), |
|
| 63 | + 'Expr_AssignOp_BitwiseAnd' => array(160, 1), |
|
| 64 | + 'Expr_AssignOp_BitwiseOr' => array(160, 1), |
|
| 65 | + 'Expr_AssignOp_BitwiseXor' => array(160, 1), |
|
| 66 | + 'Expr_AssignOp_ShiftLeft' => array(160, 1), |
|
| 67 | + 'Expr_AssignOp_ShiftRight' => array(160, 1), |
|
| 68 | + 'Expr_AssignOp_Pow' => array(160, 1), |
|
| 69 | + 'Expr_YieldFrom' => array(165, 1), |
|
| 70 | + 'Expr_Print' => array(168, 1), |
|
| 71 | 71 | 'Expr_BinaryOp_LogicalAnd' => array(170, -1), |
| 72 | 72 | 'Expr_BinaryOp_LogicalXor' => array(180, -1), |
| 73 | 73 | 'Expr_BinaryOp_LogicalOr' => array(190, -1), |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * @param array $options Dictionary of formatting options |
| 88 | 88 | */ |
| 89 | 89 | public function __construct(array $options = []) { |
| 90 | - $this->noIndentToken = '_NO_INDENT_' . mt_rand(); |
|
| 90 | + $this->noIndentToken = '_NO_INDENT_'.mt_rand(); |
|
| 91 | 91 | |
| 92 | 92 | $defaultOptions = ['shortArraySyntax' => false]; |
| 93 | 93 | $this->options = $options + $defaultOptions; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | public function prettyPrint(array $stmts) { |
| 104 | 104 | $this->preprocessNodes($stmts); |
| 105 | 105 | |
| 106 | - return ltrim(str_replace("\n" . $this->noIndentToken, "\n", $this->pStmts($stmts, false))); |
|
| 106 | + return ltrim(str_replace("\n".$this->noIndentToken, "\n", $this->pStmts($stmts, false))); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @return string Pretty printed node |
| 115 | 115 | */ |
| 116 | 116 | public function prettyPrintExpr(Expr $node) { |
| 117 | - return str_replace("\n" . $this->noIndentToken, "\n", $this->p($node)); |
|
| 117 | + return str_replace("\n".$this->noIndentToken, "\n", $this->p($node)); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return "<?php\n\n"; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - $p = "<?php\n\n" . $this->prettyPrint($stmts); |
|
| 132 | + $p = "<?php\n\n".$this->prettyPrint($stmts); |
|
| 133 | 133 | |
| 134 | 134 | if ($stmts[0] instanceof Stmt\InlineHTML) { |
| 135 | 135 | $p = preg_replace('/^<\?php\s+\?>\n?/', '', $p); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | if ($indent) { |
| 177 | - return preg_replace('~\n(?!$|' . $this->noIndentToken . ')~', "\n ", $result); |
|
| 177 | + return preg_replace('~\n(?!$|'.$this->noIndentToken.')~', "\n ", $result); |
|
| 178 | 178 | } else { |
| 179 | 179 | return $result; |
| 180 | 180 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | * @return string Pretty printed node |
| 189 | 189 | */ |
| 190 | 190 | protected function p(Node $node) { |
| 191 | - return $this->{'p' . $node->getType()}($node); |
|
| 191 | + return $this->{'p'.$node->getType()}($node); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | protected function pInfixOp($type, Node $leftNode, $operatorString, Node $rightNode) { |
@@ -201,12 +201,12 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | protected function pPrefixOp($type, $operatorString, Node $node) { |
| 203 | 203 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
| 204 | - return $operatorString . $this->pPrec($node, $precedence, $associativity, 1); |
|
| 204 | + return $operatorString.$this->pPrec($node, $precedence, $associativity, 1); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | protected function pPostfixOp($type, Node $node, $operatorString) { |
| 208 | 208 | list($precedence, $associativity) = $this->precedenceMap[$type]; |
| 209 | - return $this->pPrec($node, $precedence, $associativity, -1) . $operatorString; |
|
| 209 | + return $this->pPrec($node, $precedence, $associativity, -1).$operatorString; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -228,11 +228,11 @@ discard block |
||
| 228 | 228 | if ($childPrecedence > $parentPrecedence |
| 229 | 229 | || ($parentPrecedence == $childPrecedence && $parentAssociativity != $childPosition) |
| 230 | 230 | ) { |
| 231 | - return '(' . $this->{'p' . $type}($node) . ')'; |
|
| 231 | + return '('.$this->{'p'.$type}($node).')'; |
|
| 232 | 232 | } |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return $this->{'p' . $type}($node); |
|
| 235 | + return $this->{'p'.$type}($node); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | * @return string String marked with $this->noIndentToken's. |
| 272 | 272 | */ |
| 273 | 273 | protected function pNoIndent($string) { |
| 274 | - return str_replace("\n", "\n" . $this->noIndentToken, $string); |
|
| 274 | + return str_replace("\n", "\n".$this->noIndentToken, $string); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $result = ''; |
| 286 | 286 | |
| 287 | 287 | foreach ($comments as $comment) { |
| 288 | - $result .= $comment->getReformattedText() . "\n"; |
|
| 288 | + $result .= $comment->getReformattedText()."\n"; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | return $result; |
@@ -9,6 +9,9 @@ |
||
| 9 | 9 | |
| 10 | 10 | class ClassTest extends \PHPUnit_Framework_TestCase |
| 11 | 11 | { |
| 12 | + /** |
|
| 13 | + * @param string $class |
|
| 14 | + */ |
|
| 12 | 15 | protected function createClassBuilder($class) { |
| 13 | 16 | return new Class_($class); |
| 14 | 17 | } |
@@ -10,6 +10,9 @@ |
||
| 10 | 10 | |
| 11 | 11 | class FunctionTest extends \PHPUnit_Framework_TestCase |
| 12 | 12 | { |
| 13 | + /** |
|
| 14 | + * @param string $name |
|
| 15 | + */ |
|
| 13 | 16 | public function createFunctionBuilder($name) { |
| 14 | 17 | return new Function_($name); |
| 15 | 18 | } |
@@ -10,6 +10,9 @@ |
||
| 10 | 10 | |
| 11 | 11 | class MethodTest extends \PHPUnit_Framework_TestCase |
| 12 | 12 | { |
| 13 | + /** |
|
| 14 | + * @param string $name |
|
| 15 | + */ |
|
| 13 | 16 | public function createMethodBuilder($name) { |
| 14 | 17 | return new Method($name); |
| 15 | 18 | } |
@@ -6,6 +6,10 @@ |
||
| 6 | 6 | public $subNode1; |
| 7 | 7 | public $subNode2; |
| 8 | 8 | |
| 9 | + /** |
|
| 10 | + * @param string $subNode1 |
|
| 11 | + * @param string $subNode2 |
|
| 12 | + */ |
|
| 9 | 13 | public function __construct($subNode1, $subNode2, $attributes) { |
| 10 | 14 | parent::__construct($attributes); |
| 11 | 15 | $this->subNode1 = $subNode1; |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | $attributes = array( |
| 29 | 29 | 'startLine' => 10, |
| 30 | 30 | 'comments' => array( |
| 31 | - new Comment('// Comment' . "\n"), |
|
| 31 | + new Comment('// Comment'."\n"), |
|
| 32 | 32 | new Comment\Doc('/** doc comment */'), |
| 33 | 33 | ), |
| 34 | 34 | ); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $this->assertSame('newValue', $node->subNode); |
| 84 | 84 | |
| 85 | 85 | // indirect modification |
| 86 | - $subNode =& $node->subNode; |
|
| 86 | + $subNode = & $node->subNode; |
|
| 87 | 87 | $subNode = 'newNewValue'; |
| 88 | 88 | $this->assertSame('newNewValue', $node->subNode); |
| 89 | 89 | |
@@ -10,6 +10,9 @@ |
||
| 10 | 10 | |
| 11 | 11 | class NameResolverTest extends \PHPUnit_Framework_TestCase |
| 12 | 12 | { |
| 13 | + /** |
|
| 14 | + * @param string $string |
|
| 15 | + */ |
|
| 13 | 16 | private function canonicalize($string) { |
| 14 | 17 | return str_replace("\r\n", "\n", $string); |
| 15 | 18 | } |
@@ -302,11 +302,11 @@ discard block |
||
| 302 | 302 | $this->assertObjectNotHasAttribute('namespacedName', $stmts[0]->stmts[5]->class); |
| 303 | 303 | |
| 304 | 304 | $stmts = $traverser->traverse([new Stmt\Namespace_(null, $nsStmts)]); |
| 305 | - $this->assertSame('A', (string) $stmts[0]->stmts[0]->namespacedName); |
|
| 306 | - $this->assertSame('B', (string) $stmts[0]->stmts[1]->namespacedName); |
|
| 307 | - $this->assertSame('C', (string) $stmts[0]->stmts[2]->namespacedName); |
|
| 308 | - $this->assertSame('D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); |
|
| 309 | - $this->assertSame('E', (string) $stmts[0]->stmts[4]->namespacedName); |
|
| 305 | + $this->assertSame('A', (string) $stmts[0]->stmts[0]->namespacedName); |
|
| 306 | + $this->assertSame('B', (string) $stmts[0]->stmts[1]->namespacedName); |
|
| 307 | + $this->assertSame('C', (string) $stmts[0]->stmts[2]->namespacedName); |
|
| 308 | + $this->assertSame('D', (string) $stmts[0]->stmts[3]->consts[0]->namespacedName); |
|
| 309 | + $this->assertSame('E', (string) $stmts[0]->stmts[4]->namespacedName); |
|
| 310 | 310 | $this->assertObjectNotHasAttribute('namespacedName', $stmts[0]->stmts[5]->class); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | $classStmt = $stmts[0]; |
| 411 | 411 | $methodStmt = $classStmt->stmts[0]->stmts[0]; |
| 412 | 412 | |
| 413 | - $this->assertSame('SELF', (string)$methodStmt->stmts[0]->class); |
|
| 414 | - $this->assertSame('PARENT', (string)$methodStmt->stmts[1]->class); |
|
| 415 | - $this->assertSame('STATIC', (string)$methodStmt->stmts[2]->class); |
|
| 413 | + $this->assertSame('SELF', (string) $methodStmt->stmts[0]->class); |
|
| 414 | + $this->assertSame('PARENT', (string) $methodStmt->stmts[1]->class); |
|
| 415 | + $this->assertSame('STATIC', (string) $methodStmt->stmts[2]->class); |
|
| 416 | 416 | } |
| 417 | 417 | } |