Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

InterfaceDefinition   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 56
ccs 11
cts 11
cp 1
rs 10
wmc 4
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.1
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;
9
10
use PhUml\Code\Methods\Method;
11
use PhUml\Code\Properties\Constant;
12
use PhUml\Code\Properties\HasConstants;
13
use PhUml\Code\Properties\WithConstants;
14
15
/**
16
 * It represents an interface definition
17
 */
18
final class InterfaceDefinition extends Definition implements HasConstants
19
{
20
    use WithConstants;
21
22
    /** @var Name[] */
23
    private readonly array $parents;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ARRAY, expecting T_VARIABLE on line 23 at column 21
Loading history...
24
25
    /**
26
     * @param Method[] $methods
27
     * @param Constant[] $constants
28
     * @param Name[] $parents
29
     */
30 39
    public function __construct(
31
        Name $name,
32
        array $methods = [],
33
        array $constants = [],
34
        array $parents = []
35
    ) {
36 39
        parent::__construct($name, $methods);
37 39
        $this->constants = $constants;
38 39
        $this->parents = $parents;
39
    }
40
41
    /**
42
     * It is used by the `InterfaceGraphBuilder` to create the edge to represent inheritance
43
     *
44
     * @return Name[]
45
     * @see \PhUml\Graphviz\Builders\InterfaceGraphBuilder::extractFrom() for more details
46
     */
47 20
    public function parents(): array
48
    {
49 20
        return $this->parents;
50
    }
51
52
    /**
53
     * It is used by the `InterfaceGraphBuilder` to determine if an inheritance association should be
54
     * created
55
     *
56
     * @see \PhUml\Graphviz\Builders\InterfaceGraphBuilder::extractFrom() for more details
57
     */
58 1
    public function hasParent(): bool
59
    {
60 1
        return $this->parents !== [];
61
    }
62
63
    /**
64
     * This method is used when the commands are called with the option `hide-empty-blocks`
65
     *
66
     * It only counts the constants of an interface, since interfaces are not allowed to have
67
     * properties
68
     *
69
     * @see Definition::hasProperties() for more details
70
     */
71 11
    public function hasProperties(): bool
72
    {
73 11
        return $this->constants !== [];
74
    }
75
}
76