src/Money.php
public function plus($that, int $roundingMode = RoundingMode::UNNECESSARY) : Money
    {
        $amount = $this->getAmountOf($that);

        if ($that instanceof Money) {
            $this->checkContext($that->getContext(), __FUNCTION__);

            if ($this->context->isFixedScale()) {
                return new Money($this->amount->plus($that->amount), $this->currency, $this->context);
            }
        }

        $amount = $this->amount->toBigRational()->plus($amount);

        return self::create($amount, $this->currency, $this->context, $roundingMode);
    }
public function plus($that, int $roundingMode = RoundingMode::UNNECESSARY) : Money
    {
        $amount = $this->getAmountOf($that);

        if ($that instanceof Money) {
            $this->checkContext($that->getContext(), __FUNCTION__);

            if ($this->context->isFixedScale()) {
                return new Money($this->amount->plus($that->amount), $this->currency, $this->context);
            }
        }

        $amount = $this->amount->toBigRational()->plus($amount);

        return self::create($amount, $this->currency, $this->context, $roundingMode);
    }
public function plus ( $ that , int $ roundingMode = RoundingMode :: UNNECESSARY ) : Money { $ amount = $ this -> getAmountOf ( $ that ) ; if ( $ that instanceof Money ) { $ this -> checkContext ( $ that -> getContext ( ) , __FUNCTION__ ) ; if ( $ this -> context -> isFixedScale ( ) ) { return new Money ( $ this -> amount -> plus ( $ that -> amount ) , $ this -> currency , $ this -> context ) ; } } $ amount = $ this -> amount -> toBigRational ( ) -> plus ( $ amount ) ; return self :: create ( $ amount , $ this -> currency , $ this -> context , $ roundingMode ) ; }
Returns the sum of this Money and the given amount.

If the operand is a Money, it must have the same context as this Money, or an exception is thrown.
This is by design, to ensure that contexts are not mixed accidentally.
If you do need to add a Money in a different context, you can use `plus($money->toRational())`.

The resulting Money has the same context as this Money. If the result needs rounding to fit this context, a
rounding mode can be provided. If a rounding mode is not provided and rounding is necessary, an exception is
thrown.

@param AbstractMoney|BigNumber|number|string $that         The money or amount to add.
@param int                                   $roundingMode An optional RoundingMode constant.

@return Money

@throws MathException          If the argument is an invalid number or rounding is necessary.
@throws MoneyMismatchException If the argument is a money in a different currency or in a different context.
Returns the sum of this Money and the given amount .