Passed
Pull Request — master (#1)
by Gombos
01:47
created

FieldSettingsManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 30
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 6 1
A apply() 0 6 1
A delete() 0 12 2
1
<?php
2
3
namespace Glorand\Model\Settings\Managers;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
7
class FieldSettingsManager extends AbstractSettingsManager
8
{
9
    public function apply(array $settings = []): SettingsManagerContract
10
    {
11
        $this->model->settings = $settings;
12
        $this->model->save();
13
14
        return $this;
15
    }
16
17
    public function delete(string $path = null): SettingsManagerContract
18
    {
19
        if (!$path) {
20
            $settings = [];
21
        } else {
22
            $settings = $this->all();
23
            array_forget($settings, $path);
24
        }
25
26
        $this->apply($settings);
27
28
        return $this;
29
    }
30
31
    public function set(string $path, $value): SettingsManagerContract
32
    {
33
        $settings = $this->all();
34
        array_set($settings, $path, $value);
35
36
        return $this->apply($settings);
37
    }
38
}
39