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 ( a580f3...5442c0 )
by François
02:14
created

AccessToken::fromJson()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 17

Duplication

Lines 4
Ratio 14.81 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 27
rs 6.7272
cc 7
eloc 17
nc 6
nop 1
1
<?php
2
3
/**
4
 * Copyright (c) 2016, 2017 François Kooman <[email protected]>.
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
25
namespace fkooman\OAuth\Client;
26
27
use DateTime;
28
29
class AccessToken
30
{
31
    /** @var string */
32
    private $accessToken;
33
34
    /** @var string */
35
    private $tokenType;
36
37
    /** @var string */
38
    private $scope;
39
40
    /** @var string|null */
41
    private $refreshToken;
42
43
    /** @var \DateTime */
44
    private $expiresAt;
45
46
    /**
47
     * @param string      $accessToken
48
     * @param string      $tokenType
49
     * @param string      $scope
50
     * @param string|null $refreshToken
51
     * @param \DateTime   $expiresAt
52
     */
53
    public function __construct($accessToken, $tokenType, $scope, $refreshToken, DateTime $expiresAt)
54
    {
55
        $this->accessToken = $accessToken;
56
        $this->tokenType = $tokenType;
57
        $this->scope = $scope;
58
        $this->refreshToken = $refreshToken;
59
        $this->expiresAt = $expiresAt;
60
    }
61
62
    /**
63
     * Get the access token.
64
     *
65
     * @return string the access token
66
     *
67
     * @see https://tools.ietf.org/html/rfc6749#section-5.1
68
     */
69
    public function getToken()
70
    {
71
        return $this->accessToken;
72
    }
73
74
    /**
75
     * Get the token type.
76
     *
77
     * @return string the token type
78
     *
79
     * @see https://tools.ietf.org/html/rfc6749#section-7.1
80
     */
81
    public function getTokenType()
82
    {
83
        return $this->tokenType;
84
    }
85
86
    /**
87
     * Get the scope.
88
     *
89
     * @return string the scope
90
     *
91
     * @see https://tools.ietf.org/html/rfc6749#section-3.3
92
     */
93
    public function getScope()
94
    {
95
        return $this->scope;
96
    }
97
98
    /**
99
     * Get the refresh token.
100
     *
101
     * @return string|null the refresh token
102
     *
103
     * @see https://tools.ietf.org/html/rfc6749#section-1.5
104
     */
105
    public function getRefreshToken()
106
    {
107
        return $this->refreshToken;
108
    }
109
110
    /**
111
     * @return \DateTime
112
     */
113
    public function getExpiresAt()
114
    {
115
        return $this->expiresAt;
116
    }
117
118
    /**
119
     * @param DateTime $dateTime the current time
120
     *
121
     * @return bool
122
     */
123
    public function isExpired(DateTime $dateTime)
124
    {
125
        return $dateTime >= $this->expiresAt;
126
    }
127
128
    /**
129
     * @return string
130
     */
131
    public function json()
132
    {
133
        return json_encode(
134
            [
135
                'access_token' => $this->getToken(),
136
                'token_type' => $this->getTokenType(),
137
                'scope' => $this->getScope(),
138
                'refresh_token' => $this->getRefreshToken(),
139
                'expires_at' => $this->getExpiresAt()->format('Y-m-d H:i:s'),
140
            ]
141
        );
142
    }
143
}
144