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.

Access::getToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 8
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace BlizzardApi\Tokens;
4
5
use BlizzardApi\Tokens\Exceptions\Expired;
6
7
/**
8
 * Class Access Token
9
 *
10
 * @author Hristo Mitev <[email protected]>
11
 * @author Oleg Kachinsky <[email protected]>
12
 */
13
class Access
14
{
15
    /**
16
     * @var string $token The access token itself
17
     */
18
    protected $token;
19
20
    /**
21
     * @var string $tokenType The type of the token
22
     */
23
    protected $tokenType;
24
25
    /**
26
     * @var int $expiresIn The time for the token to expire in seconds
27
     */
28
    protected $expiresIn;
29
30
    /**
31
     * @var \DateTime $createdAt when was the token created
32
     */
33
    protected $createdAt;
34
35
    /**
36
     * @var \DateTime $expiresAt when is the token expiring
37
     */
38
    protected $expiresAt;
39
40
    /**
41
     * Constructor
42
     *
43
     * @param string $accessToken Access token
44
     * @param string $tokenType   Token type
45
     * @param int    $expiresIn   Expires in (seconds)
46
     */
47
    public function __construct($accessToken, $tokenType, $expiresIn)
48
    {
49
        $this->token = $accessToken;
50
        $this->tokenType = $tokenType;
51
        $this->expiresIn = $expiresIn;
52
        $this->createdAt = new \DateTime();
53
        $this->expiresAt = new \DateTime();
54
        $this->expiresAt->add(new \DateInterval('PT'.$this->expiresIn.'S'));
55
    }
56
57
    /**
58
     * Create token from json object
59
     *
60
     * @param \stdClass $jsonObject JSON object
61
     *
62
     * @return Access
63
     */
64
    public static function fromJson($jsonObject)
65
    {
66
        return new self($jsonObject->access_token, $jsonObject->token_type, $jsonObject->expires_in);
67
    }
68
69
    /**
70
     * Check if the token is expired
71
     *
72
     * @return bool
73
     */
74
    public function isExpired()
75
    {
76
        return $this->expiresAt < new \DateTime();
77
    }
78
79
    /**
80
     * Get the token string
81
     *
82
     * @return string
83
     *
84
     * @throws Expired
85
     */
86
    public function getToken()
87
    {
88
        if ($this->isExpired()) {
89
            throw new Expired('Token has expired');
90
        }
91
92
        return $this->token;
93
    }
94
}
95