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
5 changes: 0 additions & 5 deletions money/extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ services:
tags:
- phpstan.dynamicStaticMethodThrowTypeExtension

-
class: Brick\Money\PHPStan\MoneyFactoryRoundingModeThrowTypeExtension
tags:
- phpstan.dynamicStaticMethodThrowTypeExtension

-
class: Brick\Money\PHPStan\MoneyOperationThrowTypeExtension
tags:
Expand Down
63 changes: 0 additions & 63 deletions money/src/MoneyFactoryRoundingModeThrowTypeExtension.php

This file was deleted.

8 changes: 6 additions & 2 deletions money/src/MoneyFactoryThrowTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getThrowTypeFromStaticMethodCall(

// Money::of()/ofMinor() can still throw RoundingNecessaryException,
// unless the amount cannot require rounding.
if ($className === Money::class && ! $this->isRoundingSafe($amountType, $methodName, $args)) {
if ($className === Money::class && ! $this->isRoundingSafe($amountType, $methodName, $args, $scope)) {
$residualTypes[] = new ObjectType(RoundingNecessaryException::class);
}

Expand All @@ -114,8 +114,12 @@ public function getThrowTypeFromStaticMethodCall(
*
* @param Arg[] $args
*/
private function isRoundingSafe(Type $amountType, string $methodName, array $args): bool
private function isRoundingSafe(Type $amountType, string $methodName, array $args, Scope $scope): bool
{
if (isset($args[3]) && SafeType::isSafeRoundingMode($scope->getType($args[3]->value))) {
return true;
}

if (SafeType::isZero($amountType)) {
return true;
}
Expand Down
18 changes: 18 additions & 0 deletions money/tests/data/MoneyThrowTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,24 @@ public function ofStringWithCustomContext(string $amount): void
}
}

public function ofWithRoundingMode(BigDecimal $amount): void
{
try {
$result = Money::of($amount, 'USD', roundingMode: RoundingMode::HalfUp);
} finally {
assertVariableCertainty(TrinaryLogic::createYes(), $result);
}
}

public function ofMinorWithRoundingMode(BigDecimal $amount): void
{
try {
$result = Money::ofMinor($amount, 'USD', roundingMode: RoundingMode::HalfUp);
} finally {
assertVariableCertainty(TrinaryLogic::createYes(), $result);
}
}

// --- Comparison methods ---

public function compareToWithInt(Money $a): void
Expand Down
Loading