Skip to content

Commit

Permalink
Level 5
Browse files Browse the repository at this point in the history
  • Loading branch information
ruudk committed Nov 23, 2024
1 parent b2a5d8d commit c157108
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
level: 4
level: 5
paths:
- src
- tests
Expand Down
2 changes: 1 addition & 1 deletion resources/generate-teller-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait TellerFactory
* </code>
*
* @param non-empty-string $method
* @param array{0?: int} $arguments
* @param array{0?: Money::ROUND_*} $arguments
*/
public static function __callStatic(string $method, array $arguments): Teller
{
Expand Down
11 changes: 10 additions & 1 deletion src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public function __construct(private readonly Currencies $currencies, private rea
{
}

/**
* @param Money::ROUND_* $roundingMode
*/
public function convert(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): Money
{
return $this->convertAgainstCurrencyPair(
Expand All @@ -29,7 +32,10 @@ public function convert(Money $money, Currency $counterCurrency, int $roundingMo
);
}

/** @return array{0: Money, 1: CurrencyPair} */
/**
* @param Money::ROUND_* $roundingMode
* @return array{0: Money, 1: CurrencyPair}
*/
public function convertAndReturnWithCurrencyPair(Money $money, Currency $counterCurrency, int $roundingMode = Money::ROUND_HALF_UP): array
{
$pair = $this->exchange->quote(
Expand All @@ -40,6 +46,9 @@ public function convertAndReturnWithCurrencyPair(Money $money, Currency $counter
return [$this->convertAgainstCurrencyPair($money, $pair, $roundingMode), $pair];
}

/**
* @param Money::ROUND_* $roundingMode
*/
public function convertAgainstCurrencyPair(Money $money, CurrencyPair $currencyPair, int $roundingMode = Money::ROUND_HALF_UP): Money
{
if (! $money->getCurrency()->equals($currencyPair->getBaseCurrency())) {
Expand Down
9 changes: 5 additions & 4 deletions src/MoneyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@
* @method static Money ZMW(numeric-string|int $amount)
* @method static Money ZRX(numeric-string|int $amount)
* @method static Money ZWL(numeric-string|int $amount)
* @phpstan-immutable
* @psalm-immutable
*/
trait MoneyFactory
{
Expand All @@ -571,12 +571,13 @@ trait MoneyFactory
* $fiveDollar = Money::USD(500);
* </code>
*
* @phpstan-param non-empty-string $method
* @phpstan-param array{numeric-string|int} $arguments
* @param array $arguments
* @psalm-param non-empty-string $method
* @psalm-param array{numeric-string|int} $arguments
*
* @throws InvalidArgumentException If amount is not integer(ish).
*
* @phpstan-pure
* @psalm-pure
*/
public static function __callStatic(string $method, array $arguments): Money
{
Expand Down
15 changes: 9 additions & 6 deletions src/Teller.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ final class Teller
{
use TellerFactory;

/**
* @param Money::ROUND_* $roundingMode
*/
public function __construct(
private readonly Currency $currency,
private readonly MoneyParser $parser,
Expand Down Expand Up @@ -101,9 +104,9 @@ public function lessThanOrEqual(mixed $amount, mixed $other): bool
/**
* Adds a series of monetary amounts to each other in sequence.
*
* @param mixed $amount a monetary amount
* @param mixed $other another monetary amount
* @param mixed[] $others subsequent other monetary amounts
* @param mixed $amount a monetary amount
* @param mixed $other another monetary amount
* @param mixed $others subsequent other monetary amounts
*
* @return string the calculated monetary amount
*/
Expand All @@ -120,9 +123,9 @@ public function add(mixed $amount, mixed $other, mixed ...$others): string
/**
* Subtracts a series of monetary amounts from each other in sequence.
*
* @param mixed $amount a monetary amount
* @param mixed $other another monetary amount
* @param mixed[] $others subsequent monetary amounts
* @param mixed $amount a monetary amount
* @param mixed $other another monetary amount
* @param mixed $others subsequent monetary amounts
*/
public function subtract(mixed $amount, mixed $other, mixed ...$others): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/TellerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ trait TellerFactory
* </code>
*
* @param non-empty-string $method
* @param array{0?: int} $arguments
* @param array{0?: Money::ROUND_*} $arguments
*/
public static function __callStatic(string $method, array $arguments): Teller
{
Expand Down
1 change: 1 addition & 0 deletions tests/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ trait Locale
{
public static function runLocaleAware(int $category, string $locale, Closure $callback): void
{
// @phpstan-ignore argument.type (I dont get this error)
$currentLocale = setlocale($category, 0);
try {
setlocale($category, $locale);
Expand Down
2 changes: 1 addition & 1 deletion tests/MoneyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public function itCalculatesAvg(array $values, Money $avg): void
* @phpstan-param int $amount
* @phpstan-param non-negative-int $unit
* @phpstan-param int $expected
* @phpstan-param int $roundingMode
* @phpstan-param Money::ROUND_* $roundingMode
*
* @test
* @dataProvider roundToUnitExamples
Expand Down

0 comments on commit c157108

Please sign in to comment.