Completed
Pull Request — master (#1)
by ARCANEDEV
02:04
created

RedisStore::redis()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
ccs 3
cts 3
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php namespace Arcanedev\LaravelSettings\Stores;
2
3
/**
4
 * Class     RedisStore
5
 *
6
 * @package  Arcanedev\LaravelSettings\Stores
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class RedisStore extends AbstractStore
10
{
11
    /* -----------------------------------------------------------------
12
     |  Post-Constructor
13
     | -----------------------------------------------------------------
14
     */
15
16
    /**
17
     * Fire the post options to customize the store.
18
     *
19
     * @param  array $options
20
     */
21 24
    protected function postOptions(array $options)
22
    {
23
        // TODO: Implement postOptions() method.
24 24
    }
25
26
    /* -----------------------------------------------------------------
27
     |  Getters & Setters
28
     | -----------------------------------------------------------------
29
     */
30
31
    /**
32
     * Get the redis connection.
33
     *
34
     * @return \Illuminate\Redis\Connections\Connection
35
     */
36 24
    protected function redis()
37
    {
38
        /** @var  \Illuminate\Redis\RedisManager  $manager */
39 24
        $manager = $this->app->make('redis');
40
41 24
        return $manager->connection();
42
    }
43
44
    /* -----------------------------------------------------------------
45
     |  Main Methods
46
     | -----------------------------------------------------------------
47
     */
48
49
    /**
50
     * Read the data from the store.
51
     *
52
     * @return array
53
     */
54 24
    protected function read()
55
    {
56 24
        $data = $this->redis()->command('get', ['settings']);
57
58 24
        return is_string($data) ? json_decode($data, true) : [];
59
    }
60
61
    /**
62
     * Write the data into the store.
63
     *
64
     * @param  array  $data
65
     */
66 24
    protected function write(array $data)
67
    {
68 24
        $this->redis()->command('set', ['settings', json_encode($data)]);
69 24
    }
70
}
71