Total Complexity | 10 |
Total Lines | 70 |
Duplicated Lines | 0 % |
Coverage | 0% |
Changes | 0 |
1 | <?php |
||
8 | abstract class Model extends \MocOrm\Model\Model implements \ArrayAccess |
||
9 | { |
||
10 | /** |
||
11 | * Gets model data. |
||
12 | * |
||
13 | * @return array |
||
14 | */ |
||
15 | public function toArray() |
||
16 | { |
||
17 | return $this->getData(); |
||
18 | } |
||
19 | |||
20 | /** |
||
21 | * Gets model data through static method. |
||
22 | * |
||
23 | * @param mixed $data |
||
24 | * @return array |
||
25 | */ |
||
26 | public static function toList($data) |
||
27 | { |
||
28 | if (!($data instanceof self)) throw new \Exception(" It's not a model."); |
||
29 | |||
30 | $data = array_map(function ($object) { return $object->toArray(); }, $data); |
||
|
|||
31 | |||
32 | return $data; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Get first model from query result. |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | public function first() |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * ArrayAccess Interface. |
||
47 | */ |
||
48 | public function offsetExists($offset) |
||
49 | { |
||
50 | $data = $this->getData(); |
||
51 | |||
52 | return isset($data[$offset]); |
||
53 | } |
||
54 | |||
55 | public function offsetGet($offset) |
||
56 | { |
||
57 | $data = $this->getData(); |
||
58 | |||
59 | return isset($data[$offset]) ? $data[$offset] : null; |
||
60 | } |
||
61 | |||
62 | public function offsetSet($offset, $value) |
||
70 | } |
||
71 | } |
||
72 | |||
73 | public function offsetUnset($offset) |
||
78 | } |
||
79 | } |
||
80 |