Total Complexity | 14 |
Total Lines | 127 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
16 | class Row implements RowInterface |
||
17 | { |
||
18 | /** @var array */ |
||
19 | private array $data; |
||
20 | |||
21 | /** |
||
22 | * Row constructor. |
||
23 | * |
||
24 | * @param array $data |
||
25 | */ |
||
26 | public function __construct(array $data = []) |
||
27 | { |
||
28 | $this->data = $data; |
||
29 | } |
||
30 | |||
31 | /** |
||
32 | * @inheritdoc |
||
33 | */ |
||
34 | public function rewind(): void |
||
35 | { |
||
36 | reset($this->data); |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @inheritdoc |
||
41 | */ |
||
42 | public function current(): string |
||
43 | { |
||
44 | return current($this->data); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @inheritdoc |
||
49 | */ |
||
50 | public function key(): int |
||
51 | { |
||
52 | return key($this->data); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @inheritdoc |
||
57 | */ |
||
58 | public function next(): bool |
||
59 | { |
||
60 | return next($this->data); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | public function valid(): bool |
||
67 | { |
||
68 | return key($this->data) !== null; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | public function toArray(): array |
||
75 | { |
||
76 | return $this->data; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | public function reverse(): RowInterface |
||
83 | { |
||
84 | return new Row(array_reverse($this->data)); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | public function byIndex(mixed $index): mixed |
||
91 | { |
||
92 | return $this->data[$index] ?? null; |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @inheritdoc |
||
97 | */ |
||
98 | public function hasIndex(mixed $index): bool |
||
99 | { |
||
100 | return isset($this->data[$index]); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @inheritdoc |
||
105 | */ |
||
106 | public function removeByIndex(mixed $index): RowInterface |
||
107 | { |
||
108 | $data = $this->data; |
||
109 | |||
110 | unset($data[$index]); |
||
111 | |||
112 | return new Row($data); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @inheritdoc |
||
117 | */ |
||
118 | public function removeFirst(): RowInterface |
||
119 | { |
||
120 | $data = array_slice($this->data, 1, null, true); |
||
121 | |||
122 | return new Row($data); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * @inheritdoc |
||
127 | */ |
||
128 | public function removeLast(): RowInterface |
||
129 | { |
||
130 | $data = $this->data; |
||
131 | |||
132 | array_pop($data); |
||
133 | |||
134 | return new Row($data); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @inheritdoc |
||
139 | */ |
||
140 | public function count(): int |
||
143 | } |
||
144 | } |
||
145 |