| Conditions | 4 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 21 | public function apply(array $settings = []): SettingsManagerContract |
||
| 22 | 39 | { |
|
| 23 | 39 | $this->validate($settings); |
|
| 24 | 9 | ||
| 25 | 9 | $modelSettings = $this->model->modelSettings()->first(); |
|
| 26 | if (!count($settings)) { |
||
| 27 | if ($modelSettings) { |
||
| 28 | 39 | $modelSettings->delete(); |
|
| 29 | 39 | } |
|
| 30 | 39 | } else { |
|
| 31 | 39 | if (!$modelSettings) { |
|
| 32 | $modelSettings = new ModelSettings(); |
||
| 33 | 39 | $modelSettings->setConnection($this->model->getConnectionName()); |
|
| 34 | 39 | $modelSettings->model()->associate($this->model); |
|
| 35 | } |
||
| 36 | $modelSettings->settings = $settings; |
||
| 37 | 39 | $modelSettings->save(); |
|
| 38 | } |
||
| 39 | 39 | ||
| 40 | cache()->forget($this->model->getSettingsCacheKey()); |
||
| 41 | |||
| 42 | return $this; |
||
| 43 | } |
||
| 45 |