| Total Complexity | 4 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 7 | trait Saveable |
||
| 8 | { |
||
| 9 | protected $savePath; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Abstract functions to imppose requirements for the exhibiting class. |
||
| 13 | */ |
||
| 14 | abstract public function getResourceName($object = null); |
||
| 15 | |||
| 16 | abstract public function getAttributes($sanitized = true); |
||
| 17 | |||
| 18 | abstract public function processPath($path = null, array $values = null); |
||
| 19 | |||
| 20 | abstract public function postRequest($path, array $options = []); |
||
| 21 | |||
| 22 | abstract public function getClient(); |
||
| 23 | |||
| 24 | abstract public function setValues($values); |
||
| 25 | |||
| 26 | abstract public function getAttribute($key); |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Save an object. |
||
| 30 | * |
||
| 31 | * @throws \Lyal\Checkr\Exceptions\IdMissing |
||
| 32 | * |
||
| 33 | * @return $this |
||
| 34 | */ |
||
| 35 | public function save() |
||
| 36 | { |
||
| 37 | if ($this->getAttribute('id') === null) { |
||
| 38 | throw new IdMissing($this); |
||
| 39 | } |
||
| 40 | $path = $this->getSavePath() ?? $this->getResourceName().'/'.$this->getAttribute('id'); |
||
| 41 | $this->setValues($this->postRequest($path)); |
||
| 42 | |||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get the save path of the current object. |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | public function getSavePath() |
||
| 52 | { |
||
| 53 | return $this->savePath; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Set the save path of the current object. |
||
| 58 | * |
||
| 59 | * @param $path |
||
| 60 | * |
||
| 61 | * @return mixed |
||
| 62 | */ |
||
| 63 | public function setSavePath($path) |
||
| 66 | } |
||
| 67 | } |
||
| 68 |