Skip to content

Commit

Permalink
QA: codesniffer
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Apr 8, 2023
1 parent f331f45 commit a83c093
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/Auth/AccessTokenCacheProvider.php
Expand Up @@ -15,11 +15,13 @@ class AccessTokenCacheProvider extends AccessTokenClient
public function __construct(IHttpClient $client, Cache $cache)
{
parent::__construct($client);

$this->cache = $cache;
}

protected function generateAccessToken(Config $config): AccessToken
{
// phpcs:ignore SlevomatCodingStandard.PHP.DisallowReference.DisallowedPassingByReference
$accessToken = $this->cache->load($config->getClientId(), function (&$dependecies) use ($config): AccessToken {
$token = parent::generateAccessToken($config);
$dependecies[Cache::Expire] = $token->getExpiresAt() - AccessToken::PRE_FETCH_SECONDS;
Expand Down
28 changes: 14 additions & 14 deletions src/Entity/AccessToken.php
Expand Up @@ -26,6 +26,20 @@ public function __construct(string $accessToken, int $expiresIn, string $tokenTy
$this->expiresAt = $expiresAt ?? time() + $expiresIn;
}

/**
* @param array{access_token: string, expires_in: int, token_type: string, scope: string, expires_at?: ?int} $data
*/
public static function fromArray(array $data): self
{
return new self(
$data['access_token'],
$data['expires_in'],
$data['token_type'],
$data['scope'],
$data['expires_at'] ?? null
);
}

public function isExpired(): bool
{
return $this->expiresAt - self::PRE_FETCH_SECONDS < time();
Expand Down Expand Up @@ -56,20 +70,6 @@ public function getExpiresAt(): int
return $this->expiresAt;
}

/**
* @param array{access_token: string, expires_in: int, token_type: string, scope: string, expires_at?: ?int} $data
*/
public static function fromArray(array $data): self
{
return new self(
$data['access_token'],
$data['expires_in'],
$data['token_type'],
$data['scope'],
$data['expires_at'] ?? null
);
}

/**
* @return array{access_token: string, expires_in: int, token_type: string, scope: string, expires_at: int}
*/
Expand Down
5 changes: 3 additions & 2 deletions tests/Cases/E2E/SendSmsTest.php
Expand Up @@ -24,9 +24,10 @@ class SendSmsTest extends TestCase

private MessageClient $client;

/** @var mixed[] */
private array $config = [];

protected function setUp()
public function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -65,7 +66,7 @@ public function testClient(): void

sleep(2); // wait for send sms
$this->client->delete($messageId);
Assert::exception(function () use ($messageId) {
Assert::exception(function () use ($messageId): void {
$this->client->detail($messageId);
}, ClientException::class);
}
Expand Down

0 comments on commit a83c093

Please sign in to comment.