Passed
Push — master ( 0c664b...4bf842 )
by Gombos
04:37
created

src/Managers/FieldSettingsManager.php (2 issues)

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 7
    public function apply(array $settings = []): SettingsManagerContract
19
    {
20 7
        $this->model->{$this->model->getSettingsFieldName()} = json_encode($settings);
21 7
        if ($this->model->isPersistSettings()) {
22 7
            $this->model->save();
23
        }
24
25 7
        return $this;
26
    }
27
28
    /**
29
     * @param string|null $path
30
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
31
     */
32 2
    public function delete(string $path = null): SettingsManagerContract
33
    {
34 2
        if (!$path) {
35 2
            $settings = [];
36
        } else {
37 1
            $settings = $this->all();
38 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

38
            /** @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...
39
        }
40
41 2
        $this->apply($settings);
42
43 2
        return $this;
44
    }
45
46
    /**
47
     * @param string $path
48
     * @param mixed $value
49
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
50
     */
51 2
    public function set(string $path, $value): SettingsManagerContract
52
    {
53 2
        $settings = $this->all();
54 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

54
        /** @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...
55
56 2
        return $this->apply($settings);
57
    }
58
}
59