Passed
Push — master ( da797a...38c1ce )
by Gombos
03:26
created

FieldSettingsManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 43
ccs 15
cts 15
cp 1
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
/**
8
 * Class FieldSettingsManager
9
 * @package Glorand\Model\Settings\Managers
10
 * @property \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsField $model
11
 */
12
class FieldSettingsManager extends AbstractSettingsManager
13
{
14
    /**
15
     * @param array $settings
16
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
17
     */
18 6
    public function apply(array $settings = []): SettingsManagerContract
19
    {
20 6
        $this->model->{$this->model->getSettingsFieldName()} = json_encode($settings);
21 6
        $this->model->save();
0 ignored issues
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

21
        $this->model->/** @scrutinizer ignore-call */ 
22
                      save();
Loading history...
22
23 6
        return $this;
24
    }
25
26
    /**
27
     * @param string|null $path
28
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
29
     */
30 1
    public function delete(string $path = null): SettingsManagerContract
31
    {
32 1
        if (!$path) {
33 1
            $settings = [];
34
        } else {
35 1
            $settings = $this->all();
36 1
            array_forget($settings, $path);
0 ignored issues
show
Deprecated Code introduced by
The function array_forget() has been deprecated: Arr::forget() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

36
            /** @scrutinizer ignore-deprecated */ array_forget($settings, $path);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
37
        }
38
39 1
        $this->apply($settings);
40
41 1
        return $this;
42
    }
43
44
    /**
45
     * @param string $path
46
     * @param mixed $value
47
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
48
     */
49 2
    public function set(string $path, $value): SettingsManagerContract
50
    {
51 2
        $settings = $this->all();
52 2
        array_set($settings, $path, $value);
0 ignored issues
show
Deprecated Code introduced by
The function array_set() has been deprecated: Arr::set() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

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

52
        /** @scrutinizer ignore-deprecated */ array_set($settings, $path, $value);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
53
54 2
        return $this->apply($settings);
55
    }
56
}
57