Passed
Push — 1.5 ( c7c5a4...fe8795 )
by Luis
06:06
created

InterfaceDefinition::hasParent()   A

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
2
/**
3
 * PHP version 7.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
/**
11
 * It represents an interface definition
12
 */
13
class InterfaceDefinition extends Definition
14
{
15
    /** @var Name[] */
16
    protected $parents;
17
18
    /**
19
     * @param \PhUml\Code\Attributes\Constant[] $constants
20
     * @param \PhUml\Code\Methods\Method[] $methods
21
     * @param Name[] $parents
22
     */
23 132
    public function __construct(
24
        Name $name,
25
        array $constants = [],
26
        array $methods = [],
27
        array $parents = []
28
    ) {
29 132
        parent::__construct($name, $constants, $methods);
30 132
        $this->parents = $parents;
31 132
    }
32
33
    /**
34
     * It is used by the `InterfaceGraphBuilder` to create the edge to represent inheritance
35
     *
36
     * @return Name[]
37
     * @see \PhUml\Graphviz\Builders\InterfaceGraphBuilder::extractFrom() for more details
38
     */
39 72
    public function parents(): array
40
    {
41 72
        return $this->parents;
42
    }
43
44
    /**
45
     * It is used by the `InterfaceGraphBuilder` to determine if an inheritance association should be
46
     * created
47
     *
48
     * @return InterfaceDefinition[]
49
     * @see \PhUml\Graphviz\Builders\InterfaceGraphBuilder::extractFrom() for more details
50
     */
51 3
    public function hasParent(): bool
52
    {
53 3
        return !empty($this->parents);
0 ignored issues
show
Bug Best Practice introduced by
The expression return ! empty($this->parents) returns the type boolean which is incompatible with the documented return type PhUml\Code\InterfaceDefinition[].
Loading history...
54
    }
55
56
    /**
57
     * This method is used when the commands are called with the option `hide-empty-blocks`
58
     *
59
     * It only counts the constants of an interface, since interfaces are not allowed to have
60
     * attributes
61
     *
62
     * @see Definition::hasAttributes() for more details
63
     */
64 45
    public function hasAttributes(): bool
65
    {
66 45
        return \count($this->constants) > 0;
67
    }
68
}
69