InterfaceDefinition::hasProperties()   A
last analyzed

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
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Code;
7
8
use PhUml\Code\Methods\Method;
9
use PhUml\Code\Properties\Constant;
10
use PhUml\Code\Properties\HasConstants;
11
use PhUml\Code\Properties\WithConstants;
12
13
/**
14
 * It represents an interface definition
15
 */
16
final class InterfaceDefinition extends Definition implements HasConstants
17
{
18
    use WithConstants;
19
20
    /** @var Name[] */
21
    private readonly array $parents;
22
23
    /**
24
     * @param Method[] $methods
25
     * @param Constant[] $constants
26
     * @param Name[] $parents
27
     */
28 52
    public function __construct(
29
        Name $name,
30
        array $methods = [],
31
        array $constants = [],
32
        array $parents = []
33
    ) {
34 52
        parent::__construct($name, $methods);
35 52
        $this->constants = $constants;
36 52
        $this->parents = $parents;
0 ignored issues
show
Bug introduced by
The property parents is declared read-only in PhUml\Code\InterfaceDefinition.
Loading history...
37
    }
38
39
    /**
40
     * It is used by the `InterfaceGraphBuilder` to create the edge to represent inheritance
41
     *
42
     * @return Name[]
43
     * @see \PhUml\Graphviz\Builders\InterfaceGraphBuilder::extractFrom() for more details
44
     */
45 25
    public function parents(): array
46
    {
47 25
        return $this->parents;
48
    }
49
50
    /**
51
     * It is used by the `InterfaceGraphBuilder` to determine if an inheritance association should be
52
     * created
53
     *
54
     * @see \PhUml\Graphviz\Builders\InterfaceGraphBuilder::extractFrom() for more details
55
     */
56 1
    public function hasParent(): bool
57
    {
58 1
        return $this->parents !== [];
59
    }
60
61
    /**
62
     * This method is used when the commands are called with the option `hide-empty-blocks`
63
     *
64
     * It only counts the constants of an interface, since interfaces are not allowed to have
65
     * properties
66
     *
67
     * @see Definition::hasProperties() for more details
68
     */
69 14
    public function hasProperties(): bool
70
    {
71 14
        return $this->constants !== [];
72
    }
73
}
74