Lines
0.00%
0 / 12
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ValueShape | 0.00% | 0 / 12 | 0.00% | 0 / 2 | 182 | 0.00% | 0 / 1 | |||
| __construct | 0.00% | 0 / 4 | 0.00% | 0 / 1 | 30 | |||||
| describeExpectedValue | 0.00% | 0 / 8 | 0.00% | 0 / 1 | 72 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Json; | |
| 6 | ||
| 7 | use Stewart\Contracts\Wire\WireVariants; | |
| 8 | ||
| 9 | final readonly class ValueShape | |
| 10 | { | |
| 11 | public bool $passesThrough; | |
| 12 | ||
| 13 | public function __construct( | |
| 14 | public ValueKind $kind, | |
| 15 | public string $type = '', | |
| 16 | public ?ValueShape $element = null, | |
| 17 | public ?ValueConverter $converter = null, | |
| 18 | public string $enumBackingType = '', | |
| 19 | public ?WireVariants $variants = null, | |
| 20 | ) { | |
| 21 | $this->passesThrough = match ($kind) { | |
| 22 | ValueKind::String, ValueKind::Int, ValueKind::Float, ValueKind::Number, ValueKind::Bool, ValueKind::Json => true, | |
| 23 | ValueKind::List => $element !== null && $element->passesThrough, | |
| 24 | default => false, | |
| 25 | }; | |
| 26 | } | |
| 27 | ||
| 28 | public function describeExpectedValue(): string | |
| 29 | { | |
| 30 | return match ($this->kind) { | |
| 31 | ValueKind::String => 'a string', | |
| 32 | ValueKind::Int => 'a whole number', | |
| 33 | ValueKind::Float, ValueKind::Number => 'a number', | |
| 34 | ValueKind::Bool => 'true or false', | |
| 35 | ValueKind::List => 'a list', | |
| 36 | ValueKind::Json => 'a JSON value', | |
| 37 | default => 'an object', | |
| 38 | }; | |
| 39 | } | |
| 40 | } |