Methods |
public __construct(array $options = []) Creates a pretty printer instance using the given options. Supported options:
|
public prettyPrint(array $stmts) : string Pretty prints an array of statements.
|
public prettyPrintExpr(PhpParser Pretty prints an expression.
|
public prettyPrintFile(array $stmts) : string Pretty prints a file of statements (includes the opening tag if it is required).
|
public printFormatPreserving(array $stmts, array $origStmts, array $origTokens) : string Perform a format-preserving pretty print of an AST. The format preservation is best effort. For some changes to the AST the formatting will not be preserved (at least not locally). In order to use this method a number of prerequisites must be satisfied:
|
Constants |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
protected PhpParser |
Properties |
protected bool $canUseSemicolonNamespaces
|
protected ?string $docStringEndToken
|
protected array $emptyListInsertionMap
|
protected array $fixupMap
|
protected int $indentLevel
|
protected array $insertionMap
|
protected array $labelCharMap
|
protected array $listInsertionMap
|
protected array $modifierChangeMap
|
protected string $newline
|
protected string $nl
|
protected PhpParser
|
protected ?PhpParser
|
protected PhpParser
|
protected array $precedenceMap = ['PhpParser\Node\Expr\Clone_' => [-10, 0, 1], 'PhpParser\Node\Expr\BinaryOp\Pow' => [0, 0, 1], 'PhpParser\Node\Expr\BitwiseNot' => [10, -1, -1], 'PhpParser\Node\Expr\UnaryPlus' => [10, -1, -1], 'PhpParser\Node\Expr\UnaryMinus' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Int_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Double' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\String_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Array_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Object_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Bool_' => [10, -1, -1], 'PhpParser\Node\Expr\Cast\Unset_' => [10, -1, -1], 'PhpParser\Node\Expr\ErrorSuppress' => [10, -1, -1], 'PhpParser\Node\Expr\Instanceof_' => [20, -1, -1], 'PhpParser\Node\Expr\BooleanNot' => [30, -1, -1], 'PhpParser\Node\Expr\BinaryOp\Mul' => [40, 41, 40], 'PhpParser\Node\Expr\BinaryOp\Div' => [40, 41, 40], 'PhpParser\Node\Expr\BinaryOp\Mod' => [40, 41, 40], 'PhpParser\Node\Expr\BinaryOp\Plus' => [50, 51, 50], 'PhpParser\Node\Expr\BinaryOp\Minus' => [50, 51, 50], 'PhpParser\Node\Expr\BinaryOp\Concat' => [50, 51, 50], 'PhpParser\Node\Expr\BinaryOp\ShiftLeft' => [60, 61, 60], 'PhpParser\Node\Expr\BinaryOp\ShiftRight' => [60, 61, 60], 'PhpParser\Node\Expr\BinaryOp\Smaller' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\SmallerOrEqual' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\Greater' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\GreaterOrEqual' => [70, 70, 70], 'PhpParser\Node\Expr\BinaryOp\Equal' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\NotEqual' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\Identical' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\NotIdentical' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\Spaceship' => [80, 80, 80], 'PhpParser\Node\Expr\BinaryOp\BitwiseAnd' => [90, 91, 90], 'PhpParser\Node\Expr\BinaryOp\BitwiseXor' => [100, 101, 100], 'PhpParser\Node\Expr\BinaryOp\BitwiseOr' => [110, 111, 110], 'PhpParser\Node\Expr\BinaryOp\BooleanAnd' => [120, 121, 120], 'PhpParser\Node\Expr\BinaryOp\BooleanOr' => [130, 131, 130], 'PhpParser\Node\Expr\BinaryOp\Coalesce' => [140, 140, 141], 'PhpParser\Node\Expr\Ternary' => [150, 150, 150], 'PhpParser\Node\Expr\Assign' => [160, -1, -1], 'PhpParser\Node\Expr\AssignRef' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Plus' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Minus' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Mul' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Div' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Concat' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Mod' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\BitwiseAnd' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\BitwiseOr' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\BitwiseXor' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\ShiftLeft' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\ShiftRight' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Pow' => [160, -1, -1], 'PhpParser\Node\Expr\AssignOp\Coalesce' => [160, -1, -1], 'PhpParser\Node\Expr\YieldFrom' => [170, -1, -1], 'PhpParser\Node\Expr\Yield_' => [175, -1, -1], 'PhpParser\Node\Expr\Print_' => [180, -1, -1], 'PhpParser\Node\Expr\BinaryOp\LogicalAnd' => [190, 191, 190], 'PhpParser\Node\Expr\BinaryOp\LogicalXor' => [200, 201, 200], 'PhpParser\Node\Expr\BinaryOp\LogicalOr' => [210, 211, 210], 'PhpParser\Node\Expr\Include_' => [220, -1, -1], 'PhpParser\Node\Expr\ArrowFunction' => [230, -1, -1], 'PhpParser\Node\Expr\Throw_' => [240, -1, -1]]
|
protected array $removalMap
|
protected bool $shortArraySyntax
|
Methods |
protected callLhsRequiresParens(PhpParser Determines whether the LHS of a call must be wrapped in parenthesis.
|
protected dereferenceLhsRequiresParens(PhpParser Determines whether the LHS of an array/object operation must be wrapped in parentheses.
|
protected handleMagicTokens(string $str) : string Handles (and removes) doc-string-end tokens. |
protected indent() : void Increase indentation level. |
protected initializeEmptyListInsertionMap() : void |
protected initializeFixupMap() : void Lazily initializes fixup map. The fixup map is used to determine whether a certain subnode of a certain node may require some kind of "fixup" operation, e.g. the addition of parenthesis or braces. |
protected initializeInsertionMap() : void |
protected initializeLabelCharMap() : void Lazily initializes label char map. The label char map determines whether a certain character may occur in a label. |
protected initializeListInsertionMap() : void |
protected initializeModifierChangeMap() : void |
protected initializeNodeListDiffer() : void Lazily initializes node list differ. The node list differ is used to determine differences between two array subnodes. |
protected initializeRemovalMap() : void Lazily initializes the removal map. The removal map is used to determine which additional tokens should be removed when a certain node is replaced by null. |
protected isMultiline(array $nodes) : bool Determine whether a list of nodes uses multiline formatting.
|
protected newOperandRequiresParens(PhpParser Determines whether an expression used in "new" or "instanceof" requires parentheses.
|
protected outdent() : void Decrease indentation level. |
protected p(PhpParser Pretty prints a node. This method also handles formatting preservation for nodes.
|
protected pArray(array $nodes, array $origNodes, int $pos, int $indentAdjustment, string $parentNodeClass, string $subNodeName, ?int $fixup) : ?string Perform a format-preserving pretty print of an array.
|
protected pCommaSeparated(array $nodes) : string Pretty prints an array of nodes and implodes the printed values with commas.
|
protected pCommaSeparatedMultiline(array $nodes, bool $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).
|
protected pComments(array $comments) : string Prints reformatted text of the passed comments.
|
protected pFallback(PhpParser |
protected pFixup(int $fixup, PhpParser Print node with fixups. Fixups here refer to the addition of extra parentheses, braces or other characters, that are required to preserve program semantics in a certain context (e.g. to maintain precedence or because only certain expressions are allowed in certain places).
|
protected pImplode(array $nodes, string $glue = '') : string Pretty prints an array of nodes and implodes the printed values.
|
protected pInfixOp(string $class, PhpParser Pretty-print an infix operation while taking precedence into account.
|
protected pModifiers(int $modifiers) : string Print modifiers, including trailing whitespace.
|
protected pPostfixOp(string $class, PhpParser Pretty-print a postfix operation while taking precedence into account.
|
protected pPrefixOp(string $class, string $operatorString, PhpParser Pretty-print a prefix operation while taking precedence into account.
|
protected preprocessNodes(array $nodes) : void Preprocesses the top-level nodes to initialize pretty printer state.
|
protected pStatic(bool $static) : string |
protected pStmts(array $nodes, bool $indent = true) : string Pretty prints an array of nodes (statements) and indents them optionally.
|
protected resetState() : void Reset pretty printing state. |
protected safeAppend(string $str, string $append) : void Appends to a string, ensuring whitespace between label characters. Example: "echo" and "$x" result in "echo$x", but "echo" and "x" result in "echo x". Without safeAppend the result would be "echox", which does not preserve semantics. |
protected setIndentLevel(int $level) : void Set indentation level
|
protected staticDereferenceLhsRequiresParens(PhpParser Determines whether the LHS of a static operation must be wrapped in parentheses.
|
Properties |
private string $indent
|
private int $indentWidth
|
private int $tabWidth = 4
|
private bool $useTabs
|