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 ( 5dca88...ae720b )
by François
02:16
created

AccessToken::getRefreshToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2017 François Kooman <[email protected]>.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace fkooman\OAuth\Client;
20
21
use DateTime;
22
23
/**
24
 * AccessToken object containing the response from the OAuth 2.0 provider's
25
 * token response.
26
 */
27
class AccessToken
28
{
29
    /** @var string */
30
    private $token;
31
32
    /** @var string */
33
    private $tokenType;
34
35
    /** @var string */
36
    private $scope;
37
38
    /** @var string|null */
39
    private $refreshToken;
40
41
    /** @var \DateTime */
42
    private $expiresAt;
43
44
    public function __construct($token, $tokenType, $scope, $refreshToken, DateTime $expiresAt)
45
    {
46
        $this->token = $token;
47
        $this->tokenType = $tokenType;
48
        $this->scope = $scope;
49
        $this->refreshToken = $refreshToken;
50
        $this->expiresAt = $expiresAt;
51
    }
52
53
    /**
54
     * Get the access token as string.
55
     *
56
     * @return string the access token
57
     */
58
    public function __toString()
59
    {
60
        return sprintf(
61
            'token_type: %s, scope: %s, expires_at: %s, token: %s',
62
            $this->getTokenType(),
63
            $this->getScope(),
64
            $this->getExpiresAt()->format('Y-m-d H:i:s'),
65
            $this->getToken()
66
        );
67
    }
68
69
    /**
70
     * Get the access token.
71
     *
72
     * @return string the access token
73
     *
74
     * @see https://tools.ietf.org/html/rfc6749#section-5.1
75
     */
76
    public function getToken()
77
    {
78
        return $this->token;
79
    }
80
81
    /**
82
     * Get the token type.
83
     *
84
     * @return string the token type
85
     *
86
     * @see https://tools.ietf.org/html/rfc6749#section-7.1
87
     */
88
    public function getTokenType()
89
    {
90
        return $this->tokenType;
91
    }
92
93
    /**
94
     * Get the scope.
95
     *
96
     * @return string the scope
97
     *
98
     * @see https://tools.ietf.org/html/rfc6749#section-3.3
99
     */
100
    public function getScope()
101
    {
102
        return $this->scope;
103
    }
104
105
    /**
106
     * Get the refresh token.
107
     *
108
     * @return string|null the refresh token
109
     *
110
     * @see https://tools.ietf.org/html/rfc6749#section-1.5
111
     */
112
    public function getRefreshToken()
113
    {
114
        return $this->refreshToken;
115
    }
116
117
    /**
118
     * @return DateTime
119
     */
120
    public function getExpiresAt()
121
    {
122
        return $this->expiresAt;
123
    }
124
125
    /**
126
     * @param DateTime|null $dateTime
127
     *
128
     * @return bool
129
     */
130
    public function isExpired(DateTime $dateTime = null)
131
    {
132
        if (is_null($dateTime)) {
133
            $dateTime = new DateTime();
134
        }
135
136
        return $dateTime >= $this->expiresAt;
137
    }
138
}
139