Skip to content

Commit

Permalink
Raised phpstan level to 8
Browse files Browse the repository at this point in the history
Signed-off-by: Kristian Feldsam <feldsam@gmail.com>
  • Loading branch information
feldsam committed Jun 10, 2024
1 parent e91bdca commit 22fbc76
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
],
"test": "phpunit",
"phpcs": "phpcs --standard=PSR2 src && phpcs --standard=PSR2 tests",
"phpstan": "phpstan analyse -l 6 src tests"
"phpstan": "phpstan analyse -l 8 src tests"
}
}
22 changes: 16 additions & 6 deletions src/FioApi/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use FioApi\Exceptions\TooGreedyException;
use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;

Expand Down Expand Up @@ -59,27 +61,35 @@ public function setLastId(string $id): void

try {
$client->request('get', $url);
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
} catch (BadResponseException $e) {
$this->handleException($e);
}
}

/**
* @param string $url
* @return TransactionList
* @throws GuzzleException
*/
private function downloadTransactionsList(string $url): TransactionList

Check failure on line 74 in src/FioApi/Downloader.php

View workflow job for this annotation

GitHub Actions / PHP 7.4 on ubuntu-latest --prefer-lowest

PHPDoc tag @throws with type GuzzleHttp\Exception\GuzzleException is not subtype of Throwable

Check failure on line 74 in src/FioApi/Downloader.php

View workflow job for this annotation

GitHub Actions / PHP 8.0 on ubuntu-latest --prefer-lowest

PHPDoc tag @throws with type GuzzleHttp\Exception\GuzzleException is not subtype of Throwable

Check failure on line 74 in src/FioApi/Downloader.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 on ubuntu-latest --prefer-lowest

PHPDoc tag @throws with type GuzzleHttp\Exception\GuzzleException is not subtype of Throwable
{
$client = $this->getClient();
/** @var ?ResponseInterface $response */
$response = null;
$transactions = null;

try {
/** @var ?ResponseInterface $response */
$response = $client->request('get', $url);
} catch (\GuzzleHttp\Exception\BadResponseException $e) {
if ($response) {
$transactions = json_decode($response->getBody()->getContents())->accountStatement;
}
} catch (BadResponseException $e) {
$this->handleException($e);
}

return TransactionList::create(json_decode($response->getBody()->getContents())->accountStatement);
return TransactionList::create($transactions);
}

private function handleException(\GuzzleHttp\Exception\BadResponseException $e): void
private function handleException(BadResponseException $e): void
{
if ($e->getCode() == 409) {
throw new TooGreedyException('You can use one token for API call every 30 seconds', $e->getCode(), $e);
Expand Down
6 changes: 3 additions & 3 deletions src/FioApi/TransactionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ class TransactionList
/** @var \DateTimeImmutable */
protected $dateEnd;

/** @var float */
/** @var float|null */
protected $idFrom;

/** @var float */
/** @var float|null */
protected $idTo;

/** @var int */
/** @var int|null */
protected $idLastDownload;

/** @var Account */
Expand Down
4 changes: 2 additions & 2 deletions tests/FioApi/DownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function testUnknownResponseCodePassesOriginalException(): void
public function testDownloaderDownloadsData(): void
{
$handler = HandlerStack::create(new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . '/data/example-response.json')),
new Response(200, [], (string) file_get_contents(__DIR__ . '/data/example-response.json')),
]));
$downloader = new Downloader('validToken', new Client(['handler' => $handler]));

Expand All @@ -63,7 +63,7 @@ public function testDownloaderDownloadsData(): void
public function testDownloaderDownloadsLast(): void
{
$handler = HandlerStack::create(new MockHandler([
new Response(200, [], file_get_contents(__DIR__ . '/data/example-response.json')),
new Response(200, [], (string) file_get_contents(__DIR__ . '/data/example-response.json')),
]));
$downloader = new Downloader('validToken', new Client(['handler' => $handler]));

Expand Down
4 changes: 2 additions & 2 deletions tests/FioApi/TransactionListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TransactionListTest extends \PHPUnit\Framework\TestCase
{
public function testTransactionListValuesAreProperlySet(): void
{
$transactionList = json_decode(file_get_contents(__DIR__ . '/data/example-response.json'));
$transactionList = json_decode((string) file_get_contents(__DIR__ . '/data/example-response.json'));

$transactionList = TransactionList::create($transactionList->accountStatement);

Expand All @@ -24,7 +24,7 @@ public function testTransactionListValuesAreProperlySet(): void

public function testEmptyTransactionList(): void
{
$transactionList = json_decode(file_get_contents(__DIR__ . '/data/example-empty-response.json'));
$transactionList = json_decode((string) file_get_contents(__DIR__ . '/data/example-empty-response.json'));

$transactionList = TransactionList::create($transactionList->accountStatement);

Expand Down
2 changes: 1 addition & 1 deletion tests/FioApi/TransactionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TransactionTest extends \PHPUnit\Framework\TestCase
{
public function testAccountValuesAreProperlySet(): void
{
$transaction = json_decode(file_get_contents(__DIR__ . '/data/example-transaction.json'));
$transaction = json_decode((string) file_get_contents(__DIR__ . '/data/example-transaction.json'));

$transaction = Transaction::create($transaction);

Expand Down

0 comments on commit 22fbc76

Please sign in to comment.