final class Fields

Narrows decoded YAML, JSON and Markdown values to the shapes the definitions require.

Every accessor either returns the typed value or raises an InvalidInputException whose message names the context, so callers never handle loosely typed data themselves.

Methods§

public static function mapping(mixed $value, string $context): array<string, mixed>

Requires a mapping with string keys.

Parameters

$valuemixedThe decoded value
$contextstringThe name used in the error message

Returns

array<string, mixed> The mapping

Throws

InvalidInputException When the value is not a mapping with string keys
Test cases 11
Called from 33
Calls 3
public static function keys(
    array<string, mixed> $data,
    list<string> $allowed,
    string $context,
): void

Rejects keys that the context does not define.

Parameters

$dataarray<string, mixed>The mapping to check
$allowedlist<string>The keys the context defines
$contextstringThe name used in the error message

Throws

InvalidInputException When the mapping has a key outside the allowed list
Test cases 3
Called from 17
Calls 3
public static function text(
    array<string, mixed> $data,
    string $key,
    string|null $default = null,
): string

Reads a nonempty string field.

Parameters

$dataarray<string, mixed>The mapping holding the field
$keystringThe field name
$defaultstring|nullThe value used when the field is absent

Returns

string The field value

Throws

InvalidInputException When the value is missing, not a string or blank
Test cases 5
Called from 26
Calls 3
public static function sequence(mixed $value, string $context): list<mixed>

Requires a list.

Parameters

$valuemixedThe decoded value
$contextstringThe name used in the error message

Returns

list<mixed> The list

Throws

InvalidInputException When the value is not a list
Test cases 3
Called from 11
Calls 3
public static function strings(mixed $value, string $context, bool $unique = true): list<string>

Requires a list of nonempty strings.

Parameters

$valuemixedThe decoded value
$contextstringThe name used in the error message
$uniqueboolWhether duplicates are rejected

Returns

list<string> The strings

Throws

InvalidInputException When the value is not a list of nonempty strings or repeats one
Test cases 5
Called from 12
Calls 6
public static function percentage(mixed $value, string $context): float

Requires a finite number from 0 to 100.

Parameters

$valuemixedThe decoded value
$contextstringThe name used in the error message

Returns

float The percentage

Throws

InvalidInputException When the value is not a number within 0 to 100
Test cases 2
Called from 3
Calls 4

Test cases 65§

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

Dedicated tests 22
Other tests reaching this symbol 43

Relations§

Static calls 101