Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,26 +0,0 @@
parameters:
ignoreErrors:
-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/ExchangeRateProviders/FixerProvider.php

-
message: "#^Cannot call method timezone\\(\\) on Carbon\\\\CarbonImmutable\\|null\\.$#"
count: 1
path: src/ExchangeRateProviders/FrankfurterProvider.php

-
message: "#^Strict comparison using \\=\\=\\= between Carbon\\\\CarbonImmutable\\|null and false will always evaluate to false\\.$#"
count: 1
path: src/ExchangeRateProviders/FrankfurterProvider.php

-
message: "#^Parameter \\#1 \\$value of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 1
path: src/Support/ExchangeRateManager.php

-
message: "#^Parameter \\#1 \\$value of function strval expects bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#"
count: 2
path: src/Support/ExchangeRateManager.php
2 changes: 1 addition & 1 deletion src/Commands/ViewLatestRatesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function handle(Exchange $exchange, CurrencyCodeProvider $currencyCodePro
$data = $this->data($currencyCodeProvider);

try {
// @phpstan-ignore-next-line
// @phpstan-ignore argument.type, argument.type
$this->renderRates($exchange->rates($data['base_currency'], $data['currencies']));
} catch (InvalidCurrencyCodeException $exception) {
$this->newLine();
Expand Down
15 changes: 12 additions & 3 deletions src/ExchangeRateProviders/CurrencyGEOProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
*/
public function getRates(string $baseCurrency, array $currencies): Rates
{
// If it's the same currency return it.
// If it's the same currency, return it.
if (count($currencies) === 1 && $baseCurrency === $currencies[0]) {
return new Rates(
$baseCurrency,
Expand All @@ -36,10 +36,19 @@ public function getRates(string $baseCurrency, array $currencies): Rates

$data = $this->makeRequest($baseCurrency, $currencies);

/**
* @var non-empty-array<string, array{
* currency_name: string,
* rate: numeric-string,
* rate_for_amount: numeric-string
* }> $rates
*/
$rates = $data->get('rates');

return new Rates(
$baseCurrency,
// @phpstan-ignore-next-line
collect($data->get('rates'))->map(fn (mixed $value) => floatval($value['rate']))->all(),
// @phpstan-ignore argument.type
collect($rates)->map(fn (array $value) => floatval($value['rate']))->all(),
now()->startOfDay(),
);
}
Expand Down
8 changes: 6 additions & 2 deletions src/ExchangeRateProviders/FixerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ public function getRates(string $baseCurrency, array $currencies): Rates
{
$data = $this->makeRequest($baseCurrency, $currencies);

/** @var non-empty-array<string, float> $rates */
$rates = $data->get('rates');

return new Rates(
$baseCurrency,
// @phpstan-ignore-next-line
collect($data->get('rates'))->map(fn (mixed $value) => floatval($value))->all(),
// @phpstan-ignore argument.type
collect($rates)->map(fn (mixed $value) => floatval($value))->all(),
// @phpstan-ignore argument.type
CarbonImmutable::createFromTimestamp(intval($data->get('timestamp')))
);
}
Expand Down
13 changes: 8 additions & 5 deletions src/ExchangeRateProviders/FrankfurterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@ public function getRates(string $baseCurrency, array $currencies): Rates
{
$data = $this->makeRequest($baseCurrency, $currencies);

/** @var non-empty-array<string, float> $rates */
$rates = $data->get('rates');

return new Rates(
$baseCurrency,
// @phpstan-ignore-next-line
collect($data->get('rates'))->map(fn (mixed $value) => (float) $value)->all(),
$this->getRetreivedAt($data),
// @phpstan-ignore argument.type
collect($rates)->map(fn (mixed $value) => (float) $value)->all(),
$this->getRetrievedAt($data),
);
}

Expand Down Expand Up @@ -67,7 +70,7 @@ private function client(): PendingRequest
*
* @return CarbonImmutable
*/
private function getRetreivedAt(Collection $data): CarbonImmutable
private function getRetrievedAt(Collection $data): CarbonImmutable
{
$date = $data->get('date');

Expand All @@ -77,7 +80,7 @@ private function getRetreivedAt(Collection $data): CarbonImmutable

$carbonInstance = CarbonImmutable::createFromFormat('Y-m-d', $date);

if ($carbonInstance === false) {
if ($carbonInstance === null) {
throw new InvalidArgumentException('The returned date could not be parsed.');
}

Expand Down
5 changes: 4 additions & 1 deletion src/Facades/Exchange.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Worksome\Exchange\Facades;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Support\Facades\Facade;
use Worksome\Exchange\Support\Rates;

Expand All @@ -20,10 +21,12 @@ final class Exchange extends Facade
*/
public static function fake(array $rates = []): void
{
assert(self::$app instanceof Application);

/**
* @var \Worksome\Exchange\Exchange $fake
*
* @phpstan-ignore-next-line
* @phpstan-ignore larastanStrictRules.noFacadeRule
*/
$fake = self::$app->instance(\Worksome\Exchange\Exchange::class, self::getFacadeRoot());

Expand Down
7 changes: 5 additions & 2 deletions src/Support/ExchangeRateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class ExchangeRateManager extends Manager
{
public function getDefaultDriver(): string
{
// @phpstan-ignore argument.type
return strval($this->config->get('exchange.default') ?? 'null');
}

Expand Down Expand Up @@ -82,11 +83,13 @@ public function createCacheDriver(): CachedProvider
$factory = $this->container->make(CacheFactory::class);

return new CachedProvider(
// @phpstan-ignore-next-line
// @phpstan-ignore argument.type
$factory->store($this->config->get('exchange.services.cache.store')),
// @phpstan-ignore-next-line
// @phpstan-ignore argument.type, argument.type
$this->driver($this->config->get('exchange.services.cache.strategy')),
// @phpstan-ignore argument.type
strval($this->config->get('exchange.services.cache.key', 'cached_exchange_rates')),
// @phpstan-ignore argument.type
intval($this->config->get('exchange.services.cache.ttl', 60 * 60 * 24)),
);
}
Expand Down