Completed
Push — statistics_refactoring ( b2d9c2 )
by Luis
13:39
created

Visibility::protected()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.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;
9
10
/**
11
 * It represents the visibility of either an attribute or a method
12
 */
13
class Visibility
14
{
15
    private static $symbols = [
16
        'private' => '-',
17
        'public' => '+',
18
        'protected' => '#',
19
    ];
20
21
    /** @var string*/
22
    private $modifier;
23
24
    private function __construct(string $modifier)
25
    {
26
        $this->modifier = $modifier;
27
    }
28
29
    public static function public(): Visibility
30
    {
31
        return new Visibility('public');
32
    }
33
34
    public static function protected(): Visibility
35
    {
36
        return new Visibility('protected');
37
    }
38
39
    public static function private(): Visibility
40
    {
41
        return new Visibility('private');
42
    }
43
44
    public function equals(Visibility $another): bool
45
    {
46
        return $this->modifier === $another->modifier;
47
    }
48
49
    public function __toString()
50
    {
51
        return sprintf('%s', self::$symbols[$this->modifier]);
52
    }
53
}
54