Passed
Push — 5.0 ( d46d5f )
by Luis
39s queued 12s
created

Constant::referenceName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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\Attributes;
9
10
use PhUml\Code\Modifiers\HasVisibility;
11
use PhUml\Code\Modifiers\Visibility;
12
use PhUml\Code\Modifiers\WithVisibility;
13
use PhUml\Code\Name;
14
use PhUml\Code\Variables\HasType;
15
use PhUml\Code\Variables\TypeDeclaration;
16
use PhUml\Code\Variables\WithTypeDeclaration;
17
use Stringable;
18
19
final class Constant implements HasType, HasVisibility, Stringable
20
{
21 57
    use WithTypeDeclaration;
22
    use WithVisibility;
23 57
24 57
    public function __construct(private string $name, TypeDeclaration $type, Visibility $visibility)
25 57
    {
26
        $this->type = $type;
27 42
        $this->modifier = $visibility;
28
    }
29 42
30 42
    public function __toString(): string
31 42
    {
32 42
        return sprintf(
33
            '%s%s%s',
34
            $this->modifier,
35
            $this->name,
36
            $this->type->isPresent() ? ": {$this->type}" : ''
37
        );
38
    }
39
40
    /** @return Name[] */
41
    public function references(): array
42
    {
43
        return []; // Constants can only be built-in types
44
    }
45
}
46