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

RedisStore   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 62
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A postOptions() 0 4 1
A redis() 0 7 1
A read() 0 6 2
A write() 0 4 1
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