|
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; |
|
|
|
|
|
|
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
|
|
|
|