Completed
Push — master ( 104680...55a46d )
by Mike
03:18
created

PHPRedisAdapter   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 97
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 97
loc 97
ccs 44
cts 44
cp 1
rs 10
c 0
b 0
f 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A ping() 6 6 1
A bRPopLPush() 6 6 1
A hGet() 6 6 1
A sAdd() 6 6 1
A sRem() 6 6 1
A sIsMember() 6 6 1
A sMembers() 6 6 1
A lLen() 6 6 1
A lRange() 6 6 1
A zScore() 7 7 2
A evalLua() 6 6 1
A tryCatch() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace MGDigital\BusQue\Redis\PHPRedis;
4
5
use MGDigital\BusQue\Exception\RedisException;
6
use MGDigital\BusQue\Redis\RedisAdapterInterface;
7
8 View Code Duplication
class PHPRedisAdapter implements RedisAdapterInterface
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
11
    private $redis;
12
13 12
    public function __construct(\Redis $redis)
14
    {
15 12
        $this->redis = $redis;
16 12
    }
17
18 1
    public function ping()
19
    {
20
        $this->tryCatch(function () {
21 1
            $this->redis->ping();
22 1
        });
23 1
    }
24
25 1
    public function bRPopLPush(string $source, string $destination, int $timeout)
26
    {
27
        return $this->tryCatch(function () use ($source, $destination, $timeout) {
28 1
            return $this->redis->brpoplpush($source, $destination, $timeout);
29 1
        });
30
    }
31
32 1
    public function hGet(string $key, string $field)
33
    {
34
        return $this->tryCatch(function () use ($key, $field) {
35 1
            return $this->redis->hGet($key, $field);
36 1
        });
37
    }
38
39 1
    public function sAdd(string $key, array $members)
40
    {
41
        $this->tryCatch(function () use ($key, $members) {
42 1
            $this->redis->sAdd($key, ...$members);
43 1
        });
44 1
    }
45
46 1
    public function sRem(string $key, array $members)
47
    {
48
        $this->tryCatch(function () use ($key, $members) {
49 1
            $this->redis->sRem($key, ...$members);
50 1
        });
51 1
    }
52
53 1
    public function sIsMember(string $key, string $value): bool
54
    {
55
        return $this->tryCatch(function () use ($key, $value) {
56 1
            return $this->redis->sIsMember($key, $value);
57 1
        });
58
    }
59
60 1
    public function sMembers(string $key): array
61
    {
62
        return $this->tryCatch(function () use ($key) {
63 1
            return $this->redis->sMembers($key);
64 1
        });
65
    }
66
67 1
    public function lLen(string $key): int
68
    {
69
        return $this->tryCatch(function () use ($key) {
70 1
            return $this->redis->lLen($key);
71 1
        });
72
    }
73
74 1
    public function lRange(string $key, int $offset = 0, int $limit = 10): array
75
    {
76
        return $this->tryCatch(function () use ($key, $offset, $limit) {
77 1
            return $this->redis->lRange($key, $offset, $limit);
78 1
        });
79
    }
80
81 1
    public function zScore(string $key, string $value)
82
    {
83
        $score = $this->tryCatch(function () use ($key, $value) {
84 1
            return $this->redis->zScore($key, $value);
85 1
        });
86 1
        return $score === null ? $score : intval($score);
87
    }
88
89
    public function evalLua(string $lua, array $args)
90
    {
91 1
        return $this->tryCatch(function () use ($lua, $args) {
92 1
            return $this->redis->evaluate($lua, $args, 0);
93 1
        });
94
    }
95
96 11
    private function tryCatch(callable $callable)
97
    {
98
        try {
99 11
            return $callable();
100 11
        } 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...
101 11
            throw new RedisException($e->getMessage(), 0, $e);
102
        }
103
    }
104
}
105