Allocates the money according to a list of ratios

@param array $ratios The list of ratios

@return Money[]
485482
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;
    }
1168793
private function getSubAggregations($rawValue)
    {
        $subAggregations = [];

        foreach ($rawValue as $key => $value) {
            if (is_array($value)) {
                while (is_array($value) && isset($value[$key]) && is_array($value[$key])) {
                    $value = $value[$key];
                }

                if (isset($value['buckets'])) {
                    $subAggregations[$key] = $value;
                }
            }
        }

        return $this->create($subAggregations);
    }
908524
public static function flatten(array $values)
    {
        $results = [];

        array_walk_recursive(
            $values,
            function($value) use (&$results) {
                $results[] = $value;
            }
        );

        return $results;
    }
266018
public static function add(array ...$arrays): array
    {
        self::checkArrayLengths($arrays);

        $number_of_arrays = count($arrays);
        $length_of_arrays = count($arrays[0]);
        $sums             = array_fill(0, $length_of_arrays, 0);

        for ($i = 0; $i < $length_of_arrays; $i++) {
            for ($j = 0; $j < $number_of_arrays; $j++) {
                $sums[$i] += $arrays[$j][$i];
            }
        }

        return $sums;
    }
709242
public function all($params = array())
    {
        $arr = array(
            "currency" => $params["currency"]
        );
        $rawResponse = $this->client->request('get', 'api/deposit_money', $arr);
        return $rawResponse;
    }
491430
public function toArray()
    {
        return [
            'balance' => $this->balance,
            'connection' => $this->connection,
            'queue' => $this->queue,
            'delay' => $this->delay,
            'force' => $this->force,
            'maxProcesses' => $this->maxProcesses,
            'minProcesses' => $this->minProcesses,
            'maxTries' => $this->maxTries,
            'memory' => $this->memory,
            'nice' => $this->nice,
            'name' => $this->name,
            'sleep' => $this->sleep,
            'timeout' => $this->timeout,
        ];
    }
1094402
public function withSizes(array $sizes)
    {
        $res = clone $this;

        $res->sizes = $res->fillArrayInput($sizes);

        return $res;
    }
1032827
public function allocateIdsToEntities(array $entities)
    {
        $this->validateBatch($entities, EntityInterface::class);

        $incompleteKeys = [];
        foreach ($entities as $entity) {
            if ($entity->key()->state() === Key::STATE_INCOMPLETE) {
                $incompleteKeys[] = $entity->key();
            }
        }

        if (!empty($incompleteKeys)) {
            $keys = $this->allocateIds($incompleteKeys);
        }

        return $entities;
    }
140271
public function getAccounts()
    {
        $accounts = [];
        $groups   = $this->rpc->query("listAccounts", [0]);
        foreach($groups as $account => $balance) {
            $accounts[] = $account;
        }
        
        return $accounts;
    }
1033590
private function prepareRatios(Collection $categories)
    {
        $ratios = $categories->filter(function (Category $category) {
                return $category->hasPosts();
            })
            ->transform(function (Category $category) {
                return [
                    'label' => $category->name,
                    'posts' => $category->posts->count(),
                ];
            })
            ->sortByDesc('posts');

        $chunk  = $ratios->splice(5);
        $ratios = $this->colorizeRatios($ratios);

        return $chunk->isEmpty() ? $ratios : $ratios->push([
            'label' => 'Other Categories',
            'posts' => $chunk->sum('posts'),
            'color' => '#D2D6DE',
        ]);
    }
100012
public static function medMad(array $values) : array
    {
        $median = self::median($values);

        return [$median, self::mad($values, $median)];
    }
1269963
public function loadRatioList($force = false)
    {
        if (($force === false) && (count($this->ratioList) > 0)) {
            return $this->ratioList;
        }

        // if filename doesn't exist, init with only reference currency code
        if (!is_file($this->ratioFileName)) {
            $this->ratioList = array($this->referenceCurrencyCode => (float) 1);
            $this->saveRatioList($this->ratioList);

            return $this->ratioList;
        }
        // read ratio file
        if (($handle = fopen($this->ratioFileName, 'r')) === false) {
            throw new MoneyException('ratioFileName '.$this->ratioFileName.' is not initialized');
        }
        $row = 1;
        $this->ratioList = array();
        while (($data = fgetcsv($handle, 1000, ';')) !== false) {
            // extract data from CSV line
            if (count($data) != 2) {
                throw new MoneyException('error in ratioFileName '.$this->ratioFileName.' on line '.$row.', invalid argument count');
            }
            list($currencyCode, $ratio) = $data;


            // validate that currency exist in currency code list
            try {
                // hack to throw an exception if currency doesn't exist
                new Currency($currencyCode);
            } catch (UnknownCurrencyException $e) {
                throw new MoneyException('error in ratioFileName '.$this->ratioFileName.' on line '.$row.', unknown currency '.$currencyCode);
            }

            // validate value
            $ratio = floatval($ratio);
            if (!$ratio) {
                throw new MoneyException('error in ratioFileName '.$this->ratioFileName.' on line '.$row.', ratio is not a float or is null');
            }
            if ($ratio <= 0) {
                throw new MoneyException('error in ratioFileName '.$this->ratioFileName.' on line '.$row.', ratio has to be positive');
            }

            // validate if currency is twice in the file
            if (array_key_exists($currencyCode, $this->ratioList)) {
                throw new MoneyException('error in ratioFileName '.$this->ratioFileName.' on line '.$row.', ratio already exists for currency '.$currencyCode);
            }

            $this->ratioList[$currencyCode] = $ratio;
            $row++;
        }
        fclose($handle);

        return $this->ratioList;
    }
1152071
public function make(array $attributes = [])
    {
        if ($this->amount === null) {
            return $this->makeInstance($attributes);
        }

        if ($this->amount < 1) {
            return (new $this->class)->newCollection();
        }

        return (new $this->class)->newCollection(array_map(function () use ($attributes) {
            return $this->makeInstance($attributes);
        }, range(1, $this->amount)));
    }
22764
public function create( array $attributes = [] )
	{
		$results = $this->make( $attributes );

		if ( $this->amount === 1 )
			$results->save();
		else
			foreach ( $results as $result )
				$result->save();

		return $results;
	}
583796
public static function multiToAssoc(array $arrays)
    {
        $results = [];
        foreach ($arrays as $key => $value) {
            if (self::isReallyArray($value) === true) {
                $results = array_merge($results, self::multiToAssoc($value));
            } else {
                $results[$key] = $value;
            }
        }

        return $results;
    }
971121
public function getMultiple(string ...$keys): array
    {
        $ret = [];
        foreach ($keys as $key) {
            $ret[] = $this->get($key);
        }
        return $ret;
    }
253165
public function dividedBy($that) : RationalMoney
    {
        $amount = $this->amount->dividedBy($that);

        return new self($amount, $this->currency);
    }