Total Complexity | 5 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
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) |
|
52 | 1 | } |
|
53 | } |
||
54 |