Skip to content

Commit

Permalink
Even more stricter rules via phpstan/phpstan-strict-rules, thecodingm…
Browse files Browse the repository at this point in the history
…achind, symplify
  • Loading branch information
jimmerioles committed Dec 20, 2024
1 parent a57b6bc commit 276da1b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 29 deletions.
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"laravel/pint": "1.5.*",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-mockery": "^1.1",
"phpstan/extension-installer": "^1.4"
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan-strict-rules": "^1.6",
"thecodingmachine/phpstan-strict-rules": "^1.0",
"symplify/phpstan-rules": "^13.0"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -71,4 +74,4 @@
"@test:phpunit"
]
}
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 9
level: max
phpVersion: 80000
paths:
- src
23 changes: 2 additions & 21 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Jimmerioles\BitcoinCurrencyConverter\Provider\CoinbaseProvider;
use Jimmerioles\BitcoinCurrencyConverter\Provider\ProviderInterface;
use Jimmerioles\BitcoinCurrencyConverter\Exception\InvalidArgumentException;

class Converter
{
Expand Down Expand Up @@ -46,18 +45,9 @@ protected function getRate($currencyCode)

/**
* Compute currency value.
*
* @param float $btcAmount
* @param float $rate
* @return float
* @throws InvalidArgumentException
*/
protected function computeCurrencyValue($btcAmount, $rate): int|float
protected function computeCurrencyValue(int|float $btcAmount, int|float $rate): int|float
{
if (! is_numeric($btcAmount)) {
throw new InvalidArgumentException("Argument \$btcAmount should be numeric, '{$btcAmount}' given.");
}

return $btcAmount * $rate;
}

Expand Down Expand Up @@ -86,18 +76,9 @@ public function toBtc(float $amount, string $currencyCode): float

/**
* Compute Bitcoin value.
*
* @param float $amount
* @param float $rate
* @return float
* @throws InvalidArgumentException
*/
protected function computeBtcValue($amount, $rate): int|float
protected function computeBtcValue(int|float $amount, int|float $rate): int|float
{
if (! is_numeric($amount)) {
throw new InvalidArgumentException("Argument \$amount should be numeric, '{$amount}' given.");
}

return $amount / $rate;
}
}
6 changes: 3 additions & 3 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class AbstractProvider implements ProviderInterface
*
* @var array<string, int|float>
*/
protected $exchangeRates;
protected $exchangeRates = [];

/**
* Cache key string.
Expand Down Expand Up @@ -83,7 +83,7 @@ public function getRate($currencyCode)
*/
protected function isSupportedByProvider($currencyCode)
{
return in_array(strtoupper($currencyCode), array_keys($this->exchangeRates));
return in_array(strtoupper($currencyCode), array_keys($this->exchangeRates), true);
}

/**
Expand All @@ -93,7 +93,7 @@ protected function isSupportedByProvider($currencyCode)
*/
protected function getExchangeRates()
{
if (empty($this->exchangeRates)) {
if ($this->exchangeRates === []) {
$this->setExchangeRates($this->retrieveExchangeRates());
}

Expand Down
4 changes: 2 additions & 2 deletions src/Util/CurrencyCodeChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ class CurrencyCodeChecker
*/
public function isCryptoCurrency($currencyCode): bool
{
return in_array(strtoupper($currencyCode), $this->cryptoCurrencyCodes);
return in_array(strtoupper($currencyCode), $this->cryptoCurrencyCodes, true);
}

/**
Expand All @@ -328,7 +328,7 @@ public function isCryptoCurrency($currencyCode): bool
*/
public function isFiatCurrency($currencyCode): bool
{
return in_array(strtoupper($currencyCode), $this->fiatCurrencyCodes);
return in_array(strtoupper($currencyCode), $this->fiatCurrencyCodes, true);
}

/**
Expand Down

0 comments on commit 276da1b

Please sign in to comment.