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
4 changes: 2 additions & 2 deletions src/AbstractMoney.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ final public function getMonies(): array
/**
* Returns the sign of this money.
*
* @return int -1 if the number is negative, 0 if zero, 1 if positive.
* @return -1|0|1 -1 if the number is negative, 0 if zero, 1 if positive.
*/
final public function getSign(): int
{
Expand Down Expand Up @@ -126,7 +126,7 @@ final public function isPositiveOrZero(): bool
/**
* Compares this money to the given amount.
*
* @return int [-1, 0, 1] if `$this` is less than, equal to, or greater than `$that`.
* @return -1|0|1 If `$this` is less than, equal to, or greater than `$that`.
*
* @throws MathException If the argument is an invalid number.
* @throws MoneyMismatchException If the argument is a money in a different currency.
Expand Down
2 changes: 1 addition & 1 deletion src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function applyTo(BigNumber $amount, Currency $currency, RoundingMode $rou
* If no cash rounding is involved, this must return 1.
* This value is used by money allocation methods that do not go through the applyTo() method.
*
* @return int<1, max>
* @return positive-int
*/
public function getStep(): int;

Expand Down
4 changes: 2 additions & 2 deletions src/Context/CashContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
final readonly class CashContext implements Context
{
/**
* @param int<1, max> $step The cash rounding step, in minor units. Must be a multiple of 2 and/or 5.
* For example, step 5 on CHF would allow CHF 0.00, CHF 0.05, CHF 0.10, etc.
* @param positive-int $step The cash rounding step, in minor units. Must be a multiple of 2 and/or 5.
* For example, step 5 on CHF would allow CHF 0.00, CHF 0.05, CHF 0.10, etc.
*/
public function __construct(
private int $step,
Expand Down
6 changes: 4 additions & 2 deletions src/Context/CustomContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
/**
* @param non-negative-int $scale The scale of the monies using this context.
* @param int<1, max> $step An optional cash rounding step. Must either divide 10^scale or be a multiple of 10^scale.
* @param positive-int $step An optional cash rounding step. Must either divide 10^scale or be a multiple of 10^scale.
* For example, scale=2 and step=5 allows 0.00, 0.05, 0.10, etc.
* And scale=2 and step=1000 allows 0.00, 10.00, 20.00, etc.
*/
Expand Down Expand Up @@ -68,6 +68,8 @@ public function isFixedScale(): bool

/**
* Returns the scale used by this context.
*
* @return non-negative-int
*/
public function getScale(): int
{
Expand All @@ -76,7 +78,7 @@ public function getScale(): int

/**
* @param non-negative-int $scale
* @param int<1, max> $step
* @param positive-int $step
*/
private function isValidStepForScale(int $scale, int $step): bool
{
Expand Down
4 changes: 3 additions & 1 deletion src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* uppercase ISO 4217 currency code. For non-ISO currencies no
* constraints are defined, but the code must be unique across an
* application and must not conflict with ISO currency codes.
* @param int $numericCode The numeric currency code. For ISO currencies this will be the
* @param non-negative-int $numericCode The numeric currency code. For ISO currencies this will be the
* ISO 4217 numeric currency code, without leading zeros. For non-ISO
* currencies no constraints are defined, but the code must be unique
* across an application and must not conflict with ISO currency codes.
Expand Down Expand Up @@ -109,6 +109,8 @@ public function getCurrencyCode(): string
*
* For ISO currencies this will be the ISO 4217 numeric currency code, without leading zeros.
* For non ISO currencies no constraints are defined.
*
* @return non-negative-int
*/
public function getNumericCode(): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/IsoCurrencyProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class IsoCurrencyProvider
/**
* The raw currency data, indexed by currency code.
*
* @var array<string, array{string, int, string, non-negative-int, CurrencyType}>
* @var array<string, array{string, non-negative-int, string, non-negative-int, CurrencyType}>
*/
private readonly array $currencyData;

Expand Down
12 changes: 8 additions & 4 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ public function quotientAndRemainder(BigNumber|int|string $that): array
*
* The resulting monies have the same context as this Money.
*
* @param int[] $ratios The ratios.
* @param non-negative-int[] $ratios The ratios.
*
* @return Money[]
*
Expand All @@ -524,6 +524,7 @@ public function allocate(int ...$ratios): array
}

foreach ($ratios as $ratio) {
/** @psalm-suppress DocblockTypeContradiction */
if ($ratio < 0) {
throw new InvalidArgumentException('Cannot allocate() negative ratios.');
}
Expand Down Expand Up @@ -576,7 +577,7 @@ public function allocate(int ...$ratios): array
*
* The resulting monies have the same context as this Money.
*
* @param int[] $ratios The ratios.
* @param non-negative-int[] $ratios The ratios.
*
* @return Money[]
*
Expand All @@ -589,6 +590,7 @@ public function allocateWithRemainder(int ...$ratios): array
}

foreach ($ratios as $ratio) {
/** @psalm-suppress DocblockTypeContradiction */
if ($ratio < 0) {
throw new InvalidArgumentException('Cannot allocateWithRemainder() negative ratios.');
}
Expand Down Expand Up @@ -628,14 +630,15 @@ public function allocateWithRemainder(int ...$ratios): array
*
* The resulting monies have the same context as this Money.
*
* @param int $parts The number of parts.
* @param positive-int $parts The number of parts.
*
* @return Money[]
*
* @throws InvalidArgumentException If called with invalid parameters.
*/
public function split(int $parts): array
{
/** @psalm-suppress DocblockTypeContradiction */
if ($parts < 1) {
throw new InvalidArgumentException('Cannot split() into less than 1 part.');
}
Expand All @@ -651,14 +654,15 @@ public function split(int $parts): array
*
* The resulting monies have the same context as this Money.
*
* @param int $parts The number of parts.
* @param positive-int $parts The number of parts.
*
* @return Money[]
*
* @throws InvalidArgumentException If called with invalid parameters.
*/
public function splitWithRemainder(int $parts): array
{
/** @psalm-suppress DocblockTypeContradiction */
if ($parts < 1) {
throw new InvalidArgumentException('Cannot splitWithRemainder() into less than 1 part.');
}
Expand Down
2 changes: 1 addition & 1 deletion src/MoneyComparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
* This order is important if the exchange rate provider uses different exchange rates
* when converting back and forth two currencies.
*
* @return int -1, 0 or 1.
* @return -1|0|1
*
* @throws CurrencyConversionException If the exchange rate is not available.
*/
Expand Down