Redis   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A write() 0 3 1
A __construct() 0 3 1
A has() 0 3 2
A read() 0 3 1
A remove() 0 3 2
1
<?php
2
/**
3
 * Redis storing
4
 * User: moyo
5
 * Date: 15/11/2017
6
 * Time: 5:06 PM
7
 */
8
9
namespace Carno\Cache\Stores;
10
11
use Carno\Cache\Contracts\Storing;
12
use Redis as API;
13
14
class Redis implements Storing
15
{
16
    /**
17
     * @var API
18
     */
19
    private $backend = null;
20
21
    /**
22
     * Redis constructor.
23
     * @param API $backend
24
     */
25
    public function __construct($backend)
26
    {
27
        $this->backend = $backend;
28
    }
29
30
    /**
31
     * @param string $key
32
     * @return bool
33
     */
34
    public function has(string $key)
35
    {
36
        return (yield $this->backend->exists($key)) ? true : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->backend->exists($key) returns the type Generator which is incompatible with the documented return type boolean.
Loading history...
37
    }
38
39
    /**
40
     * @param string $key
41
     * @return mixed
42
     */
43
    public function read(string $key)
44
    {
45
        return yield $this->backend->get($key);
46
    }
47
48
    /**
49
     * @param string $key
50
     * @param mixed $data
51
     * @param int $ttl
52
     * @return bool
53
     */
54
    public function write(string $key, $data, int $ttl = null)
55
    {
56
        return yield $this->backend->setex($key, $ttl, $data);
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->backend->setex($key, $ttl, $data) returns the type Generator which is incompatible with the documented return type boolean.
Loading history...
57
    }
58
59
    /**
60
     * @param string $key
61
     * @return bool
62
     */
63
    public function remove(string $key)
64
    {
65
        return (yield $this->backend->del($key)) ? true : false;
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->backend->del($key) returns the type Generator which is incompatible with the documented return type boolean.
Loading history...
66
    }
67
}
68