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