Lines
100.00%
13 / 13
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromParts | 100.00% | 12 / 12 | 100.00% | 1 / 1 | 1 | ||
| 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 | } |