| Total Complexity | 16 |
| Total Lines | 108 |
| Duplicated Lines | 0 % |
| Coverage | 97.22% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | class FlexibleData implements DataStructure, \ArrayAccess, \Iterator { |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | private $data; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var int |
||
| 16 | */ |
||
| 17 | private $position = 0; |
||
| 18 | |||
| 19 | 7 | public function __construct(array $data = []) { |
|
| 20 | 7 | $this->data = $data; |
|
| 21 | 7 | } |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @inheritdoc |
||
| 25 | */ |
||
| 26 | 1 | public function build() { |
|
| 27 | 1 | return $this->data; |
|
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @param string|int $key |
||
| 32 | * @return mixed |
||
| 33 | */ |
||
| 34 | 4 | public function get($key) { |
|
| 35 | 4 | if (!isset($this->data[$key])) { |
|
| 36 | 1 | return null; |
|
| 37 | } |
||
| 38 | |||
| 39 | 4 | if (\is_scalar($this->data[$key])) { |
|
| 40 | 2 | return $this->data[$key]; |
|
| 41 | } |
||
| 42 | |||
| 43 | 3 | if (\is_array($this->data[$key])) { |
|
| 44 | 3 | return new FlexibleData($this->data[$key]); |
|
| 45 | } |
||
| 46 | |||
| 47 | 1 | return $this->data[$key]; |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @inheritdoc |
||
| 52 | */ |
||
| 53 | 1 | public function offsetExists($offset) { |
|
| 54 | 1 | return isset($this->data[$offset]); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @inheritdoc |
||
| 59 | */ |
||
| 60 | 4 | public function &offsetGet($offset) { |
|
| 61 | 4 | return $this->data[$offset]; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @inheritdoc |
||
| 66 | */ |
||
| 67 | 2 | public function offsetSet($offset, $value) { |
|
| 72 | } |
||
| 73 | 2 | } |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @inheritdoc |
||
| 77 | */ |
||
| 78 | 1 | public function offsetUnset($offset) { |
|
| 79 | 1 | unset($this->data[$offset]); |
|
| 80 | 1 | } |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @inheritdoc |
||
| 84 | */ |
||
| 85 | 2 | public function current() { |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @inheritdoc |
||
| 91 | */ |
||
| 92 | 2 | public function next() { |
|
| 93 | 2 | ++$this->position; |
|
| 94 | 2 | } |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @inheritdoc |
||
| 98 | */ |
||
| 99 | 1 | public function key() { |
|
| 100 | 1 | return $this->position; |
|
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @inheritdoc |
||
| 105 | */ |
||
| 106 | 2 | public function valid() { |
|
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @inheritdoc |
||
| 112 | */ |
||
| 113 | 2 | public function rewind() { |
|
| 115 | 2 | } |
|
| 116 | } |
||
| 117 |