Skip to content

Commit

Permalink
Use Psalm annotations for RoundingMode
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 20, 2021
1 parent 13af2d9 commit 3b9875d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/AbstractMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ abstract public function getCurrency() : Currency;
/**
* Converts this money to a Money in the given Context.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param Context $context The context.
* @param int $roundingMode The rounding mode, if necessary.
*
Expand Down
3 changes: 3 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Brick\Math\BigDecimal;
use Brick\Math\BigNumber;
use Brick\Math\Exception\RoundingNecessaryException;
use Brick\Math\RoundingMode;

/**
* Adjusts a rational number to a decimal amount.
Expand All @@ -20,6 +21,8 @@ interface Context
* In case the rounding mode is irrelevant, for example in AutoContext, this method MUST throw an exception if a
* rounding mode other than RoundingMode::UNNECESSARY is used.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param BigNumber $amount The amount.
* @param Currency $currency The target currency.
* @param int $roundingMode The rounding mode.
Expand Down
2 changes: 2 additions & 0 deletions src/CurrencyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public function __construct(ExchangeRateProvider $exchangeRateProvider, ?Context
/**
* Converts the given money to the given currency.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param MoneyContainer $moneyContainer The Money, RationalMoney or MoneyBag to convert.
* @param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
* @param int $roundingMode The rounding mode, if necessary.
Expand Down
16 changes: 16 additions & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public static function total(Money $money, Money ...$monies) : Money
/**
* Creates a Money from a rational amount, a currency, and a context.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param BigNumber $amount The amount.
* @param Currency $currency The currency.
* @param Context $context The context.
Expand All @@ -167,6 +169,8 @@ public static function create(BigNumber $amount, Currency $currency, Context $co
* To override this behaviour, a Context instance can be provided.
* Operations on this Money return a Money with the same context.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param BigNumber|int|float|string $amount The monetary amount.
* @param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
* @param Context|null $context An optional Context.
Expand Down Expand Up @@ -201,6 +205,8 @@ public static function of($amount, $currency, ?Context $context = null, int $rou
* currency's default fraction digits. For example, `Money::ofMinor(1234, 'USD')` will yield `USD 12.34`.
* If the amount cannot be safely converted to this scale, an exception is thrown.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param BigNumber|int|float|string $minorAmount The amount, in minor currency units.
* @param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
* @param Context|null $context An optional Context.
Expand Down Expand Up @@ -322,6 +328,8 @@ public function getContext() : Context
* rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
* thrown.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param AbstractMoney|BigNumber|int|float|string $that The money or amount to add.
* @param int $roundingMode An optional RoundingMode constant.
*
Expand Down Expand Up @@ -358,6 +366,8 @@ public function plus($that, int $roundingMode = RoundingMode::UNNECESSARY) : Mon
* rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
* thrown.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param AbstractMoney|BigNumber|int|float|string $that The money or amount to subtract.
* @param int $roundingMode An optional RoundingMode constant.
*
Expand Down Expand Up @@ -390,6 +400,8 @@ public function minus($that, int $roundingMode = RoundingMode::UNNECESSARY) : Mo
* rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
* thrown.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param BigNumber|int|float|string $that The multiplier.
* @param int $roundingMode An optional RoundingMode constant.
*
Expand All @@ -411,6 +423,8 @@ public function multipliedBy($that, int $roundingMode = RoundingMode::UNNECESSAR
* rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
* thrown.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param BigNumber|int|float|string $that The divisor.
* @param int $roundingMode An optional RoundingMode constant.
*
Expand Down Expand Up @@ -607,6 +621,8 @@ public function negated() : Money
* For example, converting a default money of `USD 1.23` to `EUR` with an exchange rate of `0.91` and
* RoundingMode::UP will yield `EUR 1.12`.
*
* @psalm-param RoundingMode::* $roundingMode
*
* @param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
* @param BigNumber|int|float|string $exchangeRate The exchange rate to multiply by.
* @param Context|null $context An optional context.
Expand Down

0 comments on commit 3b9875d

Please sign in to comment.