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

src/Managers/FieldSettingsManager.php (3 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 11
    public function apply(array $settings = []): SettingsManagerContract
19
    {
20 11
        $this->model->{$this->model->getSettingsFieldName()} = json_encode($settings);
21 11
        if ($this->model->isPersistSettings()) {
22 11
            $this->model->save();
23
        }
24
25 11
        return $this;
26
    }
27
28
    /**
29
     * @param string|null $path
30
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
31
     */
32 3
    public function delete(string $path = null): SettingsManagerContract
33
    {
34 3
        if (!$path) {
35 3
            $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 6.0. ( 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 3
        $this->apply($settings);
42
43 3
        return $this;
44
    }
45
46
    /**
47
     * @param iterable $paths
48
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
49
     */
50 1
    public function deleteMultiple(iterable $paths): SettingsManagerContract
51
    {
52 1
        $settings = $this->all();
53 1
        foreach ($paths as $path) {
54 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 6.0. ( 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_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...
55
        }
56
57 1
        $this->apply($settings);
58
59 1
        return $this;
60
    }
61
62
    /**
63
     * @param string $path
64
     * @param mixed $value
65
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
66
     */
67 2
    public function set(string $path, $value): SettingsManagerContract
68
    {
69 2
        $settings = $this->all();
70 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 6.0. ( Ignorable by Annotation )

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

70
        /** @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...
71
72 2
        return $this->apply($settings);
73
    }
74
}
75