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 ( 70c46b...316b2b )
by Hilari
02:09
created

RedisCache::set()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 8
nc 4
nop 3
1
<?php
2
3
namespace Cmp\Cache\Infrastructure;
4
5
use Cmp\Cache\Domain\Cache;
6
use Cmp\Cache\Domain\ExceptionsException;
7
use Cmp\Cache\Domain\Exceptions\NotFoundException;
8
use Exception;
9
use Redis;
10
11
/**
12
 * Class RedisCache
13
 * 
14
 * A redis powered backend for caching
15
 *
16
 * @package Cmp\Cache\Infrastureture
17
 */
18
class RedisCache implements Cache
19
{
20
    /**
21
     * @var Redis
22
     */
23
    private $client;
24
25
    /**
26
     * RedisCache constructor.
27
     *
28
     * @param Redis $client
29
     */
30
    public function __construct(Redis $client)
31
    {
32
        $this->client = $client;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function delete($key)
39
    {
40
        try {
41
            $this->client->delete($key);
42
        } catch (Exception $exception) {
43
            throw new BackendException("Redis raised an exception deleting item $key", $exception);
44
        }
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function set($key, $value, $timeToLive = 0)
51
    {
52
        try {
53
            if ($timeToLive > 0) {
54
                $this->client->setex($key, $timeToLive, $value);
55
            } else {
56
                $this->client->set($key, $value);
57
            }
58
        } catch (Exception $exception) {
59
            throw new BackendException("Redis raised an exception setting item $key", $exception);
60
        }
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66
    public function has($key)
67
    {
68
        try {
69
            return $this->client->exists($key);
70
        } catch (Exception $exception) {
71
            throw new BackendException("Redis raised an exception checking for item $key", $exception);
72
        }
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function get($key)
79
    {
80
        try {
81
            $value = $this->client->get($key);
82
83
            if (!$value && !$this->client->exists($key)) {
84
                throw new NotFoundException($key);
85
            }
86
87
            return $value;
88
        } catch (NotFoundException $exception) {
89
            throw $exception;
90
        } catch (Exception $exception) {
91
            throw new BackendException("Redis raised an exception getting item $key", $exception);
92
        }
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98
    public function pull($key, $default = null)
99
    {
100
        try {
101
            return $this->get($key);
102
        } catch (NotFoundException $exception) {
103
            return $default;
104
        }
105
    }
106
}
107