Completed
Push — master ( e9a852...6de009 )
by Mike
03:07
created

PHPRedisAdapter::sRem()   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 2
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)
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 sRem(string $key, array $members)
55
    {
56
        try {
57
            $this->redis->sRem($key, ...$members);
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 sIsMember(string $key, string $value): bool
64
    {
65
        try {
66
            return $this->redis->sIsMember($key, $value);
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 sMembers(string $key): array
73
    {
74
        try {
75
            return $this->redis->sMembers($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 lLen(string $key): int
82
    {
83
        try {
84
            return $this->redis->lLen($key);
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
    public function lRange(string $key, int $offset = 0, int $limit = 10): array
91
    {
92
        try {
93
            return $this->redis->lRange($key, $offset, $limit);
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
    }
98
99 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...
100
    {
101
        try {
102
            $score = $this->redis->zScore($key, $value);
103
        } 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...
104
            throw new RedisException();
105
        }
106
        return $score === null ? $score : intval($score);
107
    }
108
109
    public function del(string $key)
110
    {
111
        try {
112
            $this->redis->del($key);
113
        } 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...
114
            throw new RedisException();
115
        }
116
    }
117
118
    public function evalScript(string $path, array $args)
119
    {
120
        $lua = file_get_contents($path);
121
        try {
122
            return $this->redis->eval($lua, $args);
123
        } 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...
124
            throw new RedisException();
125
        }
126
    }
127
}
128