php-dextrin

Formatter
in package

FinalYes

A document laid out the way the pretty printer lays out a value -- every non-empty collection over lines, one entry per line, indented -- with every comment kept beside the entry it belongs to, mirroring `Dextrin.Document.Formatter`.

Layout only. Every token is written exactly as it was -- a literal's spelling, a key's form, an escape -- and only the space between tokens changes: indentation, line breaks, commas, and blank lines, of which at most one is kept wherever the source had any between entries. A document with no comments therefore comes out as the pretty printer writes its value.

Where a comment goes, by lines alone: a comment on the line of the token or entry before it trails that, and so does every comment line straight after it, aligned under its #; any other block of comment lines goes above the next entry, or at the end of its collection when none follows. A comment between a key or a tag and its value stays between them, and the value moves to the next line.

Tags
phpstan-type

Part array{gap: string}|array{node: SyntaxNode}

Table of Contents

Properties

$doc  : Document
$step  : string
$width  : int

Methods

format()  : string
The text of `$doc`, laid out, `$indent` spaces per level; `$width` is the columns a nested collection's one line must fit in.
__construct()  : mixed
aboveLines()  : string
between()  : string
`$prefix` and the value after it: on one line, or, with a comment between them, the comment beside the prefix and the value on the next line, a level deeper.
bodyText()  : string
collection()  : string
A collection: its opening tokens after `$head`, its entries one per line a level deeper, its closing token -- or `[]` when it holds nothing, not even a comment. Nested, holding no comment or blank line, and fitting `$room`, it goes on one line instead.
commentsIn()  : array<int, string>
end()  : int
headerText()  : string
The header, `@dxn "1.0"`: the tag, one space, and the version, each as written, however they were spaced. The tag is two tokens here (`@`, `dxn`), so the space goes before the version alone.
item()  : string
lines()  : string
A container's entries and comments, one line each at `$indent`.
oneLine()  : string
A collection's entries single-space separated between its brackets.
plain()  : bool
Whether `$node` holds no comment and no blank line between any of its tokens, however deep: what may go on one line.
slots()  : Block>}
A container's inside, as what is laid out: each entry with the comment blocks above it and the block trailing it, the blocks at its end, and the block trailing whatever opened it when `$onLine` -- a comment straight after `[` stays beside it.
start()  : int
tokensText()  : string
The tokens `$first..$last`, written together without the trivia between them.
trailed()  : string
`$text` with its trailing comments: the first two spaces after its last line, the rest aligned under it.
valueText()  : string
`$node` laid out at `$indent`, with `$room` columns left on its line; `$flat` inside a one-line collection.

Properties

Methods

format()

The text of `$doc`, laid out, `$indent` spaces per level; `$width` is the columns a nested collection's one line must fit in.

public static format(Document $doc[, int $indent = 2 ][, int $width = 80 ]) : string
Parameters
$doc : Document
$indent : int = 2
$width : int = 80
Return values
string

__construct()

private __construct(Document $doc, string $step, int $width) : mixed
Parameters
$doc : Document
$step : string
$width : int

aboveLines()

private aboveLines(array<int, Block> $blocks, string $indent) : string
Parameters
$blocks : array<int, Block>
$indent : string
Return values
string

between()

`$prefix` and the value after it: on one line, or, with a comment between them, the comment beside the prefix and the value on the next line, a level deeper.

private between(string $prefix, array<int, string> $comments, callable(string, int): string $render, string $indent, int $room) : string
Parameters
$prefix : string
$comments : array<int, string>
$render : callable(string, int): string

takes the indent of the value's line and the room left on it

$indent : string
$room : int
Return values
string

bodyText()

private bodyText(SyntaxNode $body, string $indent, int $room, bool $flat) : string
Parameters
$body : SyntaxNode
$indent : string
$room : int
$flat : bool
Return values
string

collection()

A collection: its opening tokens after `$head`, its entries one per line a level deeper, its closing token -- or `[]` when it holds nothing, not even a comment. Nested, holding no comment or blank line, and fitting `$room`, it goes on one line instead.

private collection(SyntaxNode $node, string $head, string $indent, int $room, bool $flat) : string
Parameters
$node : SyntaxNode
$head : string
$indent : string
$room : int
$flat : bool
Return values
string

commentsIn()

private static commentsIn(string $gap) : array<int, string>
Parameters
$gap : string
Return values
array<int, string>

headerText()

The header, `@dxn "1.0"`: the tag, one space, and the version, each as written, however they were spaced. The tag is two tokens here (`@`, `dxn`), so the space goes before the version alone.

private headerText(int $first, int $last) : string
Parameters
$first : int
$last : int
Return values
string

item()

private item(SyntaxNode $node, string $indent, int $room, bool $flat) : string
Parameters
$node : SyntaxNode
$indent : string
$room : int
$flat : bool
Return values
string

lines()

A container's entries and comments, one line each at `$indent`.

private lines(Block>} $laid, string $indent, callable(SyntaxNode): string $render) : string
Parameters
$laid : Block>}
$indent : string
$render : callable(SyntaxNode): string
Return values
string

oneLine()

A collection's entries single-space separated between its brackets.

private oneLine(array<int, Slot> $entries, string $open, string $close, string $indent) : string
Parameters
$entries : array<int, Slot>
$open : string
$close : string
$indent : string
Return values
string

plain()

Whether `$node` holds no comment and no blank line between any of its tokens, however deep: what may go on one line.

private plain(SyntaxNode $node) : bool
Parameters
$node : SyntaxNode
Return values
bool

slots()

A container's inside, as what is laid out: each entry with the comment blocks above it and the block trailing it, the blocks at its end, and the block trailing whatever opened it when `$onLine` -- a comment straight after `[` stays beside it.

private slots(array<int, Part> $sequence, bool $onLine) : Block>}
Parameters
$sequence : array<int, Part>
$onLine : bool
Return values
Block>}

tokensText()

The tokens `$first..$last`, written together without the trivia between them.

private tokensText(int $first, int $last) : string
Parameters
$first : int
$last : int
Return values
string

trailed()

`$text` with its trailing comments: the first two spaces after its last line, the rest aligned under it.

private trailed(string $text, array<int, string> $comments) : string
Parameters
$text : string
$comments : array<int, string>
Return values
string

valueText()

`$node` laid out at `$indent`, with `$room` columns left on its line; `$flat` inside a one-line collection.

private valueText(SyntaxNode $node, string $indent, int $room[, bool $flat = false ]) : string
Parameters
$node : SyntaxNode
$indent : string
$room : int
$flat : bool = false
Return values
string
On this page

Search results