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::expiresAt()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 5
cts 6
cp 0.8333
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2.0185
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