Lines
100.00%
13 / 13
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Snapshot | 100.00% | 13 / 13 | 100.00% | 2 / 2 | 2 | 100.00% | 1 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| fromParts | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Codegen\Snapshot; | |
| 6 | ||
| 7 | use Stewart\Client\Registry\Collection\EntityRegistryCollection; | |
| 8 | use Stewart\Client\Registry\EntityRegistryEntry; | |
| 9 | use Stewart\Contracts\Registry\Area; | |
| 10 | use Stewart\Contracts\Registry\Collection\AreaCollection; | |
| 11 | use Stewart\Contracts\Registry\Collection\FloorCollection; | |
| 12 | use Stewart\Contracts\Registry\Collection\LabelCollection; | |
| 13 | use Stewart\Contracts\Registry\Floor; | |
| 14 | use Stewart\Contracts\Registry\Label; | |
| 15 | use Stewart\Contracts\State\Collection\EntityStateCollection; | |
| 16 | use Stewart\Contracts\State\EntityState; | |
| 17 | ||
| 18 | final readonly class Snapshot | |
| 19 | { | |
| 20 | /** @param array<string, mixed> $services */ | |
| 21 | private function __construct( | |
| 22 | public string $haVersion, | |
| 23 | public EntityStateCollection $states, | |
| 24 | public EntityRegistryCollection $registry, | |
| 25 | public array $services, | |
| 26 | public AreaCollection $areas, | |
| 27 | public FloorCollection $floors, | |
| 28 | public LabelCollection $labels, | |
| 29 | ) {} | |
| 30 | ||
| 31 | /** | |
| 32 | * @param iterable<EntityState> $states | |
| 33 | * @param iterable<EntityRegistryEntry> $registry | |
| 34 | * @param array<string, mixed> $services | |
| 35 | * @param iterable<Area> $areas | |
| 36 | * @param iterable<Floor> $floors | |
| 37 | * @param iterable<Label> $labels | |
| 38 | */ | |
| 39 | public static function fromParts( | |
| 40 | string $haVersion, | |
| 41 | iterable $states, | |
| 42 | iterable $registry, | |
| 43 | array $services, | |
| 44 | iterable $areas = [], | |
| 45 | iterable $floors = [], | |
| 46 | iterable $labels = [], | |
| 47 | ): self { | |
| 48 | ksort($services); | |
| 49 | ||
| 50 | return new self( | |
| 51 | $haVersion, | |
| 52 | EntityStateCollection::keyedByEntityId($states)->sortedByEntityId(), | |
| 53 | EntityRegistryCollection::keyedByEntityId($registry)->sortedBy( | |
| 54 | static fn(EntityRegistryEntry $a, EntityRegistryEntry $b): int => strcmp($a->entityId->value, $b->entityId->value), | |
| 55 | ), | |
| 56 | $services, | |
| 57 | AreaCollection::keyedByAreaId($areas)->sortedBy(static fn(Area $a, Area $b): int => strcmp($a->areaId->value, $b->areaId->value)), | |
| 58 | FloorCollection::keyedByFloorId($floors)->sortedBy(static fn(Floor $a, Floor $b): int => strcmp($a->floorId->value, $b->floorId->value)), | |
| 59 | LabelCollection::keyedByLabelId($labels)->sortedBy(static fn(Label $a, Label $b): int => strcmp($a->labelId->value, $b->labelId->value)), | |
| 60 | ); | |
| 61 | } | |
| 62 | } |