Make PrettyPrinter\Standard methods protected

I'm not sure how these ever ended up being public.
This commit is contained in:
Nikita Popov 2016-07-25 14:27:03 +02:00
parent 5f97b12576
commit 818ef2e692
2 changed files with 148 additions and 147 deletions

View File

@ -40,6 +40,7 @@ Additionally the following changes were made:
takes an array of subnodes. Unlike classes/interfaces, traits can only have a `stmts` subnode.
* The `NodeDumper` now prints class/method/property/constant modifiers, as well as the include and
use type in a textual representation, instead of only showing the number.
* All methods on `PrettyPrinter\Standard` are now protected. Previoulsy most of them were public.
### Removed

View File

@ -17,7 +17,7 @@ class Standard extends PrettyPrinterAbstract
{
// Special nodes
public function pParam(Node\Param $node) {
protected function pParam(Node\Param $node) {
return ($node->type ? $this->pType($node->type) . ' ' : '')
. ($node->byRef ? '&' : '')
. ($node->variadic ? '...' : '')
@ -25,69 +25,69 @@ class Standard extends PrettyPrinterAbstract
. ($node->default ? ' = ' . $this->p($node->default) : '');
}
public function pArg(Node\Arg $node) {
protected function pArg(Node\Arg $node) {
return ($node->byRef ? '&' : '') . ($node->unpack ? '...' : '') . $this->p($node->value);
}
public function pConst(Node\Const_ $node) {
protected function pConst(Node\Const_ $node) {
return $node->name . ' = ' . $this->p($node->value);
}
public function pNullableType(Node\NullableType $node) {
protected function pNullableType(Node\NullableType $node) {
return '?' . $node->type;
}
// Names
public function pName(Name $node) {
protected function pName(Name $node) {
return implode('\\', $node->parts);
}
public function pName_FullyQualified(Name\FullyQualified $node) {
protected function pName_FullyQualified(Name\FullyQualified $node) {
return '\\' . implode('\\', $node->parts);
}
public function pName_Relative(Name\Relative $node) {
protected function pName_Relative(Name\Relative $node) {
return 'namespace\\' . implode('\\', $node->parts);
}
// Magic Constants
public function pScalar_MagicConst_Class(MagicConst\Class_ $node) {
protected function pScalar_MagicConst_Class(MagicConst\Class_ $node) {
return '__CLASS__';
}
public function pScalar_MagicConst_Dir(MagicConst\Dir $node) {
protected function pScalar_MagicConst_Dir(MagicConst\Dir $node) {
return '__DIR__';
}
public function pScalar_MagicConst_File(MagicConst\File $node) {
protected function pScalar_MagicConst_File(MagicConst\File $node) {
return '__FILE__';
}
public function pScalar_MagicConst_Function(MagicConst\Function_ $node) {
protected function pScalar_MagicConst_Function(MagicConst\Function_ $node) {
return '__FUNCTION__';
}
public function pScalar_MagicConst_Line(MagicConst\Line $node) {
protected function pScalar_MagicConst_Line(MagicConst\Line $node) {
return '__LINE__';
}
public function pScalar_MagicConst_Method(MagicConst\Method $node) {
protected function pScalar_MagicConst_Method(MagicConst\Method $node) {
return '__METHOD__';
}
public function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) {
protected function pScalar_MagicConst_Namespace(MagicConst\Namespace_ $node) {
return '__NAMESPACE__';
}
public function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) {
protected function pScalar_MagicConst_Trait(MagicConst\Trait_ $node) {
return '__TRAIT__';
}
// Scalars
public function pScalar_String(Scalar\String_ $node) {
protected function pScalar_String(Scalar\String_ $node) {
$kind = $node->getAttribute('kind', Scalar\String_::KIND_SINGLE_QUOTED);
switch ($kind) {
case Scalar\String_::KIND_NOWDOC:
@ -121,7 +121,7 @@ class Standard extends PrettyPrinterAbstract
throw new \Exception('Invalid string kind');
}
public function pScalar_Encapsed(Scalar\Encapsed $node) {
protected function pScalar_Encapsed(Scalar\Encapsed $node) {
if ($node->getAttribute('kind') === Scalar\String_::KIND_HEREDOC) {
$label = $node->getAttribute('docLabel');
if ($label && !$this->encapsedContainsEndLabel($node->parts, $label)) {
@ -140,7 +140,7 @@ class Standard extends PrettyPrinterAbstract
return '"' . $this->pEncapsList($node->parts, '"') . '"';
}
public function pScalar_LNumber(Scalar\LNumber $node) {
protected function pScalar_LNumber(Scalar\LNumber $node) {
$str = (string) $node->value;
switch ($node->getAttribute('kind', Scalar\LNumber::KIND_DEC)) {
case Scalar\LNumber::KIND_BIN:
@ -155,7 +155,7 @@ class Standard extends PrettyPrinterAbstract
throw new \Exception('Invalid number kind');
}
public function pScalar_DNumber(Scalar\DNumber $node) {
protected function pScalar_DNumber(Scalar\DNumber $node) {
$stringValue = sprintf('%.16G', $node->value);
if ($node->value !== (double) $stringValue) {
$stringValue = sprintf('%.17G', $node->value);
@ -167,265 +167,265 @@ class Standard extends PrettyPrinterAbstract
// Assignments
public function pExpr_Assign(Expr\Assign $node) {
protected function pExpr_Assign(Expr\Assign $node) {
return $this->pInfixOp('Expr_Assign', $node->var, ' = ', $node->expr);
}
public function pExpr_AssignRef(Expr\AssignRef $node) {
protected function pExpr_AssignRef(Expr\AssignRef $node) {
return $this->pInfixOp('Expr_AssignRef', $node->var, ' =& ', $node->expr);
}
public function pExpr_AssignOp_Plus(AssignOp\Plus $node) {
protected function pExpr_AssignOp_Plus(AssignOp\Plus $node) {
return $this->pInfixOp('Expr_AssignOp_Plus', $node->var, ' += ', $node->expr);
}
public function pExpr_AssignOp_Minus(AssignOp\Minus $node) {
protected function pExpr_AssignOp_Minus(AssignOp\Minus $node) {
return $this->pInfixOp('Expr_AssignOp_Minus', $node->var, ' -= ', $node->expr);
}
public function pExpr_AssignOp_Mul(AssignOp\Mul $node) {
protected function pExpr_AssignOp_Mul(AssignOp\Mul $node) {
return $this->pInfixOp('Expr_AssignOp_Mul', $node->var, ' *= ', $node->expr);
}
public function pExpr_AssignOp_Div(AssignOp\Div $node) {
protected function pExpr_AssignOp_Div(AssignOp\Div $node) {
return $this->pInfixOp('Expr_AssignOp_Div', $node->var, ' /= ', $node->expr);
}
public function pExpr_AssignOp_Concat(AssignOp\Concat $node) {
protected function pExpr_AssignOp_Concat(AssignOp\Concat $node) {
return $this->pInfixOp('Expr_AssignOp_Concat', $node->var, ' .= ', $node->expr);
}
public function pExpr_AssignOp_Mod(AssignOp\Mod $node) {
protected function pExpr_AssignOp_Mod(AssignOp\Mod $node) {
return $this->pInfixOp('Expr_AssignOp_Mod', $node->var, ' %= ', $node->expr);
}
public function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) {
protected function pExpr_AssignOp_BitwiseAnd(AssignOp\BitwiseAnd $node) {
return $this->pInfixOp('Expr_AssignOp_BitwiseAnd', $node->var, ' &= ', $node->expr);
}
public function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) {
protected function pExpr_AssignOp_BitwiseOr(AssignOp\BitwiseOr $node) {
return $this->pInfixOp('Expr_AssignOp_BitwiseOr', $node->var, ' |= ', $node->expr);
}
public function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) {
protected function pExpr_AssignOp_BitwiseXor(AssignOp\BitwiseXor $node) {
return $this->pInfixOp('Expr_AssignOp_BitwiseXor', $node->var, ' ^= ', $node->expr);
}
public function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) {
protected function pExpr_AssignOp_ShiftLeft(AssignOp\ShiftLeft $node) {
return $this->pInfixOp('Expr_AssignOp_ShiftLeft', $node->var, ' <<= ', $node->expr);
}
public function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) {
protected function pExpr_AssignOp_ShiftRight(AssignOp\ShiftRight $node) {
return $this->pInfixOp('Expr_AssignOp_ShiftRight', $node->var, ' >>= ', $node->expr);
}
public function pExpr_AssignOp_Pow(AssignOp\Pow $node) {
protected function pExpr_AssignOp_Pow(AssignOp\Pow $node) {
return $this->pInfixOp('Expr_AssignOp_Pow', $node->var, ' **= ', $node->expr);
}
// Binary expressions
public function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) {
protected function pExpr_BinaryOp_Plus(BinaryOp\Plus $node) {
return $this->pInfixOp('Expr_BinaryOp_Plus', $node->left, ' + ', $node->right);
}
public function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) {
protected function pExpr_BinaryOp_Minus(BinaryOp\Minus $node) {
return $this->pInfixOp('Expr_BinaryOp_Minus', $node->left, ' - ', $node->right);
}
public function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) {
protected function pExpr_BinaryOp_Mul(BinaryOp\Mul $node) {
return $this->pInfixOp('Expr_BinaryOp_Mul', $node->left, ' * ', $node->right);
}
public function pExpr_BinaryOp_Div(BinaryOp\Div $node) {
protected function pExpr_BinaryOp_Div(BinaryOp\Div $node) {
return $this->pInfixOp('Expr_BinaryOp_Div', $node->left, ' / ', $node->right);
}
public function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) {
protected function pExpr_BinaryOp_Concat(BinaryOp\Concat $node) {
return $this->pInfixOp('Expr_BinaryOp_Concat', $node->left, ' . ', $node->right);
}
public function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) {
protected function pExpr_BinaryOp_Mod(BinaryOp\Mod $node) {
return $this->pInfixOp('Expr_BinaryOp_Mod', $node->left, ' % ', $node->right);
}
public function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) {
protected function pExpr_BinaryOp_BooleanAnd(BinaryOp\BooleanAnd $node) {
return $this->pInfixOp('Expr_BinaryOp_BooleanAnd', $node->left, ' && ', $node->right);
}
public function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) {
protected function pExpr_BinaryOp_BooleanOr(BinaryOp\BooleanOr $node) {
return $this->pInfixOp('Expr_BinaryOp_BooleanOr', $node->left, ' || ', $node->right);
}
public function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) {
protected function pExpr_BinaryOp_BitwiseAnd(BinaryOp\BitwiseAnd $node) {
return $this->pInfixOp('Expr_BinaryOp_BitwiseAnd', $node->left, ' & ', $node->right);
}
public function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) {
protected function pExpr_BinaryOp_BitwiseOr(BinaryOp\BitwiseOr $node) {
return $this->pInfixOp('Expr_BinaryOp_BitwiseOr', $node->left, ' | ', $node->right);
}
public function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) {
protected function pExpr_BinaryOp_BitwiseXor(BinaryOp\BitwiseXor $node) {
return $this->pInfixOp('Expr_BinaryOp_BitwiseXor', $node->left, ' ^ ', $node->right);
}
public function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) {
protected function pExpr_BinaryOp_ShiftLeft(BinaryOp\ShiftLeft $node) {
return $this->pInfixOp('Expr_BinaryOp_ShiftLeft', $node->left, ' << ', $node->right);
}
public function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) {
protected function pExpr_BinaryOp_ShiftRight(BinaryOp\ShiftRight $node) {
return $this->pInfixOp('Expr_BinaryOp_ShiftRight', $node->left, ' >> ', $node->right);
}
public function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) {
protected function pExpr_BinaryOp_Pow(BinaryOp\Pow $node) {
return $this->pInfixOp('Expr_BinaryOp_Pow', $node->left, ' ** ', $node->right);
}
public function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) {
protected function pExpr_BinaryOp_LogicalAnd(BinaryOp\LogicalAnd $node) {
return $this->pInfixOp('Expr_BinaryOp_LogicalAnd', $node->left, ' and ', $node->right);
}
public function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) {
protected function pExpr_BinaryOp_LogicalOr(BinaryOp\LogicalOr $node) {
return $this->pInfixOp('Expr_BinaryOp_LogicalOr', $node->left, ' or ', $node->right);
}
public function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) {
protected function pExpr_BinaryOp_LogicalXor(BinaryOp\LogicalXor $node) {
return $this->pInfixOp('Expr_BinaryOp_LogicalXor', $node->left, ' xor ', $node->right);
}
public function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) {
protected function pExpr_BinaryOp_Equal(BinaryOp\Equal $node) {
return $this->pInfixOp('Expr_BinaryOp_Equal', $node->left, ' == ', $node->right);
}
public function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) {
protected function pExpr_BinaryOp_NotEqual(BinaryOp\NotEqual $node) {
return $this->pInfixOp('Expr_BinaryOp_NotEqual', $node->left, ' != ', $node->right);
}
public function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) {
protected function pExpr_BinaryOp_Identical(BinaryOp\Identical $node) {
return $this->pInfixOp('Expr_BinaryOp_Identical', $node->left, ' === ', $node->right);
}
public function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) {
protected function pExpr_BinaryOp_NotIdentical(BinaryOp\NotIdentical $node) {
return $this->pInfixOp('Expr_BinaryOp_NotIdentical', $node->left, ' !== ', $node->right);
}
public function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) {
protected function pExpr_BinaryOp_Spaceship(BinaryOp\Spaceship $node) {
return $this->pInfixOp('Expr_BinaryOp_Spaceship', $node->left, ' <=> ', $node->right);
}
public function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) {
protected function pExpr_BinaryOp_Greater(BinaryOp\Greater $node) {
return $this->pInfixOp('Expr_BinaryOp_Greater', $node->left, ' > ', $node->right);
}
public function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) {
protected function pExpr_BinaryOp_GreaterOrEqual(BinaryOp\GreaterOrEqual $node) {
return $this->pInfixOp('Expr_BinaryOp_GreaterOrEqual', $node->left, ' >= ', $node->right);
}
public function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) {
protected function pExpr_BinaryOp_Smaller(BinaryOp\Smaller $node) {
return $this->pInfixOp('Expr_BinaryOp_Smaller', $node->left, ' < ', $node->right);
}
public function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) {
protected function pExpr_BinaryOp_SmallerOrEqual(BinaryOp\SmallerOrEqual $node) {
return $this->pInfixOp('Expr_BinaryOp_SmallerOrEqual', $node->left, ' <= ', $node->right);
}
public function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) {
protected function pExpr_BinaryOp_Coalesce(BinaryOp\Coalesce $node) {
return $this->pInfixOp('Expr_BinaryOp_Coalesce', $node->left, ' ?? ', $node->right);
}
public function pExpr_Instanceof(Expr\Instanceof_ $node) {
protected function pExpr_Instanceof(Expr\Instanceof_ $node) {
return $this->pInfixOp('Expr_Instanceof', $node->expr, ' instanceof ', $node->class);
}
// Unary expressions
public function pExpr_BooleanNot(Expr\BooleanNot $node) {
protected function pExpr_BooleanNot(Expr\BooleanNot $node) {
return $this->pPrefixOp('Expr_BooleanNot', '!', $node->expr);
}
public function pExpr_BitwiseNot(Expr\BitwiseNot $node) {
protected function pExpr_BitwiseNot(Expr\BitwiseNot $node) {
return $this->pPrefixOp('Expr_BitwiseNot', '~', $node->expr);
}
public function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
protected function pExpr_UnaryMinus(Expr\UnaryMinus $node) {
return $this->pPrefixOp('Expr_UnaryMinus', '-', $node->expr);
}
public function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
protected function pExpr_UnaryPlus(Expr\UnaryPlus $node) {
return $this->pPrefixOp('Expr_UnaryPlus', '+', $node->expr);
}
public function pExpr_PreInc(Expr\PreInc $node) {
protected function pExpr_PreInc(Expr\PreInc $node) {
return $this->pPrefixOp('Expr_PreInc', '++', $node->var);
}
public function pExpr_PreDec(Expr\PreDec $node) {
protected function pExpr_PreDec(Expr\PreDec $node) {
return $this->pPrefixOp('Expr_PreDec', '--', $node->var);
}
public function pExpr_PostInc(Expr\PostInc $node) {
protected function pExpr_PostInc(Expr\PostInc $node) {
return $this->pPostfixOp('Expr_PostInc', $node->var, '++');
}
public function pExpr_PostDec(Expr\PostDec $node) {
protected function pExpr_PostDec(Expr\PostDec $node) {
return $this->pPostfixOp('Expr_PostDec', $node->var, '--');
}
public function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) {
protected function pExpr_ErrorSuppress(Expr\ErrorSuppress $node) {
return $this->pPrefixOp('Expr_ErrorSuppress', '@', $node->expr);
}
public function pExpr_YieldFrom(Expr\YieldFrom $node) {
protected function pExpr_YieldFrom(Expr\YieldFrom $node) {
return $this->pPrefixOp('Expr_YieldFrom', 'yield from ', $node->expr);
}
public function pExpr_Print(Expr\Print_ $node) {
protected function pExpr_Print(Expr\Print_ $node) {
return $this->pPrefixOp('Expr_Print', 'print ', $node->expr);
}
// Casts
public function pExpr_Cast_Int(Cast\Int_ $node) {
protected function pExpr_Cast_Int(Cast\Int_ $node) {
return $this->pPrefixOp('Expr_Cast_Int', '(int) ', $node->expr);
}
public function pExpr_Cast_Double(Cast\Double $node) {
protected function pExpr_Cast_Double(Cast\Double $node) {
return $this->pPrefixOp('Expr_Cast_Double', '(double) ', $node->expr);
}
public function pExpr_Cast_String(Cast\String_ $node) {
protected function pExpr_Cast_String(Cast\String_ $node) {
return $this->pPrefixOp('Expr_Cast_String', '(string) ', $node->expr);
}
public function pExpr_Cast_Array(Cast\Array_ $node) {
protected function pExpr_Cast_Array(Cast\Array_ $node) {
return $this->pPrefixOp('Expr_Cast_Array', '(array) ', $node->expr);
}
public function pExpr_Cast_Object(Cast\Object_ $node) {
protected function pExpr_Cast_Object(Cast\Object_ $node) {
return $this->pPrefixOp('Expr_Cast_Object', '(object) ', $node->expr);
}
public function pExpr_Cast_Bool(Cast\Bool_ $node) {
protected function pExpr_Cast_Bool(Cast\Bool_ $node) {
return $this->pPrefixOp('Expr_Cast_Bool', '(bool) ', $node->expr);
}
public function pExpr_Cast_Unset(Cast\Unset_ $node) {
protected function pExpr_Cast_Unset(Cast\Unset_ $node) {
return $this->pPrefixOp('Expr_Cast_Unset', '(unset) ', $node->expr);
}
// Function calls and similar constructs
public function pExpr_FuncCall(Expr\FuncCall $node) {
protected function pExpr_FuncCall(Expr\FuncCall $node) {
return $this->pCallLhs($node->name)
. '(' . $this->pCommaSeparated($node->args) . ')';
}
public function pExpr_MethodCall(Expr\MethodCall $node) {
protected function pExpr_MethodCall(Expr\MethodCall $node) {
return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name)
. '(' . $this->pCommaSeparated($node->args) . ')';
}
public function pExpr_StaticCall(Expr\StaticCall $node) {
protected function pExpr_StaticCall(Expr\StaticCall $node) {
return $this->pDereferenceLhs($node->class) . '::'
. ($node->name instanceof Expr
? ($node->name instanceof Expr\Variable
@ -435,19 +435,19 @@ class Standard extends PrettyPrinterAbstract
. '(' . $this->pCommaSeparated($node->args) . ')';
}
public function pExpr_Empty(Expr\Empty_ $node) {
protected function pExpr_Empty(Expr\Empty_ $node) {
return 'empty(' . $this->p($node->expr) . ')';
}
public function pExpr_Isset(Expr\Isset_ $node) {
protected function pExpr_Isset(Expr\Isset_ $node) {
return 'isset(' . $this->pCommaSeparated($node->vars) . ')';
}
public function pExpr_Eval(Expr\Eval_ $node) {
protected function pExpr_Eval(Expr\Eval_ $node) {
return 'eval(' . $this->p($node->expr) . ')';
}
public function pExpr_Include(Expr\Include_ $node) {
protected function pExpr_Include(Expr\Include_ $node) {
static $map = array(
Expr\Include_::TYPE_INCLUDE => 'include',
Expr\Include_::TYPE_INCLUDE_ONCE => 'include_once',
@ -458,13 +458,13 @@ class Standard extends PrettyPrinterAbstract
return $map[$node->type] . ' ' . $this->p($node->expr);
}
public function pExpr_List(Expr\List_ $node) {
protected function pExpr_List(Expr\List_ $node) {
return 'list(' . $this->pCommaSeparated($node->items) . ')';
}
// Other
public function pExpr_Variable(Expr\Variable $node) {
protected function pExpr_Variable(Expr\Variable $node) {
if ($node->name instanceof Expr) {
return '${' . $this->p($node->name) . '}';
} else {
@ -472,7 +472,7 @@ class Standard extends PrettyPrinterAbstract
}
}
public function pExpr_Array(Expr\Array_ $node) {
protected function pExpr_Array(Expr\Array_ $node) {
$syntax = $node->getAttribute('kind',
$this->options['shortArraySyntax'] ? Expr\Array_::KIND_SHORT : Expr\Array_::KIND_LONG);
if ($syntax === Expr\Array_::KIND_SHORT) {
@ -482,37 +482,37 @@ class Standard extends PrettyPrinterAbstract
}
}
public function pExpr_ArrayItem(Expr\ArrayItem $node) {
protected function pExpr_ArrayItem(Expr\ArrayItem $node) {
return (null !== $node->key ? $this->p($node->key) . ' => ' : '')
. ($node->byRef ? '&' : '') . $this->p($node->value);
}
public function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) {
protected function pExpr_ArrayDimFetch(Expr\ArrayDimFetch $node) {
return $this->pDereferenceLhs($node->var)
. '[' . (null !== $node->dim ? $this->p($node->dim) : '') . ']';
}
public function pExpr_ConstFetch(Expr\ConstFetch $node) {
protected function pExpr_ConstFetch(Expr\ConstFetch $node) {
return $this->p($node->name);
}
public function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node) {
return $this->p($node->class) . '::' . $node->name;
}
public function pExpr_PropertyFetch(Expr\PropertyFetch $node) {
protected function pExpr_PropertyFetch(Expr\PropertyFetch $node) {
return $this->pDereferenceLhs($node->var) . '->' . $this->pObjectProperty($node->name);
}
public function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) {
protected function pExpr_StaticPropertyFetch(Expr\StaticPropertyFetch $node) {
return $this->pDereferenceLhs($node->class) . '::$' . $this->pObjectProperty($node->name);
}
public function pExpr_ShellExec(Expr\ShellExec $node) {
protected function pExpr_ShellExec(Expr\ShellExec $node) {
return '`' . $this->pEncapsList($node->parts, '`') . '`';
}
public function pExpr_Closure(Expr\Closure $node) {
protected function pExpr_Closure(Expr\Closure $node) {
return ($node->static ? 'static ' : '')
. 'function ' . ($node->byRef ? '&' : '')
. '(' . $this->pCommaSeparated($node->params) . ')'
@ -521,11 +521,11 @@ class Standard extends PrettyPrinterAbstract
. ' {' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pExpr_ClosureUse(Expr\ClosureUse $node) {
protected function pExpr_ClosureUse(Expr\ClosureUse $node) {
return ($node->byRef ? '&' : '') . '$' . $node->var;
}
public function pExpr_New(Expr\New_ $node) {
protected function pExpr_New(Expr\New_ $node) {
if ($node->class instanceof Stmt\Class_) {
$args = $node->args ? '(' . $this->pCommaSeparated($node->args) . ')' : '';
return 'new ' . $this->pClassCommon($node->class, $args);
@ -533,11 +533,11 @@ class Standard extends PrettyPrinterAbstract
return 'new ' . $this->p($node->class) . '(' . $this->pCommaSeparated($node->args) . ')';
}
public function pExpr_Clone(Expr\Clone_ $node) {
protected function pExpr_Clone(Expr\Clone_ $node) {
return 'clone ' . $this->p($node->expr);
}
public function pExpr_Ternary(Expr\Ternary $node) {
protected function pExpr_Ternary(Expr\Ternary $node) {
// a bit of cheating: we treat the ternary as a binary op where the ?...: part is the operator.
// this is okay because the part between ? and : never needs parentheses.
return $this->pInfixOp('Expr_Ternary',
@ -545,13 +545,13 @@ class Standard extends PrettyPrinterAbstract
);
}
public function pExpr_Exit(Expr\Exit_ $node) {
protected function pExpr_Exit(Expr\Exit_ $node) {
$kind = $node->getAttribute('kind', Expr\Exit_::KIND_DIE);
return ($kind === Expr\Exit_::KIND_EXIT ? 'exit' : 'die')
. (null !== $node->expr ? '(' . $this->p($node->expr) . ')' : '');
}
public function pExpr_Yield(Expr\Yield_ $node) {
protected function pExpr_Yield(Expr\Yield_ $node) {
if ($node->value === null) {
return 'yield';
} else {
@ -565,7 +565,7 @@ class Standard extends PrettyPrinterAbstract
// Declarations
public function pStmt_Namespace(Stmt\Namespace_ $node) {
protected function pStmt_Namespace(Stmt\Namespace_ $node) {
if ($this->canUseSemicolonNamespaces) {
return 'namespace ' . $this->p($node->name) . ';' . "\n" . $this->pStmts($node->stmts, false);
} else {
@ -574,17 +574,17 @@ class Standard extends PrettyPrinterAbstract
}
}
public function pStmt_Use(Stmt\Use_ $node) {
protected function pStmt_Use(Stmt\Use_ $node) {
return 'use ' . $this->pUseType($node->type)
. $this->pCommaSeparated($node->uses) . ';';
}
public function pStmt_GroupUse(Stmt\GroupUse $node) {
protected function pStmt_GroupUse(Stmt\GroupUse $node) {
return 'use ' . $this->pUseType($node->type) . $this->pName($node->prefix)
. '\{' . $this->pCommaSeparated($node->uses) . '};';
}
public function pStmt_UseUse(Stmt\UseUse $node) {
protected function pStmt_UseUse(Stmt\UseUse $node) {
return $this->pUseType($node->type) . $this->p($node->name)
. ($node->name->getLast() !== $node->alias ? ' as ' . $node->alias : '');
}
@ -594,34 +594,34 @@ class Standard extends PrettyPrinterAbstract
: ($type === Stmt\Use_::TYPE_CONSTANT ? 'const ' : '');
}
public function pStmt_Interface(Stmt\Interface_ $node) {
protected function pStmt_Interface(Stmt\Interface_ $node) {
return 'interface ' . $node->name
. (!empty($node->extends) ? ' extends ' . $this->pCommaSeparated($node->extends) : '')
. "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Class(Stmt\Class_ $node) {
protected function pStmt_Class(Stmt\Class_ $node) {
return $this->pClassCommon($node, ' ' . $node->name);
}
public function pStmt_Trait(Stmt\Trait_ $node) {
protected function pStmt_Trait(Stmt\Trait_ $node) {
return 'trait ' . $node->name
. "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_TraitUse(Stmt\TraitUse $node) {
protected function pStmt_TraitUse(Stmt\TraitUse $node) {
return 'use ' . $this->pCommaSeparated($node->traits)
. (empty($node->adaptations)
? ';'
: ' {' . $this->pStmts($node->adaptations) . "\n" . '}');
}
public function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) {
protected function pStmt_TraitUseAdaptation_Precedence(Stmt\TraitUseAdaptation\Precedence $node) {
return $this->p($node->trait) . '::' . $node->method
. ' insteadof ' . $this->pCommaSeparated($node->insteadof) . ';';
}
public function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) {
protected function pStmt_TraitUseAdaptation_Alias(Stmt\TraitUseAdaptation\Alias $node) {
return (null !== $node->trait ? $this->p($node->trait) . '::' : '')
. $node->method . ' as'
. (null !== $node->newModifier ? ' ' . rtrim($this->pModifiers($node->newModifier), ' ') : '')
@ -629,16 +629,16 @@ class Standard extends PrettyPrinterAbstract
. ';';
}
public function pStmt_Property(Stmt\Property $node) {
protected function pStmt_Property(Stmt\Property $node) {
return (0 === $node->flags ? 'var ' : $this->pModifiers($node->flags)) . $this->pCommaSeparated($node->props) . ';';
}
public function pStmt_PropertyProperty(Stmt\PropertyProperty $node) {
protected function pStmt_PropertyProperty(Stmt\PropertyProperty $node) {
return '$' . $node->name
. (null !== $node->default ? ' = ' . $this->p($node->default) : '');
}
public function pStmt_ClassMethod(Stmt\ClassMethod $node) {
protected function pStmt_ClassMethod(Stmt\ClassMethod $node) {
return $this->pModifiers($node->flags)
. 'function ' . ($node->byRef ? '&' : '') . $node->name
. '(' . $this->pCommaSeparated($node->params) . ')'
@ -648,50 +648,50 @@ class Standard extends PrettyPrinterAbstract
: ';');
}
public function pStmt_ClassConst(Stmt\ClassConst $node) {
protected function pStmt_ClassConst(Stmt\ClassConst $node) {
return $this->pModifiers($node->flags)
. 'const ' . $this->pCommaSeparated($node->consts) . ';';
}
public function pStmt_Function(Stmt\Function_ $node) {
protected function pStmt_Function(Stmt\Function_ $node) {
return 'function ' . ($node->byRef ? '&' : '') . $node->name
. '(' . $this->pCommaSeparated($node->params) . ')'
. (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : '')
. "\n" . '{' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Const(Stmt\Const_ $node) {
protected function pStmt_Const(Stmt\Const_ $node) {
return 'const ' . $this->pCommaSeparated($node->consts) . ';';
}
public function pStmt_Declare(Stmt\Declare_ $node) {
protected function pStmt_Declare(Stmt\Declare_ $node) {
return 'declare (' . $this->pCommaSeparated($node->declares) . ')'
. (null !== $node->stmts ? ' {' . $this->pStmts($node->stmts) . "\n" . '}' : ';');
}
public function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) {
protected function pStmt_DeclareDeclare(Stmt\DeclareDeclare $node) {
return $node->key . '=' . $this->p($node->value);
}
// Control flow
public function pStmt_If(Stmt\If_ $node) {
protected function pStmt_If(Stmt\If_ $node) {
return 'if (' . $this->p($node->cond) . ') {'
. $this->pStmts($node->stmts) . "\n" . '}'
. $this->pImplode($node->elseifs)
. (null !== $node->else ? $this->p($node->else) : '');
}
public function pStmt_ElseIf(Stmt\ElseIf_ $node) {
protected function pStmt_ElseIf(Stmt\ElseIf_ $node) {
return ' elseif (' . $this->p($node->cond) . ') {'
. $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Else(Stmt\Else_ $node) {
protected function pStmt_Else(Stmt\Else_ $node) {
return ' else {' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_For(Stmt\For_ $node) {
protected function pStmt_For(Stmt\For_ $node) {
return 'for ('
. $this->pCommaSeparated($node->init) . ';' . (!empty($node->cond) ? ' ' : '')
. $this->pCommaSeparated($node->cond) . ';' . (!empty($node->loop) ? ' ' : '')
@ -699,104 +699,104 @@ class Standard extends PrettyPrinterAbstract
. ') {' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Foreach(Stmt\Foreach_ $node) {
protected function pStmt_Foreach(Stmt\Foreach_ $node) {
return 'foreach (' . $this->p($node->expr) . ' as '
. (null !== $node->keyVar ? $this->p($node->keyVar) . ' => ' : '')
. ($node->byRef ? '&' : '') . $this->p($node->valueVar) . ') {'
. $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_While(Stmt\While_ $node) {
protected function pStmt_While(Stmt\While_ $node) {
return 'while (' . $this->p($node->cond) . ') {'
. $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Do(Stmt\Do_ $node) {
protected function pStmt_Do(Stmt\Do_ $node) {
return 'do {' . $this->pStmts($node->stmts) . "\n"
. '} while (' . $this->p($node->cond) . ');';
}
public function pStmt_Switch(Stmt\Switch_ $node) {
protected function pStmt_Switch(Stmt\Switch_ $node) {
return 'switch (' . $this->p($node->cond) . ') {'
. $this->pStmts($node->cases) . "\n" . '}';
}
public function pStmt_Case(Stmt\Case_ $node) {
protected function pStmt_Case(Stmt\Case_ $node) {
return (null !== $node->cond ? 'case ' . $this->p($node->cond) : 'default') . ':'
. $this->pStmts($node->stmts);
}
public function pStmt_TryCatch(Stmt\TryCatch $node) {
protected function pStmt_TryCatch(Stmt\TryCatch $node) {
return 'try {' . $this->pStmts($node->stmts) . "\n" . '}'
. $this->pImplode($node->catches)
. ($node->finally !== null ? $this->p($node->finally) : '');
}
public function pStmt_Catch(Stmt\Catch_ $node) {
protected function pStmt_Catch(Stmt\Catch_ $node) {
return ' catch (' . $this->pImplode($node->types, '|') . ' $' . $node->var . ') {'
. $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Finally(Stmt\Finally_ $node) {
protected function pStmt_Finally(Stmt\Finally_ $node) {
return ' finally {' . $this->pStmts($node->stmts) . "\n" . '}';
}
public function pStmt_Break(Stmt\Break_ $node) {
protected function pStmt_Break(Stmt\Break_ $node) {
return 'break' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
}
public function pStmt_Continue(Stmt\Continue_ $node) {
protected function pStmt_Continue(Stmt\Continue_ $node) {
return 'continue' . ($node->num !== null ? ' ' . $this->p($node->num) : '') . ';';
}
public function pStmt_Return(Stmt\Return_ $node) {
protected function pStmt_Return(Stmt\Return_ $node) {
return 'return' . (null !== $node->expr ? ' ' . $this->p($node->expr) : '') . ';';
}
public function pStmt_Throw(Stmt\Throw_ $node) {
protected function pStmt_Throw(Stmt\Throw_ $node) {
return 'throw ' . $this->p($node->expr) . ';';
}
public function pStmt_Label(Stmt\Label $node) {
protected function pStmt_Label(Stmt\Label $node) {
return $node->name . ':';
}
public function pStmt_Goto(Stmt\Goto_ $node) {
protected function pStmt_Goto(Stmt\Goto_ $node) {
return 'goto ' . $node->name . ';';
}
// Other
public function pStmt_Echo(Stmt\Echo_ $node) {
protected function pStmt_Echo(Stmt\Echo_ $node) {
return 'echo ' . $this->pCommaSeparated($node->exprs) . ';';
}
public function pStmt_Static(Stmt\Static_ $node) {
protected function pStmt_Static(Stmt\Static_ $node) {
return 'static ' . $this->pCommaSeparated($node->vars) . ';';
}
public function pStmt_Global(Stmt\Global_ $node) {
protected function pStmt_Global(Stmt\Global_ $node) {
return 'global ' . $this->pCommaSeparated($node->vars) . ';';
}
public function pStmt_StaticVar(Stmt\StaticVar $node) {
protected function pStmt_StaticVar(Stmt\StaticVar $node) {
return '$' . $node->name
. (null !== $node->default ? ' = ' . $this->p($node->default) : '');
}
public function pStmt_Unset(Stmt\Unset_ $node) {
protected function pStmt_Unset(Stmt\Unset_ $node) {
return 'unset(' . $this->pCommaSeparated($node->vars) . ');';
}
public function pStmt_InlineHTML(Stmt\InlineHTML $node) {
protected function pStmt_InlineHTML(Stmt\InlineHTML $node) {
return '?>' . $this->pNoIndent("\n" . $node->value) . '<?php ';
}
public function pStmt_HaltCompiler(Stmt\HaltCompiler $node) {
protected function pStmt_HaltCompiler(Stmt\HaltCompiler $node) {
return '__halt_compiler();' . $node->remaining;
}
public function pStmt_Nop(Stmt\Nop $node) {
protected function pStmt_Nop(Stmt\Nop $node) {
return '';
}