Skip to content

Commit

Permalink
Merge pull request #290 from TomA-R/fix_time
Browse files Browse the repository at this point in the history
Fix Client::getTime()
  • Loading branch information
TomA-R authored May 17, 2023
2 parents faaa7a6 + 3a94a87 commit b1e8767
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 22 deletions.
12 changes: 1 addition & 11 deletions .phpstan/baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,6 @@ parameters:
count: 1
path: ../src/Bigcommerce/Api/Client.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:getRequestsRemaining\\(\\) should return int but returns false\\.$#"
count: 1
path: ../src/Bigcommerce/Api/Client.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:getRulesByProduct\\(\\) has parameter \\$filter with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -450,11 +445,6 @@ parameters:
count: 1
path: ../src/Bigcommerce/Api/Client.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:getTime\\(\\) should return DateTime but returns array\\|float\\|int\\|string\\|false\\|null\\.$#"
count: 1
path: ../src/Bigcommerce/Api/Client.php

-
message: "#^Method Bigcommerce\\\\Api\\\\Client\\:\\:mapCollection\\(\\) has parameter \\$object with no value type specified in iterable type array\\.$#"
count: 1
Expand Down Expand Up @@ -547,7 +537,7 @@ parameters:

-
message: "#^Negated boolean expression is always false\\.$#"
count: 2
count: 1
path: ../src/Bigcommerce/Api/Client.php

-
Expand Down
15 changes: 8 additions & 7 deletions src/Bigcommerce/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace Bigcommerce\Api;

use \Exception as Exception;
use DateTime;
use Exception;
use Firebase\JWT\JWT;

/**
Expand Down Expand Up @@ -452,17 +453,17 @@ public static function getCustomerLoginToken($id, $redirectUrl = '', $requestIp
/**
* Pings the time endpoint to test the connection to a store.
*
* @return \DateTime
* @return ?DateTime
*/
public static function getTime()
{
$response = self::connection()->get(self::$api_path . '/time');
$response = self::connection()->get(self::$api_url . '/time');

if ($response == false || is_string($response)) {
return $response;
if (empty($response)) {
return null;
}

return new \DateTime("@{$response->time}");
return new DateTime("@{$response}");
}

/**
Expand Down Expand Up @@ -1333,7 +1334,7 @@ public static function getStore()
* last request that was fetched within the current script. If no
* requests have been made, pings the time endpoint to get the value.
*
* @return int
* @return int|false
*/
public static function getRequestsRemaining()
{
Expand Down
8 changes: 4 additions & 4 deletions test/Unit/Api/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public function testGetTimeReturnsTheExpectedTime()
$now = new \DateTime();
$this->connection->expects($this->once())
->method('get')
->with($this->basePath . '/time', false)
->will($this->returnValue((object)array('time' => $now->format('U'))));
->with('https://api.bigcommerce.com/time', false)
->will($this->returnValue($now->format('U')));

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

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

$this->assertSame(12345, Client::getRequestsRemaining());
}
Expand Down

0 comments on commit b1e8767

Please sign in to comment.