Total Complexity | 6 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
6 | abstract class AbstractArray extends \ArrayObject |
||
7 | { |
||
8 | protected $elements = []; |
||
9 | protected $valueType; |
||
10 | |||
11 | 16 | public function __construct(string $valueType) { |
|
12 | 16 | parent::__construct(); |
|
13 | |||
14 | 16 | $this->valueType = $valueType; |
|
15 | 16 | } |
|
16 | |||
17 | 15 | public function offsetSet($offset, $value) |
|
18 | { |
||
19 | 15 | $this->checkType($value); |
|
20 | |||
21 | 13 | $this->checkOffset($offset); |
|
22 | |||
23 | 11 | parent::offsetSet($offset, $value); |
|
24 | 11 | } |
|
25 | |||
26 | 1 | public function exchangeArray($array) |
|
27 | { |
||
28 | 1 | array_walk($array, function($value, $offset) { |
|
29 | 1 | $this->checkOffset($offset); |
|
30 | 1 | $this->checkType($value); |
|
31 | 1 | }); |
|
32 | |||
33 | 1 | parent::exchangeArray($array); |
|
34 | 1 | } |
|
35 | |||
36 | 16 | protected function checkType($value): void |
|
40 | } |
||
41 | 14 | } |
|
42 | |||
43 | abstract protected function checkOffset($offset): void; |
||
44 | } |