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
EntityAlias 100.00% 5 / 5 100.00% 5 / 5 5 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 named 100.00% 1 / 1 100.00% 1 / 1 1
 entityName 100.00% 1 / 1 100.00% 1 / 1 1
 isEntityName 100.00% 1 / 1 100.00% 1 / 1 1
 equals 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Registry;
6
7// A null phrase stands for the entity's own name, as Home Assistant stores it.
8final readonly class EntityAlias
9{
10    public function __construct(public ?string $phrase) {}
11
12    public static function named(string $phrase): self
13    {
14        return new self($phrase);
15    }
16
17    public static function entityName(): self
18    {
19        return new self(null);
20    }
21
22    public function isEntityName(): bool
23    {
24        return $this->phrase === null;
25    }
26
27    public function equals(self $other): bool
28    {
29        return $this->phrase === $other->phrase;
30    }
31}