Passed
Push — master ( 0a106d...6f5789 )
by Gombos
08:09 queued 03:26
created

RedisSettingsManager::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Glorand\Model\Settings\Managers;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Redis;
8
9
/**
10
 * Class FieldSettingsManager
11
 * @package Glorand\Model\Settings\Managers
12
 * @property \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsRedis $model
13
 */
14
class RedisSettingsManager extends AbstractSettingsManager
15
{
16 33
    public function apply(array $settings = []): SettingsManagerContract
17
    {
18 33
        Redis::set($this->model->cacheKey(), json_encode($settings));
19
20 33
        return $this;
21
    }
22
23 6
    public function set(string $path, $value): SettingsManagerContract
24
    {
25 6
        $settings = $this->all();
26 6
        Arr::set($settings, $path, $value);
27
28 6
        return $this->apply($settings);
29
    }
30
31
    /**
32
     * Delete an item by its unique path.
33
     *
34
     * @param string|null $path
35
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
36
     */
37 18
    public function delete(string $path = null): SettingsManagerContract
38
    {
39
        {
40 18
            if (!$path) {
41 18
                $settings = [];
42
            } else {
43 3
                $settings = $this->all();
44 3
                Arr::forget($settings, $path);
45
            }
46
47 18
            $this->apply($settings);
48
49 18
            return $this;
50
        }
51
    }
52
}
53