Total Complexity | 6 |
Total Lines | 40 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
16 | final class Visibility implements Stringable |
||
17 | { |
||
18 | /** @var string[] */ |
||
19 | private const SYMBOLS = [ |
||
20 | 'private' => '-', |
||
21 | 'public' => '+', |
||
22 | 'protected' => '#', |
||
23 | ]; |
||
24 | |||
25 | private readonly string $modifier; |
||
|
|||
26 | |||
27 | 98 | public function __construct(string $modifier) |
|
28 | { |
||
29 | 98 | Assert::oneOf($modifier, array_keys(self::SYMBOLS)); |
|
30 | 97 | $this->modifier = $modifier; |
|
31 | } |
||
32 | |||
33 | 61 | public static function public(): Visibility |
|
34 | { |
||
35 | 61 | return new Visibility('public'); |
|
36 | } |
||
37 | |||
38 | 38 | public static function protected(): Visibility |
|
39 | { |
||
40 | 38 | return new Visibility('protected'); |
|
41 | } |
||
42 | |||
43 | 50 | public static function private(): Visibility |
|
44 | { |
||
45 | 50 | return new Visibility('private'); |
|
46 | } |
||
47 | |||
48 | 19 | public function equals(Visibility $another): bool |
|
49 | { |
||
50 | 19 | return $this->modifier === $another->modifier; |
|
51 | } |
||
52 | |||
53 | 23 | public function __toString(): string |
|
54 | { |
||
55 | 23 | return self::SYMBOLS[$this->modifier]; |
|
56 | } |
||
58 |