RedisRepository   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 90.48%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 62
ccs 19
cts 21
cp 0.9048
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 6 2
A push() 0 3 1
A increment() 0 3 1
A __construct() 0 2 1
A decrement() 0 3 1
A flush() 0 3 1
A set() 0 3 1
1
<?php
2
3
namespace Krenor\Prometheus\Storage\Repositories;
4
5
use Tightenco\Collect\Support\Collection;
6
use Krenor\Prometheus\Contracts\Repository;
7
use Krenor\Prometheus\Storage\Redis\Connection as Redis;
8
9
class RedisRepository implements Repository
10
{
11
    /**
12
     * RedisRepository constructor.
13
     *
14
     * @param Redis $redis
15
     */
16
    public function __construct(protected Redis $redis)
17
    {
18
        //
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 12
    public function get(string $key): Collection
25
    {
26 12
        return new Collection(
27 12
            !str_contains($key, ':VALUES')
28 12
                ? $this->redis->hgetall($key)
29 12
                : $this->redis->lrange($key, 0, -1)
30
        );
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 8
    public function increment(string $key, string $field, float $value): void
37
    {
38 8
        $this->redis->hincrbyfloat($key, $field, $value);
39 8
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 2
    public function decrement(string $key, string $field, float $value): void
45
    {
46 2
        $this->increment($key, $field, -abs($value));
47 2
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 4
    public function set(string $key, string $field, mixed $value): void
53
    {
54 4
        $this->redis->hset($key, $field, $value);
55 4
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60 2
    public function push(string $key, float $value): void
61
    {
62 2
        $this->redis->rpush($key, [$value]);
63 2
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68 12
    public function flush(): bool
69
    {
70 12
        return $this->redis->flushdb();
71
    }
72
}
73