Completed
Branch cleanup (eec673)
by Paul
01:32
created

SimpleCacheTokenPersistence   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A saveToken() 0 4 1
A deleteToken() 0 4 1
A restoreToken() 0 10 2
1
<?php
2
3
namespace LibLynx\Connect;
4
5
use kamermans\OAuth2\Persistence\TokenPersistenceInterface;
6
use kamermans\OAuth2\Token\TokenInterface;
7
use Psr\SimpleCache\CacheInterface;
8
9
class SimpleCacheTokenPersistence implements TokenPersistenceInterface
10
{
11
    /**
12
     * @var CacheInterface
13
     */
14
    private $cache;
15
16
    /**
17
     * @var string
18
     */
19
    private $cacheKey;
20
21 12
    public function __construct(CacheInterface $cache, $cacheKey = 'guzzle-oauth2-token')
22
    {
23 12
        $this->cache = $cache;
24 12
        $this->cacheKey = $cacheKey;
25 12
    }
26
27 12
    public function saveToken(TokenInterface $token)
28
    {
29 12
        $this->cache->set($this->cacheKey, $token->serialize());
30 12
    }
31
32 12
    public function restoreToken(TokenInterface $token)
33
    {
34 12
        $data = $this->cache->get($this->cacheKey);
35
36 12
        if (!is_array($data)) {
37 10
            return null;
38
        }
39
40 2
        return $token->unserialize($data);
41
    }
42
43 12
    public function deleteToken()
44
    {
45 12
        $this->cache->delete($this->cacheKey);
46 12
    }
47
}
48