Total Complexity | 9 |
Total Lines | 93 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class Resource implements ResourceInterface |
||
14 | { |
||
15 | /** @var string */ |
||
16 | private string $id; |
||
17 | |||
18 | /** @var ResourceInterface[] */ |
||
19 | private array $parents; |
||
20 | |||
21 | /** @var ResourceInterface[] */ |
||
22 | private array $children; |
||
23 | |||
24 | /** |
||
25 | * Resource constructor. |
||
26 | * |
||
27 | * @param string $id |
||
28 | */ |
||
29 | public function __construct(string $id) |
||
30 | { |
||
31 | $this->id = $id; |
||
32 | $this->parents = []; |
||
33 | $this->children = []; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @inheritdoc |
||
38 | */ |
||
39 | public function __toString(): string |
||
40 | { |
||
41 | return $this->id; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | public function addParent(ResourceInterface $resource): ResourceInterface |
||
48 | { |
||
49 | $this->parents[(string)$resource] = $resource; |
||
50 | |||
51 | return $this; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | */ |
||
57 | public function removeParent(ResourceInterface $resource): ResourceInterface |
||
58 | { |
||
59 | unset($this->parents[(string)$resource]); |
||
60 | |||
61 | return $this; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | */ |
||
67 | public function parents(): array |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @inheritdoc |
||
74 | */ |
||
75 | public function hasParents(): bool |
||
76 | { |
||
77 | return !empty($this->parents); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @inheritdoc |
||
82 | */ |
||
83 | public function addChildren(ResourceInterface $resource): ResourceInterface |
||
84 | { |
||
85 | $this->children[(string)$resource] = $resource; |
||
86 | |||
87 | return $this; |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @inheritdoc |
||
92 | */ |
||
93 | public function removeChildren(ResourceInterface $resource): ResourceInterface |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * @inheritdoc |
||
102 | */ |
||
103 | public function children(): array |
||
104 | { |
||
108 |