| Total Complexity | 5 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | trait Storable |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @return bool |
||
| 11 | */ |
||
| 12 | abstract public function exists(); |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param array $attributes |
||
| 16 | */ |
||
| 17 | abstract public function fill(array $attributes); |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param int $options |
||
| 21 | * @param bool $withDeferred |
||
| 22 | * |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | abstract public function json($options = 0, $withDeferred = false); |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @return Connection |
||
| 29 | */ |
||
| 30 | abstract public function connection(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | abstract public function url(); |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return mixed |
||
| 39 | */ |
||
| 40 | abstract public function primaryKeyContent(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @return $this |
||
| 44 | */ |
||
| 45 | public function save() |
||
| 46 | { |
||
| 47 | if ($this->exists()) { |
||
| 48 | $this->fill($this->update()); |
||
| 49 | } else { |
||
| 50 | $this->fill($this->insert()); |
||
| 51 | } |
||
| 52 | |||
| 53 | return $this; |
||
| 54 | } |
||
| 55 | |||
| 56 | public function insert() |
||
| 59 | } |
||
| 60 | |||
| 61 | public function update() |
||
| 62 | { |
||
| 63 | $primaryKey = $this->primaryKeyContent(); |
||
| 64 | |||
| 65 | return $this->connection()->put($this->url() . "(guid'$primaryKey')", $this->json()); |
||
| 66 | } |
||
| 67 | |||
| 68 | public function delete() |
||
| 73 | } |
||
| 74 | } |
||
| 75 |