Total Complexity | 7 |
Total Lines | 88 |
Duplicated Lines | 0 % |
Coverage | 52.38% |
Changes | 0 |
1 | <?php |
||
21 | class Mirror |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $master; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected $slaves; |
||
32 | |||
33 | /** |
||
34 | * @var CircularArray |
||
35 | */ |
||
36 | protected $all; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $data; |
||
42 | |||
43 | /** |
||
44 | * @param string $master |
||
45 | * @param array $slaves |
||
46 | */ |
||
47 | 1 | public function __construct(string $master, array $slaves) |
|
48 | { |
||
49 | 1 | $this->master = $master; |
|
50 | 1 | $this->slaves = $slaves; |
|
51 | |||
52 | 1 | $this->data = $slaves; |
|
53 | 1 | if (!in_array($master, $this->data)) { |
|
54 | $this->data[] = $master; |
||
55 | } |
||
56 | |||
57 | 1 | $this->all = CircularArray::fromArray($this->data); |
|
58 | 1 | } |
|
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getMaster():string |
||
64 | { |
||
65 | return $this->master; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Get all mirrors. |
||
70 | * |
||
71 | * @return CircularArray |
||
72 | */ |
||
73 | 1 | public function getAll():CircularArray |
|
74 | { |
||
75 | 1 | return $this->all; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Get next item. |
||
80 | * |
||
81 | * @return string |
||
82 | */ |
||
83 | public function getNext():string |
||
84 | { |
||
85 | $this->all->next(); |
||
86 | |||
87 | return $this->all->current(); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param string $value |
||
92 | * |
||
93 | * @return CircularArray |
||
94 | */ |
||
95 | public function remove(string $value):CircularArray |
||
96 | { |
||
97 | $this->data = array_values(array_diff($this->data, [$value])); |
||
98 | $this->all = CircularArray::fromArray($this->data); |
||
99 | |||
100 | return $this->getAll(); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @return array |
||
105 | */ |
||
106 | 1 | public function toArray():array |
|
109 | } |
||
110 | } |
||
111 |