Completed
Pull Request — master (#10)
by
unknown
02:57
created

AccessToken::getScope()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Akeneo\SalesForce\Authentification;
4
5
use Carbon\Carbon;
6
7
class AccessToken
8
{
9
    /**
10
     * @var string
11
     */
12
    private $id;
13
14
    /**
15
     * @var \Carbon\Carbon
16
     */
17
    private $dateIssued;
18
19
    /**
20
     * @var \Carbon\Carbon
21
     */
22
    private $dateExpires;
23
24
    /**
25
     * @var array
26
     */
27
    private $scope;
28
29
    /**
30
     * @var string
31
     */
32
    private $tokenType;
33
34
    /**
35
     * @var string
36
     */
37
    private $refreshToken;
38
39
    /**
40
     * @var string
41
     */
42
    private $signature;
43
44
    /**
45
     * @var string
46
     */
47
    private $accessToken;
48
49
    /**
50
     * @var string
51
     */
52
    private $apiUrl;
53
54
    /**
55
     * @param string         $id
56
     * @param \Carbon\Carbon $dateIssued
57
     * @param \Carbon\Carbon $dateExpires
58
     * @param array          $scope
59
     * @param string         $tokenType
60
     * @param string         $refreshToken
61
     * @param string         $signature
62
     * @param string         $accessToken
63
     * @param string         $apiUrl
64
     */
65
    public function __construct(
66
        $id,
67
        $dateIssued,
68
        $dateExpires,
69
        $scope,
70
        $tokenType,
71
        $refreshToken,
72
        $signature,
73
        $accessToken,
74
        $apiUrl
75
    ) {
76
        $this->id           = $id;
77
        $this->dateIssued   = $dateIssued;
78
        $this->dateExpires  = $dateExpires;
79
        $this->scope        = $scope;
80
        $this->tokenType    = $tokenType;
81
        $this->refreshToken = $refreshToken;
82
        $this->signature    = $signature;
83
        $this->accessToken  = $accessToken;
84
        $this->apiUrl       = $apiUrl;
85
    }
86
87
    public function updateFromSalesforceRefresh(array $salesforceToken)
88
    {
89
        $this->dateIssued = Carbon::createFromTimestamp((int) ($salesforceToken[TokenFields::ISSUED_AT] / 1000));
90
91
        $this->dateExpires = $this->dateIssued->copy()->addHour()->subMinutes(5);
92
93
        $this->signature = $salesforceToken[TokenFields::SIGNATURE];
0 ignored issues
show
Documentation Bug introduced by
It seems like $salesforceToken[\Akeneo...TokenFields::SIGNATURE] of type integer or double is incompatible with the declared type string of property $signature.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
94
95
        $this->accessToken = $salesforceToken[TokenFields::ACCESS_TOKEN];
0 ignored issues
show
Documentation Bug introduced by
It seems like $salesforceToken[\Akeneo...enFields::ACCESS_TOKEN] of type integer or double is incompatible with the declared type string of property $accessToken.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
96
    }
97
98
    /**
99
     * @return bool
100
     */
101
    public function needsRefresh()
102
    {
103
        return $this->dateExpires->lt(Carbon::now());
104
    }
105
106
    /**
107
     * @return array
108
     */
109
    public function toArray()
110
    {
111
        return [
112
            TokenFields::ID            => $this->id,
113
            TokenFields::DATE_ISSUED   => $this->dateIssued->format(TokenFields::DATE_ISSUED_FORMAT),
114
            TokenFields::DATE_EXPIRES  => $this->dateExpires->format(TokenFields::DATE_EXPIRES_FORMAT),
115
            TokenFields::SCOPE         => $this->scope,
116
            TokenFields::TOKEN_TYPE    => $this->tokenType,
117
            TokenFields::REFRESH_TOKEN => $this->refreshToken,
118
            TokenFields::SIGNATURE     => $this->signature,
119
            TokenFields::ACCESS_TOKEN  => $this->accessToken,
120
            TokenFields::API_URL       => $this->apiUrl,
121
        ];
122
    }
123
124
    /**
125
     * @param int $options
126
     *
127
     * @return string
128
     */
129
    public function toJson($options = 0)
130
    {
131
        return json_encode($this->toArray(), $options);
132
    }
133
134
    /**
135
     * @return string
136
     */
137
    public function __toString()
138
    {
139
        return $this->toJson();
140
    }
141
142
    /**
143
     * @return Carbon
144
     */
145
    public function getDateExpires()
146
    {
147
        return $this->dateExpires;
148
    }
149
150
    /**
151
     * @return Carbon
152
     */
153
    public function getDateIssued()
154
    {
155
        return $this->dateIssued;
156
    }
157
158
    /**
159
     * @return string
160
     */
161
    public function getRefreshToken()
162
    {
163
        return $this->refreshToken;
164
    }
165
166
    /**
167
     * @return string
168
     */
169
    public function getAccessToken()
170
    {
171
        return $this->accessToken;
172
    }
173
174
    /**
175
     * @return array
176
     */
177
    public function getScope()
178
    {
179
        return $this->scope;
180
    }
181
182
    /**
183
     * @return string
184
     */
185
    public function getApiUrl()
186
    {
187
        return $this->apiUrl;
188
    }
189
}
190