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
Device 75.00% 3 / 4 75.00% 3 / 4 4.25 0.00% 0 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 getDisplayName 100.00% 1 / 1 100.00% 1 / 1 1
 listLabelIds 0.00% 0 / 1 0.00% 0 / 1 2
 isDisabled 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Registry;
6
7use Stewart\Contracts\Registry\Collection\LabelIdCollection;
8use Stewart\Contracts\Wire\ListOf;
9
10final readonly class Device
11{
12    /** @param list<LabelId> $labelIds */
13    public function __construct(
14        public DeviceId $deviceId,
15        public ?string $name = null,
16        public ?string $nameByUser = null,
17        public ?AreaId $areaId = null,
18        #[ListOf(LabelId::class)]
19        public array $labelIds = [],
20        public ?string $manufacturer = null,
21        public ?string $model = null,
22        public ?string $disabledBy = null,
23    ) {}
24
25    public function getDisplayName(): ?string
26    {
27        return $this->nameByUser ?? $this->name;
28    }
29
30    public function listLabelIds(): LabelIdCollection
31    {
32        return LabelIdCollection::fromList($this->labelIds);
33    }
34
35    public function isDisabled(): bool
36    {
37        return $this->disabledBy !== null;
38    }
39}