Lines
100.00%
4 / 4
Functions and Methods
100.00%
4 / 4
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| HistoricalStatesFragment | 100.00% | 4 / 4 | 100.00% | 4 / 4 | 4 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromCollection | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromDecodedValue | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| encodeToJson | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Ipc\Wire; | |
| 6 | ||
| 7 | use Stewart\Contracts\History\Collection\HistoricalStateCollection; | |
| 8 | use Stewart\Contracts\State\EntityState; | |
| 9 | use Stewart\Runtime\Json\JsonFragment; | |
| 10 | use Stewart\Runtime\Json\WireMapper; | |
| 11 | ||
| 12 | final class HistoricalStatesFragment implements JsonFragment | |
| 13 | { | |
| 14 | private ?string $json = null; | |
| 15 | ||
| 16 | private function __construct(public readonly HistoricalStateCollection $collection) {} | |
| 17 | ||
| 18 | public static function fromCollection(HistoricalStateCollection $states): self | |
| 19 | { | |
| 20 | return new self($states); | |
| 21 | } | |
| 22 | ||
| 23 | public static function fromDecodedValue(mixed $value, string $path, WireMapper $mapper): static | |
| 24 | { | |
| 25 | return new self(HistoricalStateCollection::fromList($mapper->decodeObjectList(EntityState::class, $value, $path))); | |
| 26 | } | |
| 27 | ||
| 28 | public function encodeToJson(WireMapper $mapper): string | |
| 29 | { | |
| 30 | return $this->json ??= $mapper->encodeObjectList($this->collection->listValues()); | |
| 31 | } | |
| 32 | } |