Passed
Pull Request — 5.0 (#11)
by Luis
11:53 queued 09: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
eloc 16
dl 0
loc 40
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A equals() 0 3 1
A protected() 0 3 1
A __toString() 0 3 1
A public() 0 3 1
A private() 0 3 1
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.0
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;
0 ignored issues
show
Bug introduced by
The type Webmozart\Assert\Assert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
/**
14
 * It represents the visibility of either an attribute 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 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 97
    }
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