Test Failed
Push — master ( d9eb19...0a106d )
by Gombos
03:48
created

FieldSettingsManager::deleteMultiple()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A FieldSettingsManager::set() 0 6 1
1
<?php
2
3
namespace Glorand\Model\Settings\Managers;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
use Illuminate\Support\Arr;
7
8
/**
9
 * Class FieldSettingsManager
10
 * @package Glorand\Model\Settings\Managers
11
 * @property \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsField $model
12
 */
13
class FieldSettingsManager extends AbstractSettingsManager
14
{
15
    /**
16
     * @param array $settings
17
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
18 12
     */
19
    public function apply(array $settings = []): SettingsManagerContract
20 12
    {
21 12
        $this->model->{$this->model->getSettingsFieldName()} = json_encode($settings);
22 12
        if ($this->model->isPersistSettings()) {
23
            $this->model->save();
1 ignored issue
show
Bug introduced by
It seems like save() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
            $this->model->/** @scrutinizer ignore-call */ 
24
                          save();
Loading history...
24
        }
25 12
26
        return $this;
27
    }
28
29
    /**
30
     * @param string|null $path
31
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
32 3
     */
33
    public function delete(string $path = null): SettingsManagerContract
34 3
    {
35 3
        if (!$path) {
36
            $settings = [];
37 1
        } else {
38 1
            $settings = $this->all();
39
            Arr::forget($settings, $path);
40
        }
41 3
42
        $this->apply($settings);
43 3
44
        return $this;
45
    }
46
47
    /**
48
     * @param string $path
49
     * @param mixed $value
50 1
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
51
     */
52 1
    public function set(string $path, $value): SettingsManagerContract
53 1
    {
54 1
        $settings = $this->all();
55
        Arr::set($settings, $path, $value);
56
57 1
        return $this->apply($settings);
58
    }
59
}
60