Lines
92.85%
13 / 14
Methods
75.00%
3 / 4
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| none | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromRaw | 90.90% | 10 / 11 | 0.00% | 0 / 1 | 5.02 | ||
| acceptsDomain | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 3 | ||
| 9 | final readonly class ServiceTargetSpec | |
| 10 | { | |
| 11 | /** @param list<string> $entityDomains */ | |
| 12 | private function __construct( | |
| 13 | public bool $isTargetable, | |
| 14 | public bool $acceptsEntities, | |
| 15 | public array $entityDomains, | |
| 16 | ) {} | |
| 17 | ||
| 18 | private static function none(): self | |
| 19 | { | |
| 20 | return new self(false, false, []); | |
| 21 | } | |
| 22 | ||
| 23 | public static function fromRaw(RawMap $service): self | |
| 24 | { | |
| 25 | if (!$service->hasKey('target')) { | |
| 26 | return self::none(); | |
| 27 | } | |
| 28 | ||
| 29 | $target = $service->readMap('target'); | |
| 30 | ||
| 31 | if (!$target->hasKey('entity')) { | |
| 32 | return new self(true, false, []); | |
| 33 | } | |
| 34 | ||
| 35 | $domains = []; | |
| 36 | ||
| 37 | foreach ($target->listMaps('entity') as $selector) { | |
| 38 | foreach ($selector->listStrings('domain') as $domain) { | |
| 39 | $domains[$domain] = true; | |
| 40 | } | |
| 41 | } | |
| 42 | ||
| 43 | ksort($domains); | |
| 44 | ||
| 45 | return new self(true, true, array_keys($domains)); | |
| 46 | } | |
| 47 | ||
| 48 | public function acceptsDomain(string $domain): bool | |
| 49 | { | |
| 50 | return $this->acceptsEntities && ($this->entityDomains === [] || \in_array($domain, $this->entityDomains, true)); | |
| 51 | } | |
| 52 | } |