| Total Complexity | 12 |
| Total Lines | 100 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | abstract class Model extends \MocOrm\Model\Model implements \ArrayAccess |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Gets model data. |
||
| 13 | * |
||
| 14 | * @return array |
||
| 15 | */ |
||
| 16 | public function toArray() |
||
| 17 | { |
||
| 18 | return $this->getData(); |
||
|
|
|||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Return count of data |
||
| 23 | * @return int |
||
| 24 | */ |
||
| 25 | public function count() |
||
| 26 | { |
||
| 27 | return count($this->getData()); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get first model from query result. |
||
| 32 | * @return mixed |
||
| 33 | */ |
||
| 34 | public function end() { |
||
| 35 | return end($this->getData()); |
||
| 36 | } |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Gets model data through static method. |
||
| 40 | * |
||
| 41 | * @param mixed $data |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public static function toList($data) |
||
| 45 | { |
||
| 46 | if (!($data instanceof self)) throw new \Exception(" It's not a model."); |
||
| 47 | |||
| 48 | $data = array_map(function ($object) { |
||
| 49 | return $object->toArray(); |
||
| 50 | }, $data); |
||
| 51 | |||
| 52 | return $data; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Get first model from query result. |
||
| 57 | * |
||
| 58 | * @return mixed |
||
| 59 | */ |
||
| 60 | public function first() |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * ArrayAccess Interface. |
||
| 67 | */ |
||
| 68 | public function offsetExists($offset) |
||
| 69 | { |
||
| 70 | $data = $this->getData(); |
||
| 71 | |||
| 72 | return isset($data[$offset]); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param mixed $offset |
||
| 77 | * @return mixed|null |
||
| 78 | */ |
||
| 79 | public function offsetGet($offset) |
||
| 80 | { |
||
| 81 | $data = $this->getData(); |
||
| 82 | |||
| 83 | return isset($data[$offset]) ? $data[$offset] : null; |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @param mixed $offset |
||
| 88 | * @param mixed $value |
||
| 89 | */ |
||
| 90 | public function offsetSet($offset, $value) |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param mixed $offset |
||
| 103 | */ |
||
| 104 | public function offsetUnset($offset) |
||
| 109 | } |
||
| 110 | } |
||
| 111 |