Passed
Push — variadic-params-visibility-con... ( ca0a66 )
by Luis
13:54
created

Constant::referenceName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 7.2
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 BadMethodCallException;
11
use PhUml\Code\Modifiers\HasVisibility;
12
use PhUml\Code\Modifiers\Visibility;
13
use PhUml\Code\Modifiers\WithVisibility;
14
use PhUml\Code\Name;
15
use PhUml\Code\Variables\HasType;
16
use PhUml\Code\Variables\TypeDeclaration;
17
use PhUml\Code\Variables\WithTypeDeclaration;
18
19
final class Constant implements HasType, HasVisibility
20
{
21
    use WithTypeDeclaration;
22
    use WithVisibility;
23
24
    /** @var string */
25
    private $name;
26
27
    public function __construct(string $name, TypeDeclaration $type, Visibility $visibility = null)
28
    {
29
        $this->name = $name;
30
        $this->type = $type;
31
        $this->modifier = $visibility ?? Visibility::public();
32
    }
33
34
    public function __toString()
35
    {
36
        return sprintf(
37
            '%s%s%s',
38
            $this->modifier,
39
            $this->name,
40
            $this->type->isPresent() ? ": {$this->type}" : ''
41
        );
42
    }
43
44
    public function referenceName(): Name
45
    {
46
        throw new BadMethodCallException('Constants must be built-in types');
47
    }
48
}
49