Lines
42.30%
11 / 26
Functions and Methods
33.33%
7 / 21
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| RegistryCache | 42.30% | 11 / 26 | 33.33% | 7 / 21 | 114.94 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| replaceIfNewer | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 2 | |||||
| replaceAsNextRevision | 0.00% | 0 / 2 | 0.00% | 0 / 1 | 2 | |||||
| getRevision | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| getIndexedRegistry | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| listAreas | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| findArea | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| findAreaByName | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| listAreasOnFloor | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| listFloors | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findFloor | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findFloorByName | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| listLabels | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findLabel | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findLabelByName | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| listDevices | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findDevice | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| listDevicesInArea | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| listEntities | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findEntity | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| findEntityPlacement | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Registry; | |
| 6 | ||
| 7 | use Stewart\Contracts\Entity\EntityId; | |
| 8 | use Stewart\Contracts\Registry\Area; | |
| 9 | use Stewart\Contracts\Registry\AreaId; | |
| 10 | use Stewart\Contracts\Registry\Collection\AreaCollection; | |
| 11 | use Stewart\Contracts\Registry\Collection\DeviceCollection; | |
| 12 | use Stewart\Contracts\Registry\Collection\FloorCollection; | |
| 13 | use Stewart\Contracts\Registry\Collection\LabelCollection; | |
| 14 | use Stewart\Contracts\Registry\Collection\RegisteredEntityCollection; | |
| 15 | use Stewart\Contracts\Registry\Device; | |
| 16 | use Stewart\Contracts\Registry\DeviceId; | |
| 17 | use Stewart\Contracts\Registry\EntityPlacement; | |
| 18 | use Stewart\Contracts\Registry\Floor; | |
| 19 | use Stewart\Contracts\Registry\FloorId; | |
| 20 | use Stewart\Contracts\Registry\Label; | |
| 21 | use Stewart\Contracts\Registry\LabelId; | |
| 22 | use Stewart\Contracts\Registry\RegisteredEntity; | |
| 23 | use Stewart\Contracts\Registry\Registry; | |
| 24 | use Stewart\Support\State\IndexedRegistry; | |
| 25 | ||
| 26 | final class RegistryCache implements Registry | |
| 27 | { | |
| 28 | private IndexedRegistry $registry; | |
| 29 | ||
| 30 | private int $revision = 0; | |
| 31 | ||
| 32 | public function __construct() | |
| 33 | { | |
| 34 | $this->registry = IndexedRegistry::empty(); | |
| 35 | } | |
| 36 | ||
| 37 | public function replaceIfNewer(IndexedRegistry $registry, int $revision): bool | |
| 38 | { | |
| 39 | if ($revision <= $this->revision) { | |
| 40 | return false; | |
| 41 | } | |
| 42 | ||
| 43 | $this->registry = $registry; | |
| 44 | $this->revision = $revision; | |
| 45 | ||
| 46 | return true; | |
| 47 | } | |
| 48 | ||
| 49 | public function replaceAsNextRevision(IndexedRegistry $registry): void | |
| 50 | { | |
| 51 | $this->registry = $registry; | |
| 52 | ++$this->revision; | |
| 53 | } | |
| 54 | ||
| 55 | public function getRevision(): int | |
| 56 | { | |
| 57 | return $this->revision; | |
| 58 | } | |
| 59 | ||
| 60 | public function getIndexedRegistry(): IndexedRegistry | |
| 61 | { | |
| 62 | return $this->registry; | |
| 63 | } | |
| 64 | ||
| 65 | public function listAreas(): AreaCollection | |
| 66 | { | |
| 67 | return $this->registry->listAreas(); | |
| 68 | } | |
| 69 | ||
| 70 | public function findArea(AreaId|string $areaId): ?Area | |
| 71 | { | |
| 72 | return $this->registry->findArea($areaId); | |
| 73 | } | |
| 74 | ||
| 75 | public function findAreaByName(string $name): ?Area | |
| 76 | { | |
| 77 | return $this->registry->findAreaByName($name); | |
| 78 | } | |
| 79 | ||
| 80 | public function listAreasOnFloor(FloorId|string $floorId): AreaCollection | |
| 81 | { | |
| 82 | return $this->registry->listAreasOnFloor($floorId); | |
| 83 | } | |
| 84 | ||
| 85 | public function listFloors(): FloorCollection | |
| 86 | { | |
| 87 | return $this->registry->listFloors(); | |
| 88 | } | |
| 89 | ||
| 90 | public function findFloor(FloorId|string $floorId): ?Floor | |
| 91 | { | |
| 92 | return $this->registry->findFloor($floorId); | |
| 93 | } | |
| 94 | ||
| 95 | public function findFloorByName(string $name): ?Floor | |
| 96 | { | |
| 97 | return $this->registry->findFloorByName($name); | |
| 98 | } | |
| 99 | ||
| 100 | public function listLabels(): LabelCollection | |
| 101 | { | |
| 102 | return $this->registry->listLabels(); | |
| 103 | } | |
| 104 | ||
| 105 | public function findLabel(LabelId|string $labelId): ?Label | |
| 106 | { | |
| 107 | return $this->registry->findLabel($labelId); | |
| 108 | } | |
| 109 | ||
| 110 | public function findLabelByName(string $name): ?Label | |
| 111 | { | |
| 112 | return $this->registry->findLabelByName($name); | |
| 113 | } | |
| 114 | ||
| 115 | public function listDevices(): DeviceCollection | |
| 116 | { | |
| 117 | return $this->registry->listDevices(); | |
| 118 | } | |
| 119 | ||
| 120 | public function findDevice(DeviceId|string $deviceId): ?Device | |
| 121 | { | |
| 122 | return $this->registry->findDevice($deviceId); | |
| 123 | } | |
| 124 | ||
| 125 | public function listDevicesInArea(AreaId|string $areaId): DeviceCollection | |
| 126 | { | |
| 127 | return $this->registry->listDevicesInArea($areaId); | |
| 128 | } | |
| 129 | ||
| 130 | public function listEntities(): RegisteredEntityCollection | |
| 131 | { | |
| 132 | return $this->registry->listEntities(); | |
| 133 | } | |
| 134 | ||
| 135 | public function findEntity(EntityId|string $entityId): ?RegisteredEntity | |
| 136 | { | |
| 137 | return $this->registry->findEntity($entityId); | |
| 138 | } | |
| 139 | ||
| 140 | public function findEntityPlacement(EntityId|string $entityId): EntityPlacement | |
| 141 | { | |
| 142 | return $this->registry->findEntityPlacement($entityId); | |
| 143 | } | |
| 144 | } |