src/Domain/Value/Money/Money.php
public function split(int $num): array
    {
        if ($num <= 0) {
            $message = sprintf('%s expects $num to be greater than zero', __METHOD__);
            throw new DomainException($message);
        }

        $amount = $this->castToInteger($this->amount / $num);
        $remainder = $this->amount % $num;
        $shares = [];

        for ($i = 0; $i < $num; $i++) {
            $shares[] = $this->withAmount($amount);
        }

        for ($i = 0; $i < $remainder; $i++) {
            $shares[$i] = $this->withAmount($shares[$i]->amount + 1);
        }

        return $shares;
    }
public function split(int $num): array
    {
        if ($num <= 0) {
            $message = sprintf('%s expects $num to be greater than zero', __METHOD__);
            throw new DomainException($message);
        }

        $amount = $this->castToInteger($this->amount / $num);
        $remainder = $this->amount % $num;
        $shares = [];

        for ($i = 0; $i < $num; $i++) {
            $shares[] = $this->withAmount($amount);
        }

        for ($i = 0; $i < $remainder; $i++) {
            $shares[$i] = $this->withAmount($shares[$i]->amount + 1);
        }

        return $shares;
    }
public function split ( int $ num ) : array { if ( $ num <= 0 ) { $ message = sprintf ( '%s expects $num to be greater than zero' , __METHOD__ ) ; throw new DomainException ( $ message ) ; } $ amount = $ this -> castToInteger ( $ this -> amount / $ num ) ; $ remainder = $ this -> amount % $ num ; $ shares = [ ] ; for ( $ i = 0 ; $ i < $ num ; $ i ++ ) { $ shares [ ] = $ this -> withAmount ( $ amount ) ; } for ( $ i = 0 ; $ i < $ remainder ; $ i ++ ) { $ shares [ $ i ] = $ this -> withAmount ( $ shares [ $ i ] -> amount + 1 ) ; } return $ shares ; }
Allocates the money among a given number of targets

@param int $num The number of targets

@return Money[]

@throws DomainException When num is not greater than zero
Allocates the money among a given number of targets