Completed
Push — master ( 389baa...c7c5a4 )
by Luis
14:17 queued 08:06
created

Visibility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 3 1
A protected() 0 3 1
A __toString() 0 3 1
A public() 0 3 1
A __construct() 0 3 1
A private() 0 3 1
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\Modifiers;
9
10
/**
11
 * It represents the visibility of either an attribute or a method
12
 */
13
class Visibility
14
{
15
    /** @var string[] */
16
    private static $symbols = [
17
        'private' => '-',
18
        'public' => '+',
19
        'protected' => '#',
20
    ];
21
22
    /** @var string */
23
    private $modifier;
24
25 174
    private function __construct(string $modifier)
26
    {
27 174
        $this->modifier = $modifier;
28 174
    }
29
30 150
    public static function public(): Visibility
31
    {
32 150
        return new Visibility('public');
33
    }
34
35 78
    public static function protected(): Visibility
36
    {
37 78
        return new Visibility('protected');
38
    }
39
40 90
    public static function private(): Visibility
41
    {
42 90
        return new Visibility('private');
43
    }
44
45 30
    public function equals(Visibility $another): bool
46
    {
47 30
        return $this->modifier === $another->modifier;
48
    }
49
50 69
    public function __toString()
51
    {
52 69
        return sprintf('%s', self::$symbols[$this->modifier]);
53
    }
54
}
55