Properties

$precedenceMap

$precedenceMap : 

Type

$noIndentToken

$noIndentToken : 

Type

$docStringEndToken

$docStringEndToken : 

Type

$canUseSemicolonNamespaces

$canUseSemicolonNamespaces : 

Type

$options

$options : 

Type

Methods

__construct()

__construct(array  $options = array()) 

Creates a pretty printer instance using the given options.

Supported options:

  • bool $shortArraySyntax = false: Whether to use [] instead of array() as the default array syntax, if the node does not specify a format.

Parameters

array $options

Dictionary of formatting options

prettyPrint()

prettyPrint(array<mixed,\PhpParser\Node>  $stmts) : string

Pretty prints an array of statements.

Parameters

array<mixed,\PhpParser\Node> $stmts

Array of statements

Returns

string —

Pretty printed statements

prettyPrintExpr()

prettyPrintExpr(\PhpParser\Node\Expr  $node) : string

Pretty prints an expression.

Parameters

\PhpParser\Node\Expr $node

Expression node

Returns

string —

Pretty printed node

prettyPrintFile()

prettyPrintFile(array<mixed,\PhpParser\Node>  $stmts) : string

Pretty prints a file of statements (includes the opening <?php tag if it is required).

Parameters

array<mixed,\PhpParser\Node> $stmts

Array of statements

Returns

string —

Pretty printed statements

preprocessNodes()

preprocessNodes(array<mixed,\PhpParser\Node>  $nodes) 

Preprocesses the top-level nodes to initialize pretty printer state.

Parameters

array<mixed,\PhpParser\Node> $nodes

Array of nodes

handleMagicTokens()

handleMagicTokens(  $str) 

Parameters

$str

pStmts()

pStmts(array<mixed,\PhpParser\Node>  $nodes, boolean  $indent = true) : string

Pretty prints an array of nodes (statements) and indents them optionally.

Parameters

array<mixed,\PhpParser\Node> $nodes

Array of nodes

boolean $indent

Whether to indent the printed nodes

Returns

string —

Pretty printed statements

p()

p(\PhpParser\Node  $node) : string

Pretty prints a node.

Parameters

\PhpParser\Node $node

Node to be pretty printed

Returns

string —

Pretty printed node

pInfixOp()

pInfixOp(  $type, \PhpParser\Node  $leftNode,   $operatorString, \PhpParser\Node  $rightNode) 

Parameters

$type
\PhpParser\Node $leftNode
$operatorString
\PhpParser\Node $rightNode

pPrefixOp()

pPrefixOp(  $type,   $operatorString, \PhpParser\Node  $node) 

Parameters

$type
$operatorString
\PhpParser\Node $node

pPostfixOp()

pPostfixOp(  $type, \PhpParser\Node  $node,   $operatorString) 

Parameters

$type
\PhpParser\Node $node
$operatorString

pPrec()

pPrec(\PhpParser\Node  $node, integer  $parentPrecedence, integer  $parentAssociativity, integer  $childPosition) : string

Prints an expression node with the least amount of parentheses necessary to preserve the meaning.

Parameters

\PhpParser\Node $node

Node to pretty print

integer $parentPrecedence

Precedence of the parent operator

integer $parentAssociativity

Associativity of parent operator (-1 is left, 0 is nonassoc, 1 is right)

integer $childPosition

Position of the node relative to the operator (-1 is left, 1 is right)

Returns

string —

The pretty printed node

pImplode()

pImplode(array<mixed,\PhpParser\Node>  $nodes, string  $glue = '') : string

Pretty prints an array of nodes and implodes the printed values.

Parameters

array<mixed,\PhpParser\Node> $nodes

Array of Nodes to be printed

string $glue

Character to implode with

Returns

string —

Imploded pretty printed nodes

pCommaSeparated()

pCommaSeparated(array<mixed,\PhpParser\Node>  $nodes) : string

Pretty prints an array of nodes and implodes the printed values with commas.

Parameters

array<mixed,\PhpParser\Node> $nodes

Array of Nodes to be printed

Returns

string —

Comma separated pretty printed nodes

pCommaSeparatedMultiline()

pCommaSeparatedMultiline(array<mixed,\PhpParser\Node>  $nodes, boolean  $trailingComma) : string

Pretty prints a comma-separated list of nodes in multiline style, including comments.

The result includes a leading newline and one level of indentation (same as pStmts).

Parameters

array<mixed,\PhpParser\Node> $nodes

Array of Nodes to be printed

boolean $trailingComma

Whether to use a trailing comma

Returns

string —

Comma separated pretty printed nodes in multiline style

pNoIndent()

pNoIndent(string  $string) : string

Signals the pretty printer that a string shall not be indented.

Parameters

string $string

Not to be indented string

Returns

string —

String marked with $this->noIndentToken's.

pComments()

pComments(array<mixed,\PhpParser\Comment>  $comments) : string

Prints reformatted text of the passed comments.

Parameters

array<mixed,\PhpParser\Comment> $comments

List of comments

Returns

string —

Reformatted text of comments