1 | <?php |
||||
2 | |||||
3 | namespace Glorand\Model\Settings\Managers; |
||||
4 | |||||
5 | use Glorand\Model\Settings\Contracts\SettingsManagerContract; |
||||
6 | use Glorand\Model\Settings\Models\ModelSettings; |
||||
7 | |||||
8 | /** |
||||
9 | * Class TableSettingsManager |
||||
10 | * @package Glorand\Model\Settings\Managers |
||||
11 | * @property \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsTable $model |
||||
12 | */ |
||||
13 | class TableSettingsManager extends AbstractSettingsManager |
||||
14 | { |
||||
15 | /** |
||||
16 | * @param array $settings |
||||
17 | * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract |
||||
18 | * @throws \Exception |
||||
19 | * @SuppressWarnings(PHPMD.ElseExpression) |
||||
20 | 39 | */ |
|||
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()); |
|||
0 ignored issues
–
show
Bug
introduced
by
![]() It seems like
$this->model->getConnectionName() can also be of type Glorand\Model\Settings\C...SettingsManagerContract ; however, parameter $name of Illuminate\Database\Eloq...\Model::setConnection() does only seem to accept null|string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
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()); |
||||
0 ignored issues
–
show
It seems like
$this->model->getSettingsCacheKey() can also be of type Illuminate\Database\Eloquent\Builder ; however, parameter $key of Illuminate\Cache\Repository::forget() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
41 | |||||
42 | return $this; |
||||
43 | } |
||||
44 | } |
||||
45 |