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 — 1.x ( f2247a...73fe3f )
by Jakub
04:00
created

TokenMemoryCacheStorage   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A set() 0 5 1
A has() 0 13 3
A delete() 0 5 1
A clear() 0 5 1
1
<?php
2
3
namespace zaporylie\Vipps\Authentication;
4
5
use zaporylie\Vipps\Exceptions\Authentication\InvalidArgumentException;
6
use zaporylie\Vipps\Model\Authorization\ResponseGetToken;
7
8
/**
9
 * Class TokenMemoryCacheStorage
10
 *
11
 * @package Vipps\Authentication
12
 */
13
class TokenMemoryCacheStorage implements TokenStorageInterface
14
{
15
16
    /**
17
     * @var \zaporylie\Vipps\Model\Authorization\ResponseGetToken
18
     */
19
    protected $token;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function get()
25
    {
26
        if (!$this->has()) {
27
            throw new InvalidArgumentException('Missing Token');
28
        }
29
        return $this->token;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function set(ResponseGetToken $token)
36
    {
37
        $this->token = $token;
38
        return $this;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function has()
45
    {
46
        if (!($this->token instanceof ResponseGetToken)) {
47
            return false;
48
        }
49
50
        if ($this->token->getExpiresOn()->getTimestamp() < (new \DateTime())->getTimestamp()) {
51
            $this->delete();
52
            return false;
53
        }
54
55
        return true;
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function delete()
62
    {
63
        $this->token = null;
64
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function clear()
71
    {
72
        $this->delete();
73
        return $this;
74
    }
75
}
76