final class Domain
Restricted visibility: declared "@visibility root". Code outside that scope must not name this declaration.

Every value an expression may take, over-approximated.

A domain is a bounded set of alternatives. Keeping the set means a query built from an enum-typed parameter is reported as the handful of statements it can actually be, instead of one statement with a gap. When the set would grow past the bound it is generalized into a single shape that still covers all of it, so the approximation only ever widens.

Constants§

public const MAX_TERMS = 12

How many alternatives a domain keeps before generalizing them into one shape.

Properties§

public list<Term> $terms
public bool $widened
public bool $combined = false

Methods§

public static function of(Term $term): self

The domain holding exactly one alternative.

Parameters

$termTerm

Returns

self
Test cases 95
Called from 39
Calls 1
public static function literal(string|int|float|bool|null $value): self

The domain holding one resolved scalar.

Parameters

$valuestring|int|float|bool|null

Returns

self
Test cases 325
Called from 120
Calls 2
public static function opaque(TypeShape $type, Origin $origin, ?string $expression = null): self

The domain of values known only by type and origin.

Parameters

$typeTypeShape
$originOrigin
$expression?string

Returns

self
Test cases 18
Called from 70
Calls 2
public static function unknown(?string $expression = null): self

The domain of a value nothing is known about.

Parameters

$expression?string

Returns

self
Test cases 55
Called from 41
Calls 2
public static function fromTerms(
    list<Term> $terms,
    bool $widened = false,
    bool $combined = false,
): self

The domain built from a set of alternatives, deduplicated and bounded.

Parameters

$termslist<Term>
$widenedbool
$combinedbool

Returns

self
Test cases 19
Called from 16
Calls 7
public function union(self $other): self

The domain admitting every value either domain admits.

Parameters

$otherself

Returns

self
Calls 2
public function concat(self $other): self

The domain of the strings produced by writing this domain then the other.

Pairing two sides that each hold several alternatives produces every combination of them, and nothing here can tell which combinations the program can actually reach. The result is marked as combined so that a report can say the alternatives may be wider than the code allows.

Parameters

$otherself

Returns

self
Calls 3
public function select(self $keys, ?string $expression = null): ?self

The elements the keys select from this domain's arrays, or null when that is not known.

A resolved key reads the element written under it; a key that did not resolve reads whatever element the array holds. Every alternative here must be an array and every resolved key must find its element, so a lookup never resolves to a value the array does not hold. Keys paired from parts that vary independently select elements that are paired the same way, so the result stays marked as combined.

Parameters

$keysself
$expression?string

Returns

?self
Calls 2
public function collapse(Origin $origin): self

The domain narrowed to a single shape covering all of its alternatives.

Parameters

$originOrigin

Returns

self
Calls 3
public function soleLiteral(): ?LiteralTerm

The one resolved scalar this domain holds, or null when it holds anything else.

Returns

Test cases 23
Called from 2
Calls 1
public function withVariable(string $variable): self

Labels opaque alternatives with the PHP variable read at their use site.

Provenance, resolved fragments, comparison signatures and domain flags remain unchanged; the name is only an annotation for report readers.

Parameters

$variablestring

Returns

self
Calls 4
public function patterns(): list<TextPattern>

The alternatives written as string patterns.

Returns

Test cases 1
public function isExact(): bool

Whether every alternative resolves to an exact string.

Returns

bool
public function equals(self $other): bool

Whether the two domains describe the same set of values.

Parameters

$otherself

Returns

bool
Calls 2

Private surface 2§

Implementation details, listed for orientation only.

private ?string $signature = null
private function __construct(
    public list<Term> $terms,
    public bool $widened,
    public bool $combined = false,
)

Test cases 403§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 32
Other tests reaching this symbol 371

Relations§

Static calls 280
Method calls 26
Type declarations 116