@@ -49,12 +49,12 @@ discard block |
||
49 | 49 | public function handleNewTokens($response_timestamp, $refresh_token, $access_token) |
50 | 50 | { |
51 | 51 | $this->resetAcquiringLockTries(); |
52 | - if($this->acquireLock($this->token_lock_name) === false) { |
|
52 | + if ($this->acquireLock($this->token_lock_name) === false) { |
|
53 | 53 | throw new \Exception('Could not acquire lock..'); |
54 | 54 | } |
55 | 55 | |
56 | 56 | $refreshed = false; |
57 | - if($this->isNewRefreshToken($response_timestamp, $refresh_token)) { |
|
57 | + if ($this->isNewRefreshToken($response_timestamp, $refresh_token)) { |
|
58 | 58 | $this->saveNewTokens($response_timestamp, $refresh_token, $access_token); |
59 | 59 | $this->saveTokenToHistory($response_timestamp, $refresh_token, $access_token); |
60 | 60 | $this->saveLastToken($refresh_token); |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | */ |
76 | 76 | public function getLatestRefreshToken($fallback_token) |
77 | 77 | { |
78 | - if($this->acquireLock($this->token_lock_name) === false) { |
|
78 | + if ($this->acquireLock($this->token_lock_name) === false) { |
|
79 | 79 | throw new \Exception('Could not acquire lock..'); |
80 | 80 | } |
81 | 81 | |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | { |
95 | 95 | $tokens = Cache::get($this->token_history_name, []); |
96 | 96 | |
97 | - foreach($tokens as $token) { |
|
98 | - if($token['refresh_token'] === $refresh_token) { |
|
97 | + foreach ($tokens as $token) { |
|
98 | + if ($token['refresh_token'] === $refresh_token) { |
|
99 | 99 | return false; |
100 | 100 | } |
101 | - if($token['time'] > $response_timestamp) { |
|
101 | + if ($token['time'] > $response_timestamp) { |
|
102 | 102 | return false; |
103 | 103 | } |
104 | 104 | } |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | public function handleMinuteLimit($limit) |
166 | 166 | { |
167 | 167 | $this->resetAcquiringLockTries(); |
168 | - if($this->acquireLock($this->limit_lock_name) === false) { |
|
168 | + if ($this->acquireLock($this->limit_lock_name) === false) { |
|
169 | 169 | throw new \Exception('Could not acquire lock..'); |
170 | 170 | } |
171 | 171 | |
@@ -196,13 +196,13 @@ discard block |
||
196 | 196 | */ |
197 | 197 | protected function acquireLock($key) |
198 | 198 | { |
199 | - if($this->acquiring_lock_tries >= 20) { |
|
199 | + if ($this->acquiring_lock_tries >= 20) { |
|
200 | 200 | return false; |
201 | 201 | } |
202 | 202 | |
203 | 203 | $this->acquiring_lock_tries++; |
204 | 204 | |
205 | - if(Cache::has($key)) { |
|
205 | + if (Cache::has($key)) { |
|
206 | 206 | $this->sleepForLock(); |
207 | 207 | return $this->acquireLock($key); |
208 | 208 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | |
213 | 213 | $this->sleepForLock(); |
214 | 214 | |
215 | - if(Cache::get($key) === $random_value) { |
|
215 | + if (Cache::get($key) === $random_value) { |
|
216 | 216 | return true; |
217 | 217 | } |
218 | 218 |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | $latest_refresh_token = $this->getProfile() |
26 | 26 | ->getLatestRefreshToken($current_refresh_token); |
27 | 27 | |
28 | - if($latest_refresh_token !== $current_refresh_token) { |
|
28 | + if ($latest_refresh_token !== $current_refresh_token) { |
|
29 | 29 | $this->useNewRefreshToken($latest_refresh_token); |
30 | 30 | } |
31 | 31 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | protected function handleRateLimitsFromResponse(Response $response) |
48 | 48 | { |
49 | - if($response->hasHeader('X-RateLimit-Minutely-Limit') === false) { |
|
49 | + if ($response->hasHeader('X-RateLimit-Minutely-Limit') === false) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $profile_class_name = Config::get('exact.profile', DefaultProfile::class); |
80 | 80 | |
81 | 81 | $profile = new $profile_class_name(); |
82 | - if($profile instanceof DefaultProfile === false) { |
|
82 | + if ($profile instanceof DefaultProfile === false) { |
|
83 | 83 | throw new \Exception('Profile must extend \Picqer\Financials\Exact\DefaultProfile'); |
84 | 84 | } |
85 | 85 |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | protected function pause() |
253 | 253 | { |
254 | 254 | if ($this->pauseForMinuteLimitEnabled()) { |
255 | - if($this->minuteLimitExceeded()) { |
|
255 | + if ($this->minuteLimitExceeded()) { |
|
256 | 256 | sleep(60); |
257 | 257 | } |
258 | 258 | } |
@@ -312,12 +312,12 @@ discard block |
||
312 | 312 | } |
313 | 313 | |
314 | 314 | // If we have a token, sign the request |
315 | - if (!$this->needsAuthentication() && !empty($this->accessToken)) { |
|
315 | + if ( ! $this->needsAuthentication() && ! empty($this->accessToken)) { |
|
316 | 316 | $headers['Authorization'] = 'Bearer ' . $this->accessToken; |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Create param string |
320 | - if (!empty($params)) { |
|
320 | + if ( ! empty($params)) { |
|
321 | 321 | $endpoint .= '?' . http_build_query($params); |
322 | 322 | } |
323 | 323 | |
@@ -673,7 +673,7 @@ discard block |
||
673 | 673 | */ |
674 | 674 | private function getTimestampFromExpiresIn($expiresIn) |
675 | 675 | { |
676 | - if (!ctype_digit($expiresIn)) { |
|
676 | + if ( ! ctype_digit($expiresIn)) { |
|
677 | 677 | throw new \InvalidArgumentException('Function requires a numeric expires value'); |
678 | 678 | } |
679 | 679 | |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | */ |
772 | 772 | private function parseExceptionForErrorMessages(Exception $e) |
773 | 773 | { |
774 | - if (! $e instanceof BadResponseException) { |
|
774 | + if ( ! $e instanceof BadResponseException) { |
|
775 | 775 | throw new ApiException($e->getMessage()); |
776 | 776 | } |
777 | 777 | |
@@ -780,13 +780,13 @@ discard block |
||
780 | 780 | $responseBody = $response->getBody()->getContents(); |
781 | 781 | $decodedResponseBody = json_decode($responseBody, true); |
782 | 782 | |
783 | - if (! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) { |
|
783 | + if ( ! is_null($decodedResponseBody) && isset($decodedResponseBody['error']['message']['value'])) { |
|
784 | 784 | $errorMessage = $decodedResponseBody['error']['message']['value']; |
785 | 785 | } else { |
786 | 786 | $errorMessage = $responseBody; |
787 | 787 | } |
788 | 788 | |
789 | - throw new ApiException('Error ' . $response->getStatusCode() .': ' . $errorMessage); |
|
789 | + throw new ApiException('Error ' . $response->getStatusCode() . ': ' . $errorMessage); |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | /** |