GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

RedisStorage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A remove() 0 5 1
A get() 0 9 2
A storageKey() 0 3 1
A __construct() 0 4 1
A add() 0 5 1
A has() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Key\Storage;
6
7
use Damax\Bundle\ApiAuthBundle\Key\Key;
8
use Predis\ClientInterface;
9
10
final class RedisStorage implements Storage
11
{
12
    private $client;
13
    private $prefix;
14
15
    public function __construct(ClientInterface $client, string $prefix = '')
16
    {
17
        $this->client = $client;
18
        $this->prefix = $prefix;
19
    }
20
21
    public function has(string $key): bool
22
    {
23
        $storageKey = $this->storageKey($key);
24
25
        return (bool) $this->client->exists($storageKey);
26
    }
27
28
    public function get(string $key): Key
29
    {
30
        $storageKey = $this->storageKey($key);
31
32
        if (null === $identity = $this->client->get($storageKey)) {
33
            throw new KeyNotFound();
34
        }
35
36
        return new Key($key, $identity, $this->client->ttl($storageKey));
37
    }
38
39
    public function add(Key $key): void
40
    {
41
        $storageKey = $this->storageKey((string) $key);
42
43
        $this->client->setex($storageKey, $key->ttl(), $key->identity());
44
    }
45
46
    public function remove(string $key): void
47
    {
48
        $storageKey = $this->storageKey($key);
49
50
        $this->client->del([$storageKey]);
51
    }
52
53
    private function storageKey(string $key): string
54
    {
55
        return $this->prefix . $key;
56
    }
57
}
58