src/Domain/Value/Money/Money.php
public function allocate(array $ratios): array
    {
        $total = array_sum($ratios);
        $remainder = $this->amount;
        $shares = [];

        foreach ($ratios as $ratio) {
            $amount = $this->castToInteger($this->amount * $ratio / $total);
            $shares[] = $this->withAmount($amount);
            $remainder -= $amount;
        }

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

        return $shares;
    }
public function allocate(array $ratios): array
    {
        $total = array_sum($ratios);
        $remainder = $this->amount;
        $shares = [];

        foreach ($ratios as $ratio) {
            $amount = $this->castToInteger($this->amount * $ratio / $total);
            $shares[] = $this->withAmount($amount);
            $remainder -= $amount;
        }

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

        return $shares;
    }
public function allocate ( array $ ratios ) : array { $ total = array_sum ( $ ratios ) ; $ remainder = $ this -> amount ; $ shares = [ ] ; foreach ( $ ratios as $ ratio ) { $ amount = $ this -> castToInteger ( $ this -> amount * $ ratio / $ total ) ; $ shares [ ] = $ this -> withAmount ( $ amount ) ; $ remainder -= $ amount ; } for ( $ i = 0 ; $ i < $ remainder ; $ i ++ ) { $ shares [ $ i ] = $ this -> withAmount ( $ shares [ $ i ] -> amount + 1 ) ; } return $ shares ; }
Allocates the money according to a list of ratios

@param array $ratios The list of ratios

@return Money[]
Allocates the money according to a list of ratios