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.

AccessToken   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 78
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A __toString() 0 4 1
A resetExpiresAt() 0 5 1
A getExpiresAt() 0 4 1
A isExpired() 0 8 2
A getValue() 0 4 1
A setExpiresAtFromTimeStamp() 0 6 1
1
<?php
2
3
namespace LPTracker\authentication;
4
5
class AccessToken
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $value = '';
11
12
    /**
13
     * @var \DateTime|null
14
     */
15
    protected $expiresAt;
16
17
    /**
18
     * @param string $accessToken
19
     * @param int $expiresAt
20
     */
21
    public function __construct($accessToken, $expiresAt = 0)
22
    {
23
        $this->value = $accessToken;
24
        if ($expiresAt) {
25
            $this->setExpiresAtFromTimeStamp($expiresAt);
26
        } else {
27
            $this->resetExpiresAt();
28
        }
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function __toString()
35
    {
36
        return $this->getValue();
37
    }
38
39
    public function resetExpiresAt()
40
    {
41
        $this->expiresAt = new \DateTime();
42
        $this->expiresAt->modify('+1 day');
43
    }
44
45
    /**
46
     * @return \DateTime|null
47
     */
48
    public function getExpiresAt()
49
    {
50
        return $this->expiresAt;
51
    }
52
53
    /**
54
     * @return bool|null
55
     */
56
    public function isExpired()
57
    {
58
        if ($this->getExpiresAt() instanceof \DateTime) {
59
            return $this->getExpiresAt()->getTimestamp() < time();
60
        }
61
62
        return null;
63
    }
64
65
    /**
66
     * @return string
67
     */
68
    public function getValue()
69
    {
70
        return $this->value;
71
    }
72
73
    /**
74
     * @param int $timeStamp
75
     */
76
    protected function setExpiresAtFromTimeStamp($timeStamp)
77
    {
78
        $dt = new \DateTime();
79
        $dt->setTimestamp($timeStamp);
80
        $this->expiresAt = $dt;
81
    }
82
}
83