Skip to content

Commit a392dcd

Browse files
committed
Fix usage of sleep
1 parent 6c33a58 commit a392dcd

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/ShipStation.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace LaravelShipStation;
34

45
use GuzzleHttp\Client;
@@ -31,7 +32,7 @@ class ShipStation
3132
'/stores/',
3233
'/users/',
3334
'/warehouses/',
34-
'/webhooks/'
35+
'/webhooks/',
3536
];
3637

3738
/**
@@ -59,14 +60,14 @@ class ShipStation
5960
*/
6061
public function __construct($apiKey, $apiSecret, $apiURL, $partnerApiKey = null)
6162
{
62-
if (!isset($apiKey, $apiSecret)) {
63+
if (! isset($apiKey, $apiSecret)) {
6364
throw new \Exception('Your API key and/or private key are not set. Did you run artisan vendor:publish?');
6465
}
6566

6667
$this->base_uri = $apiURL;
6768

6869
$headers = [
69-
'Authorization' => 'Basic ' . base64_encode("{$apiKey}:{$apiSecret}"),
70+
'Authorization' => 'Basic '.base64_encode("{$apiKey}:{$apiSecret}"),
7071
];
7172

7273
if (! empty($partnerApiKey)) {
@@ -143,7 +144,7 @@ public function update($options = [], $endpoint = '')
143144
}
144145

145146
/**
146-
* Get the maximum number of requests that can be sent per window
147+
* Get the maximum number of requests that can be sent per window.
147148
*
148149
* @return int
149150
*/
@@ -153,7 +154,7 @@ public function getMaxAllowedRequests()
153154
}
154155

155156
/**
156-
* Get the remaining number of requests that can be sent in the current window
157+
* Get the remaining number of requests that can be sent in the current window.
157158
*
158159
* @return int
159160
*/
@@ -163,7 +164,7 @@ public function getRemainingRequests()
163164
}
164165

165166
/**
166-
* Get the number of seconds remaining until the next window begins
167+
* Get the number of seconds remaining until the next window begins.
167168
*
168169
* @return int
169170
*/
@@ -174,7 +175,7 @@ public function getSecondsUntilReset()
174175

175176
/**
176177
* Are we currently rate limited?
177-
* We are if there are no more requests allowed in the current window
178+
* We are if there are no more requests allowed in the current window.
178179
*
179180
* @return bool
180181
*/
@@ -195,7 +196,7 @@ public function sleepIfRateLimited(Response $response)
195196
$this->secondsUntilReset = (int) $response->getHeader('X-Rate-Limit-Reset')[0];
196197

197198
if ($this->isRateLimited() || ($this->secondsUntilReset / $this->remainingRequests) > 1.5) {
198-
sleep(1.5);
199+
usleep(1500000);
199200
}
200201
}
201202

@@ -207,11 +208,11 @@ public function sleepIfRateLimited(Response $response)
207208
*/
208209
public function __get($property)
209210
{
210-
if (in_array('/' . $property . '/', $this->endpoints)) {
211-
$this->endpoint = '/' . $property . '/';
211+
if (in_array('/'.$property.'/', $this->endpoints)) {
212+
$this->endpoint = '/'.$property.'/';
212213
}
213214

214-
$className = "LaravelShipStation\\Helpers\\" . ucfirst($property);
215+
$className = 'LaravelShipStation\\Helpers\\'.ucfirst($property);
215216

216217
if (class_exists($className)) {
217218
return new $className($this);

0 commit comments

Comments
 (0)