Passed
Push — master ( b54e8f...ab9cd5 )
by Gombos
03:13
created

TableSettingsManager::delete()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 3
rs 10
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
use Illuminate\Support\Arr;
8
9
/**
10
 * Class TableSettingsManager
11
 * @package Glorand\Model\Settings\Managers
12
 * @property  \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsTable $model
13
 */
14
class TableSettingsManager extends AbstractSettingsManager
15
{
16
    /**
17
     * @param array $settings
18
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
19
     * @throws \Exception
20
     */
21 33
    public function apply(array $settings = []): SettingsManagerContract
22
    {
23 33
        if (!$modelSettings = $this->model->modelSettings()->first()) {
24 33
            $modelSettings = new ModelSettings();
25 33
            $modelSettings->model()->associate($this->model);
26
        }
27 33
        $modelSettings->settings = $settings;
28 33
        $modelSettings->save();
29
30 33
        cache()->forget($this->model->getSettingsCacheKey());
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

30
        cache()->forget(/** @scrutinizer ignore-type */ $this->model->getSettingsCacheKey());
Loading history...
31
32 33
        return $this;
33
    }
34
}
35