Constant::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
c 0
b 0
f 0
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;
0 ignored issues
show
Bug introduced by
The type PhUml\Code\Modifiers\Visibility 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...
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 28
    public function __construct(private readonly string $name, TypeDeclaration $type, Visibility $visibility)
23
    {
24 28
        $this->type = $type;
25 28
        $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