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.
Completed
Push — master ( 45e0c6...234875 )
by Hilari
02:43
created

RedisCache   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 71
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A delete() 0 4 1
A set() 0 8 2
A has() 0 4 1
A get() 0 10 3
A pull() 0 8 2
1
<?php
2
3
namespace Cmp\Cache\Infrastructure\Backend;
4
5
use Cmp\Cache\Domain\Cache;
6
use Cmp\Cache\Domain\Exceptions\NotFoundException;
7
use Redis;
8
9
/**
10
 * Class RedisCache
11
 * 
12
 * A redis powered backend for caching
13
 *
14
 * @package Cmp\Cache\Infrastureture\Backend
15
 */
16
class RedisCache implements Cache
17
{
18
    /**
19
     * @var Redis
20
     */
21
    private $client;
22
23
    /**
24
     * RedisCache constructor.
25
     *
26
     * @param Redis $client
27
     */
28
    public function __construct(Redis $client)
29
    {
30
        $this->client = $client;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function delete($key)
37
    {
38
        $this->client->delete($key);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function set($key, $value, $timeToLive = 0)
45
    {
46
        if ($timeToLive > 0) {
47
            $this->client->setex($key, $timeToLive, $value);
48
        } else {
49
            $this->client->set($key, $value);
50
        }
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function has($key)
57
    {
58
        return $this->client->exists($key);
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function get($key)
65
    {
66
        $value = $this->client->get($key);
67
68
        if (!$value && !$this->client->exists($key)) {
69
            throw new NotFoundException($key);
70
        }
71
72
        return $value;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function pull($key, $default = null)
79
    {
80
        try {
81
            return $this->get($key);
82
        } catch (NotFoundException $exception) {
83
            return $default;
84
        }
85
    }
86
}
87