Completed
Push — master ( 233041...d4b129 )
by ARCANEDEV
14s
created

RedisStore   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A postOptions() 0 4 1
A read() 0 7 2
A write() 0 5 1
1
<?php namespace Arcanedev\LaravelSettings\Stores;
2
3
use Illuminate\Redis\RedisManager;
4
use Illuminate\Support\Arr;
5
6
/**
7
 * Class     RedisStore
8
 *
9
 * @package  Arcanedev\LaravelSettings\Stores
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class RedisStore extends AbstractStore
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * The redis manager.
21
     *
22
     * @var  \Illuminate\Redis\RedisManager
23
     */
24
    protected $manager;
25
26
    /* -----------------------------------------------------------------
27
     |  Post-Constructor
28
     | -----------------------------------------------------------------
29
     */
30
31
    /**
32
     * Fire the post options to customize the store.
33
     *
34
     * @param  array  $options
35
     */
36 24
    protected function postOptions(array $options)
37
    {
38 24
        $this->manager = new RedisManager(Arr::pull($options, 'client', 'predis'), $options);
39 24
    }
40
41
    /* -----------------------------------------------------------------
42
     |  Main Methods
43
     | -----------------------------------------------------------------
44
     */
45
46
    /**
47
     * Read the data from the store.
48
     *
49
     * @return array
50
     */
51 24
    protected function read()
52
    {
53 24
        $data = $this->manager->connection()
54 24
                              ->command('get', ['settings']);
55
56 24
        return is_string($data) ? json_decode($data, true) : [];
57
    }
58
59
    /**
60
     * Write the data into the store.
61
     *
62
     * @param  array  $data
63
     */
64 24
    protected function write(array $data)
65
    {
66 24
        $this->manager->connection()
67 24
                      ->command('set', ['settings', json_encode($data)]);
68 24
    }
69
}
70