Completed
Pull Request — master (#20)
by ARCANEDEV
14:51 queued 09:11
created

RedisStore::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 1.037
rs 10
c 0
b 0
f 0
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 3
    protected function postOptions(array $options)
37
    {
38 3
        $this->manager = new RedisManager(Arr::pull($options, 'client', 'predis'), $options, []);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
39 3
    }
40
41
    /* -----------------------------------------------------------------
42
     |  Main Methods
43
     | -----------------------------------------------------------------
44
     */
45
46
    /**
47
     * Read the data from the store.
48
     *
49
     * @return array
50
     */
51 3
    protected function read()
52
    {
53 3
        $data = $this->command('get', ['settings']);
54
55
        return is_string($data) ? json_decode($data, true) : [];
56
    }
57
58
    /**
59
     * Write the data into the store.
60
     *
61
     * @param  array  $data
62
     */
63 3
    protected function write(array $data)
64
    {
65 3
        $this->command('set', ['settings', json_encode($data)]);
66
    }
67
68
    /* -----------------------------------------------------------------
69
     |  Other Methods
70
     | -----------------------------------------------------------------
71
     */
72
73
    /**
74
     * Get a Redis connection by name.
75
     *
76
     * @param  string|null  $name
77
     *
78
     * @return \Illuminate\Redis\Connections\Connection
79
     */
80 3
    protected function connection($name = null)
81
    {
82 3
        return $this->manager->connection($name);
83
    }
84
85
    /**
86
     * Run a command against the Redis database.
87
     *
88
     * @param  string  $method
89
     * @param  array   $parameters
90
     *
91
     * @return mixed
92
     */
93 3
    protected function command($method, array $parameters = [])
94
    {
95 3
        return $this->connection()->command($method, $parameters);
96
    }
97
}
98