Lines
75.00%
3 / 4
Functions and Methods
75.00%
3 / 4
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| SubscriptionRoutes | 75.00% | 3 / 4 | 75.00% | 3 / 4 | 4.25 | 0.00% | 0 / 1 | |||
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| listSubscriptionIdsForWorker | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| listWorkerIds | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | |||||
| isEmpty | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace Stewart\Runtime\Broker; | |
| 6 | ||
| 7 | use Stewart\Runtime\Model\Collection\SubscriptionIdCollection; | |
| 8 | use Stewart\Runtime\Model\Collection\WorkerIdCollection; | |
| 9 | use Stewart\Runtime\Model\WorkerId; | |
| 10 | ||
| 11 | final readonly class SubscriptionRoutes | |
| 12 | { | |
| 13 | /** @param array<int, SubscriptionIdCollection> $subscriptionIdsByWorker */ | |
| 14 | public function __construct(private array $subscriptionIdsByWorker = []) {} | |
| 15 | ||
| 16 | public function listSubscriptionIdsForWorker(WorkerId $workerId): SubscriptionIdCollection | |
| 17 | { | |
| 18 | return $this->subscriptionIdsByWorker[$workerId->value] ?? SubscriptionIdCollection::empty(); | |
| 19 | } | |
| 20 | ||
| 21 | public function listWorkerIds(): WorkerIdCollection | |
| 22 | { | |
| 23 | return WorkerIdCollection::fromList(array_map(WorkerId::fromInt(...), array_keys($this->subscriptionIdsByWorker))); | |
| 24 | } | |
| 25 | ||
| 26 | public function isEmpty(): bool | |
| 27 | { | |
| 28 | return $this->subscriptionIdsByWorker === []; | |
| 29 | } | |
| 30 | } |