BlablacarRedisStorage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 44
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 3 1
A has() 0 3 1
A __construct() 0 4 1
A get() 0 9 2
1
<?php
2
3
namespace Xsolve\SalesforceClient\Storage;
4
5
use Blablacar\Redis\Client;
6
use Xsolve\SalesforceClient\Security\Token\TokenInterface;
7
8
class BlablacarRedisStorage implements TokenStorageInterface
9
{
10
    const DEFAULT_KEY = 'salesforce_token';
11
12
    /**
13
     * @var Client
14
     */
15
    protected $client;
16
17
    /**
18
     * @var string
19
     */
20
    protected $key;
21
22 5
    public function __construct(Client $client, string $key = self::DEFAULT_KEY)
23
    {
24 5
        $this->client = $client;
25 5
        $this->key = $key;
26 5
    }
27
28
    /**
29
     * @return TokenInterface
30
     *
31
     * @throws \LogicException if the token is not set
32
     */
33 2
    public function get(): TokenInterface
34
    {
35 2
        $token = $this->client->get($this->key);
36
37 2
        if (null === $token) {
38 1
            throw new \LogicException('No token has been set');
39
        }
40
41 1
        return unserialize($token);
42
    }
43
44 2
    public function has(): bool
45
    {
46 2
        return (bool) $this->client->exists($this->key);
47
    }
48
49 1
    public function save(TokenInterface $token)
50
    {
51 1
        $this->client->set($this->key, serialize($token));
52 1
    }
53
}
54