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 ( 7bf065...13ae28 )
by Axel
02:07
created

MemoryCacheItem   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 93.1%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 91
ccs 27
cts 29
cp 0.931
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 5 1
A isHit() 0 3 1
A getKey() 0 3 1
A get() 0 6 2
A expiresAfter() 0 7 2
A getExpirationDate() 0 3 1
A getDriver() 0 3 1
A expiresAt() 0 8 2
1
<?php
2
3
namespace PhpAbac\Cache\Item;
4
5
use Psr\Cache\CacheItemInterface;
6
7
use PhpAbac\Cache\Exception\ExpiredCacheException;
8
9
class MemoryCacheItem implements CacheItemInterface {
10
    /** @var string **/
11
    protected $key;
12
    /** @var mixed **/
13
    protected $value;
14
    /** @var int **/
15
    protected $defaultLifetime = 3600;
16
    /** @var \DateTime **/
17
    protected $expiresAt;
18
    /** @var string **/
19
    protected $driver = 'memory';
20
21
    /**
22
     * @param string $key
23
     * @param int $ttl
24
     */
25 20
    public function __construct($key, $ttl = null) {
26 20
        $this->key = $key;
27 20
        $this->expiresAfter($ttl);
28 20
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 8
    public function set($value) {
34 8
        $this->value = $value;
35
36 8
        return $this;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 11
    public function isHit() {
43 11
        return $this->expiresAt >= new \DateTime();
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 14
    public function getKey() {
50 14
        return $this->key;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 9
    public function get() {
57 9
        if(!$this->isHit()) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after IF keyword; 0 found
Loading history...
58
            throw new ExpiredCacheException('Cache item is expired');
59
        }
60 9
        return $this->value;
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 20
    public function expiresAfter($time) {
67 20
        $lifetime = ($time !== null) ? $time : $this->defaultLifetime;
68
69 20
        $this->expiresAt = (new \DateTime())->setTimestamp(time() + $lifetime);
70
71 20
        return $this;
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 2
    public function expiresAt($expiration) {
78 2
        $this->expiresAt =
79 2
            ($expiration === null)
80
            ? (new \DateTime())->setTimestamp(time() + $this->defaultLifetime)
81 2
            : $expiration
82
        ;
83 2
        return $this;
84
    }
85
86
    /**
87
     * @return \DateTime
88
     */
89 2
    public function getExpirationDate() {
90 2
        return $this->expiresAt;
91
    }
92
93
    /**
94
     * @return string
95
     */
96 2
    public function getDriver() {
97 2
        return $this->driver;
98
    }
99
}
100