| Total Complexity | 16 |
| Total Lines | 108 |
| Duplicated Lines | 0 % |
| Coverage | 77.78% |
| 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 | 4 | public function __construct(array $data = []) { |
|
| 20 | 4 | $this->data = $data; |
|
| 21 | 4 | } |
|
| 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 | 2 | public function get($key) { |
|
| 35 | 2 | if (!isset($this->data[$key])) { |
|
| 36 | return null; |
||
| 37 | } |
||
| 38 | |||
| 39 | 2 | if (\is_scalar($this->data[$key])) { |
|
| 40 | 1 | return $this->data[$key]; |
|
| 41 | } |
||
| 42 | |||
| 43 | 1 | if (\is_array($this->data[$key])) { |
|
| 44 | 1 | return new FlexibleData($this->data[$key]); |
|
| 45 | } |
||
| 46 | |||
| 47 | 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 | 2 | public function &offsetGet($offset) { |
|
| 61 | 2 | return $this->data[$offset]; |
|
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @inheritdoc |
||
| 66 | */ |
||
| 67 | 2 | public function offsetSet($offset, $value) { |
|
| 68 | 2 | if (null === $offset) { |
|
| 69 | $this->data[] = $value; |
||
| 70 | } else { |
||
| 71 | 2 | $this->data[$offset] = $value; |
|
| 72 | } |
||
| 73 | 2 | } |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @inheritdoc |
||
| 77 | */ |
||
| 78 | public function offsetUnset($offset) { |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @inheritdoc |
||
| 84 | */ |
||
| 85 | 1 | public function current() { |
|
| 86 | 1 | return new FlexibleData($this->data[$this->position]); |
|
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @inheritdoc |
||
| 91 | */ |
||
| 92 | 1 | public function next() { |
|
| 93 | 1 | ++$this->position; |
|
| 94 | 1 | } |
|
| 95 | |||
| 96 | /** |
||
| 97 | * @inheritdoc |
||
| 98 | */ |
||
| 99 | public function key() { |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @inheritdoc |
||
| 105 | */ |
||
| 106 | 1 | public function valid() { |
|
| 108 | } |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @inheritdoc |
||
| 112 | */ |
||
| 113 | 1 | public function rewind() { |
|
| 115 | 1 | } |
|
| 116 | } |
||
| 117 |