Total Complexity | 8 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
12 | final class Name |
||
13 | { |
||
14 | private $value; |
||
15 | |||
16 | 189 | public function __construct(string $value) |
|
17 | { |
||
18 | 189 | $value = Str::of($value); |
|
19 | |||
20 | 189 | if ($value->empty()) { |
|
21 | 1 | throw new NameMustContainAtLeastACharacter; |
|
22 | } |
||
23 | |||
24 | 188 | $this->value = $value; |
|
25 | 188 | } |
|
26 | |||
27 | 31 | public function root(): self |
|
28 | { |
||
29 | 31 | $namespace = $this->value->split('.'); |
|
30 | |||
31 | 31 | if ($namespace->size() === 1) { |
|
32 | 14 | throw new NameNotNamespaced((string) $this->value); |
|
33 | } |
||
34 | |||
35 | 19 | return new self((string) $namespace->first()); |
|
36 | } |
||
37 | |||
38 | 14 | public function withoutRoot(): self |
|
47 | } |
||
48 | |||
49 | 5 | public function equals(self $other): bool |
|
50 | { |
||
51 | 5 | return (string) $this === (string) $other; |
|
52 | } |
||
53 | |||
54 | 173 | public function __toString(): string |
|
57 | } |
||
58 | } |
||
59 |