Skip to content

Commit

Permalink
fixed #12
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Nov 16, 2023
1 parent 751ce50 commit 86de3c1
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/BucketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function getInventory(string $id): Http\Response
return $this->get(\sprintf('/?inventory&id=%s', $id));
}

public function getInventoryConfigurations(?string $nextContinuationToken = null): Http\Response
public function getInventoryConfigurations(string $nextContinuationToken = null): Http\Response
{
return $this->get(\sprintf('/?inventory&continuation-token=%s', $nextContinuationToken));
}
Expand Down
2 changes: 0 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class Client
protected array $requiredConfigKeys = [];

/**
* @param array|\Overtrue\CosClient\Config $config
*
* @throws \Overtrue\CosClient\Exceptions\InvalidConfigException
*/
public function __construct(array|Config $config)
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Overtrue\CosClient\Support\XML;
use Psr\Http\Message\ResponseInterface;

class Response extends \GuzzleHttp\Psr7\Response implements \JsonSerializable, \ArrayAccess
class Response extends \GuzzleHttp\Psr7\Response implements \ArrayAccess, \JsonSerializable
{
protected ?array $arrayResult = null;

Expand Down Expand Up @@ -128,19 +128,19 @@ final public function isServerError(): bool
#[Pure]
final public function isOk(): bool
{
return 200 === $this->getStatusCode();
return $this->getStatusCode() === 200;
}

#[Pure]
final public function isForbidden(): bool
{
return 403 === $this->getStatusCode();
return $this->getStatusCode() === 403;
}

#[Pure]
final public function isNotFound(): bool
{
return 404 === $this->getStatusCode();
return $this->getStatusCode() === 404;
}

#[Pure]
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class ServiceClient extends Client
{
public function getBuckets(?string $region = null): Http\Response
public function getBuckets(string $region = null): Http\Response
{
$uri = $region ? \sprintf('https://cos.%s.myqcloud.com/', $region) : 'https://service.cos.myqcloud.com/';

Expand Down
4 changes: 2 additions & 2 deletions src/Signature.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class Signature
'range',
];

public function __construct(public string $accessKey, public string $secretKey)
public function __construct(public string $accessKey, public string $secretKey)
{
}

public function createAuthorizationHeader(RequestInterface $request, int|string|\DateTimeInterface $expires = null): string
{
$signTime = self::getTimeSegments($expires);
$signTime = self::getTimeSegments($expires ?? '+60 minutes');
$queryToBeSigned = self::getQueryToBeSigned($request);
$headersToBeSigned = self::getHeadersToBeSigned($request);

Expand Down
19 changes: 19 additions & 0 deletions tests/SignatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,23 @@ public function test_getTimeSegments()

date_default_timezone_set($timezone);
}

public function test_getTimeSegments_with_null()
{
$signature = new Signature('mock-access-key', 'mock-secret-key');

$request = new Request('GET', 'https://example.com');

$timezone = \date_default_timezone_get();

date_default_timezone_set('PRC');

$output = strtotime('+60 minutes');
$expect = sprintf('q-sign-time=%d;%d&q-key-time=%d;%d', time() - 60, $output, time() - 60, $output);

$this->assertStringContainsString($expect, $signature->createAuthorizationHeader($request));
$this->assertStringContainsString($expect, $signature->createAuthorizationHeader($request, null));

date_default_timezone_set($timezone);
}
}

0 comments on commit 86de3c1

Please sign in to comment.