Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

Visibility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 40
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Code\Modifiers;
9
10
use Stringable;
11
use Webmozart\Assert\Assert;
12
13
/**
14
 * It represents the visibility of either a property or a method
15
 */
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;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 25 at column 21
Loading history...
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
    }
57
}
58