Lines
100.00%
6 / 6
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| __construct | 100.00% | 1 / 1 | 100.00% | 1 / 1 | 1 | ||
| fromCurrentUserResult | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | ||
| 9 | final readonly class HaUser | |
| 10 | { | |
| 11 | public function __construct( | |
| 12 | public string $id, | |
| 13 | public ?string $name, | |
| 14 | public bool $isAdmin, | |
| 15 | ) {} | |
| 16 | ||
| 17 | /** | |
| 18 | * @param array<array-key, mixed> $result | |
| 19 | * @throws HaClientException | |
| 20 | */ | |
| 21 | public static function fromCurrentUserResult(array $result): self | |
| 22 | { | |
| 23 | $id = $result['id'] ?? null; | |
| 24 | $name = $result['name'] ?? null; | |
| 25 | ||
| 26 | if (!\is_string($id) || $id === '') { | |
| 27 | throw HaClientException::protocolViolation('a current user without an id'); | |
| 28 | } | |
| 29 | ||
| 30 | return new self($id, \is_string($name) ? $name : null, ($result['is_admin'] ?? false) === true); | |
| 31 | } | |
| 32 | } |