PHP Class PhpParser\PrettyPrinterAbstract

Show file Open project: nikic/php-parser Class Usage Examples

Protected Properties

Property Type Description
$canUseSemicolonNamespaces
$docStringEndToken
$noIndentToken
$options
$precedenceMap

Public Methods

Method Description
__construct ( array $options = [] ) Creates a pretty printer instance using the given options.
prettyPrint ( array $stmts ) : string Pretty prints an array of statements.
prettyPrintExpr ( PhpParser\Node\Expr $node ) : string Pretty prints an expression.
prettyPrintFile ( array $stmts ) : string Pretty prints a file of statements (includes the opening

Protected Methods

Method Description
handleMagicTokens ( $str )
p ( phpparser\Node $node ) : string Pretty prints a node.
pCommaSeparated ( array $nodes ) : string Pretty prints an array of nodes and implodes the printed values with commas.
pComments ( array $comments ) : string Prints reformatted text of the passed comments.
pImplode ( array $nodes, string $glue = '' ) : string Pretty prints an array of nodes and implodes the printed values.
pInfixOp ( $type, phpparser\Node $leftNode, $operatorString, phpparser\Node $rightNode )
pNoIndent ( string $string ) : string Signals the pretty printer that a string shall not be indented.
pPostfixOp ( $type, phpparser\Node $node, $operatorString )
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.
pPrefixOp ( $type, $operatorString, phpparser\Node $node )
pStmts ( array $nodes, boolean $indent = true ) : string Pretty prints an array of nodes (statements) and indents them optionally.
preprocessNodes ( array $nodes ) Preprocesses the top-level nodes to initialize pretty printer state.

Method Details

__construct() public method

Supported options: * bool $shortArraySyntax = false: Whether to use [] instead of array() as the default array syntax, if the node does not specify a format.
public __construct ( array $options = [] )
$options array Dictionary of formatting options

handleMagicTokens() protected method

protected handleMagicTokens ( $str )

p() protected method

Pretty prints a node.
protected p ( phpparser\Node $node ) : string
$node phpparser\Node Node to be pretty printed
return string Pretty printed node

pCommaSeparated() protected method

Pretty prints an array of nodes and implodes the printed values with commas.
protected pCommaSeparated ( array $nodes ) : string
$nodes array Array of Nodes to be printed
return string Comma separated pretty printed nodes

pComments() protected method

Prints reformatted text of the passed comments.
protected pComments ( array $comments ) : string
$comments array List of comments
return string Reformatted text of comments

pImplode() protected method

Pretty prints an array of nodes and implodes the printed values.
protected pImplode ( array $nodes, string $glue = '' ) : string
$nodes array Array of Nodes to be printed
$glue string Character to implode with
return string Imploded pretty printed nodes

pInfixOp() protected method

protected pInfixOp ( $type, phpparser\Node $leftNode, $operatorString, phpparser\Node $rightNode )
$leftNode phpparser\Node
$rightNode phpparser\Node

pNoIndent() protected method

Signals the pretty printer that a string shall not be indented.
protected pNoIndent ( string $string ) : string
$string string Not to be indented string
return string String marked with $this->noIndentToken's.

pPostfixOp() protected method

protected pPostfixOp ( $type, phpparser\Node $node, $operatorString )
$node phpparser\Node

pPrec() protected method

Prints an expression node with the least amount of parentheses necessary to preserve the meaning.
protected pPrec ( phpparser\Node $node, integer $parentPrecedence, integer $parentAssociativity, integer $childPosition ) : string
$node phpparser\Node Node to pretty print
$parentPrecedence integer Precedence of the parent operator
$parentAssociativity integer Associativity of parent operator (-1 is left, 0 is nonassoc, 1 is right)
$childPosition integer Position of the node relative to the operator (-1 is left, 1 is right)
return string The pretty printed node

pPrefixOp() protected method

protected pPrefixOp ( $type, $operatorString, phpparser\Node $node )
$node phpparser\Node

pStmts() protected method

Pretty prints an array of nodes (statements) and indents them optionally.
protected pStmts ( array $nodes, boolean $indent = true ) : string
$nodes array Array of nodes
$indent boolean Whether to indent the printed nodes
return string Pretty printed statements

preprocessNodes() protected method

Preprocesses the top-level nodes to initialize pretty printer state.
protected preprocessNodes ( array $nodes )
$nodes array Array of nodes

prettyPrint() public method

Pretty prints an array of statements.
public prettyPrint ( array $stmts ) : string
$stmts array Array of statements
return string Pretty printed statements

prettyPrintExpr() public method

Pretty prints an expression.
public prettyPrintExpr ( PhpParser\Node\Expr $node ) : string
$node PhpParser\Node\Expr Expression node
return string Pretty printed node

prettyPrintFile() public method

Pretty prints a file of statements (includes the opening
public prettyPrintFile ( array $stmts ) : string
$stmts array Array of statements
return string Pretty printed statements

Property Details

$canUseSemicolonNamespaces protected property

protected $canUseSemicolonNamespaces

$docStringEndToken protected property

protected $docStringEndToken

$noIndentToken protected property

protected $noIndentToken

$options protected property

protected $options

$precedenceMap protected property

protected $precedenceMap