Passed
Push — master ( d09870...716959 )
by Luis
02:38
created

Visibility::public()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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 144
    private function __construct(string $modifier)
25
    {
26 144
        $this->modifier = $modifier;
27 144
    }
28
29 132
    public static function public(): Visibility
30
    {
31 132
        return new Visibility('public');
32
    }
33
34 54
    public static function protected(): Visibility
35
    {
36 54
        return new Visibility('protected');
37
    }
38
39 66
    public static function private(): Visibility
40
    {
41 66
        return new Visibility('private');
42
    }
43
44 12
    public function equals(Visibility $another): bool
45
    {
46 12
        return $this->modifier === $another->modifier;
47
    }
48
49 33
    public function __toString()
50
    {
51 33
        return sprintf('%s', self::$symbols[$this->modifier]);
52
    }
53
}
54