Skip to content

Commit b1e8767

Browse files
authored
Merge pull request #290 from TomA-R/fix_time
Fix Client::getTime()
2 parents faaa7a6 + 3a94a87 commit b1e8767

3 files changed

Lines changed: 13 additions & 22 deletions

File tree

.phpstan/baseline.neon

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,6 @@ parameters:
385385
count: 1
386386
path: ../src/Bigcommerce/Api/Client.php
387387

388-
-
389-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:getRequestsRemaining\\(\\) should return int but returns false\\.$#"
390-
count: 1
391-
path: ../src/Bigcommerce/Api/Client.php
392-
393388
-
394389
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:getRulesByProduct\\(\\) has parameter \\$filter with no value type specified in iterable type array\\.$#"
395390
count: 1
@@ -450,11 +445,6 @@ parameters:
450445
count: 1
451446
path: ../src/Bigcommerce/Api/Client.php
452447

453-
-
454-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:getTime\\(\\) should return DateTime but returns array\\|float\\|int\\|string\\|false\\|null\\.$#"
455-
count: 1
456-
path: ../src/Bigcommerce/Api/Client.php
457-
458448
-
459449
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:mapCollection\\(\\) has parameter \\$object with no value type specified in iterable type array\\.$#"
460450
count: 1
@@ -547,7 +537,7 @@ parameters:
547537

548538
-
549539
message: "#^Negated boolean expression is always false\\.$#"
550-
count: 2
540+
count: 1
551541
path: ../src/Bigcommerce/Api/Client.php
552542

553543
-

src/Bigcommerce/Api/Client.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Bigcommerce\Api;
44

5-
use \Exception as Exception;
5+
use DateTime;
6+
use Exception;
67
use Firebase\JWT\JWT;
78

89
/**
@@ -452,17 +453,17 @@ public static function getCustomerLoginToken($id, $redirectUrl = '', $requestIp
452453
/**
453454
* Pings the time endpoint to test the connection to a store.
454455
*
455-
* @return \DateTime
456+
* @return ?DateTime
456457
*/
457458
public static function getTime()
458459
{
459-
$response = self::connection()->get(self::$api_path . '/time');
460+
$response = self::connection()->get(self::$api_url . '/time');
460461

461-
if ($response == false || is_string($response)) {
462-
return $response;
462+
if (empty($response)) {
463+
return null;
463464
}
464465

465-
return new \DateTime("@{$response->time}");
466+
return new DateTime("@{$response}");
466467
}
467468

468469
/**
@@ -1333,7 +1334,7 @@ public static function getStore()
13331334
* last request that was fetched within the current script. If no
13341335
* requests have been made, pings the time endpoint to get the value.
13351336
*
1336-
* @return int
1337+
* @return int|false
13371338
*/
13381339
public static function getRequestsRemaining()
13391340
{

test/Unit/Api/ClientTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ public function testGetTimeReturnsTheExpectedTime()
244244
$now = new \DateTime();
245245
$this->connection->expects($this->once())
246246
->method('get')
247-
->with($this->basePath . '/time', false)
248-
->will($this->returnValue((object)array('time' => $now->format('U'))));
247+
->with('https://api.bigcommerce.com/time', false)
248+
->will($this->returnValue($now->format('U')));
249249

250250
$this->assertEquals($now->format('U'), Client::getTime()->format('U'));
251251
}
@@ -278,8 +278,8 @@ public function testGetRequestsRemainingRequestsTimeWhenNoValueAvailable()
278278

279279
$this->connection->expects($this->once())
280280
->method('get')
281-
->with($this->basePath . '/time', false)
282-
->will($this->returnValue((object)array('time' => time())));
281+
->with('https://api.bigcommerce.com/time', false)
282+
->will($this->returnValue(time()));
283283

284284
$this->assertSame(12345, Client::getRequestsRemaining());
285285
}

0 commit comments

Comments
 (0)