Passed
Push — master ( d4f709...8319cd )
by Mike
07:40 queued 01:16
created

PHPRedisAdapter::sMembers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
namespace MGDigital\BusQue\Redis\PHPRedis;
4
5
use MGDigital\BusQue\Exception\RedisException;
6
use MGDigital\BusQue\Redis\RedisAdapterInterface;
7
8
class PHPRedisAdapter implements RedisAdapterInterface
9
{
10
11
    private $redis;
12
13
    public function __construct(\Redis $redis)
14
    {
15
        $this->redis = $redis;
16
    }
17
18
    public function ping()
19
    {
20
        try {
21
            $this->redis->ping();
22
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
23
            throw new RedisException();
24
        }
25
    }
26
27
    public function bRPopLPush(string $source, string $destination, int $timeout = null)
28
    {
29
        try {
30
            return $this->redis->brpoplpush($source, $destination, $timeout);
31
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
32
            throw new RedisException();
33
        }
34
    }
35
36
    public function hGet(string $key, string $field)
37
    {
38
        try {
39
            return $this->redis->hGet($key, $field);
40
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
41
            throw new RedisException();
42
        }
43
    }
44
45
    public function sAdd(string $key, array $members)
46
    {
47
        try {
48
            $this->redis->sAdd($key, ...$members);
49
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
50
            throw new RedisException();
51
        }
52
    }
53
54
    public function sIsMember(string $key, string $value): bool
55
    {
56
        try {
57
            return $this->redis->sIsMember($key, $value);
58
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
59
            throw new RedisException();
60
        }
61
    }
62
63
    public function sMembers(string $key): array
64
    {
65
        try {
66
            return $this->redis->sMembers($key);
67
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
68
            throw new RedisException();
69
        }
70
    }
71
72
    public function lLen(string $key): int
73
    {
74
        try {
75
            return $this->redis->lLen($key);
76
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
77
            throw new RedisException();
78
        }
79
    }
80
81
    public function lRange(string $key, int $offset = 0, int $limit = 10): array
82
    {
83
        try {
84
            return $this->redis->lRange($key, $offset, $limit);
85
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
86
            throw new RedisException();
87
        }
88
    }
89
90 View Code Duplication
    public function zScore(string $key, string $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
        try {
93
            $score = $this->redis->zScore($key, $value);
94
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
95
            throw new RedisException();
96
        }
97
        return $score === null ? $score : intval($score);
98
    }
99
100
    public function del(string $key)
101
    {
102
        try {
103
            $this->redis->del($key);
104
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
105
            throw new RedisException();
106
        }
107
    }
108
109
    public function evalScript(string $path, array $args)
110
    {
111
        $lua = file_get_contents($path);
112
        try {
113
            return $this->redis->eval($lua, $args);
114
        } catch (\RedisException $e) {
0 ignored issues
show
Bug introduced by
The class RedisException does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
115
            throw new RedisException();
116
        }
117
    }
118
}
119