Passed
Pull Request — master (#30)
by
unknown
46:28 queued 21:27
created

Constant   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 7 2
A references() 0 3 1
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Code\Properties;
7
8
use PhUml\Code\Modifiers\HasVisibility;
9
use PhUml\Code\Modifiers\Visibility;
10
use PhUml\Code\Modifiers\WithVisibility;
11
use PhUml\Code\Name;
12
use PhUml\Code\Variables\HasType;
13
use PhUml\Code\Variables\TypeDeclaration;
14
use PhUml\Code\Variables\WithTypeDeclaration;
15
use Stringable;
16
17
final class Constant implements HasType, HasVisibility, Stringable
18
{
19
    use WithTypeDeclaration;
20
    use WithVisibility;
21
22 27
    public function __construct(private readonly string $name, TypeDeclaration $type, Visibility $visibility)
23
    {
24 27
        $this->type = $type;
25 27
        $this->visibility = $visibility;
0 ignored issues
show
Bug introduced by
The property visibility is declared read-only in PhUml\Code\Properties\Constant.
Loading history...
26
    }
27
28 13
    public function __toString(): string
29
    {
30 13
        return sprintf(
31
            '%s%s%s',
32 13
            $this->visibility->value,
33 13
            $this->name,
34 13
            $this->type->isPresent() ? ": {$this->type}" : ''
35
        );
36
    }
37
38
    /** @return Name[] */
39 1
    public function references(): array
40
    {
41 1
        return []; // Constants can only be built-in types
42
    }
43
}
44