Passed
Push — 5.0 ( 674e23...50290c )
by Luis
38s queued 11s
created

Visibility::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
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 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