<commit_before><?php

declare(strict_types=1);

namespace Brick\Money;

use Brick\Math\BigRational;

/**
 * Container for monies in different currencies.
 *
 * This class is mutable.
 */
final class MoneyBag implements MoneyContainer
{
    /**
     * The amounts in this bag, indexed by currency code.
     *
     * @var BigRational[]
     */
    private $amounts = [];

    /**
     * Returns the amount in the given currency contained in the bag, as a rational number.
     *
     * @param Currency|string $currency The Currency instance or currency code.
     *
     * @return BigRational
     */
    public function getAmount($currency) : BigRational
    {
        $currencyCode = (string) $currency;

        return isset($this->amounts[$currencyCode])
            ? $this->amounts[$currencyCode]
            : BigRational::zero();
    }

    /**
     * Returns the amounts contained in this bag, as rational numbers, indexed by currency code.
     *
     * @return BigRational[]<commit_msg>Accept an ISO numeric currency code in MoneyBag::getAmount()<commit_after><?php

declare(strict_types=1);

namespace Brick\Money;

use Brick\Math\BigRational;

/**
 * Container for monies in different currencies.
 *
 * This class is mutable.
 */
final class MoneyBag implements MoneyContainer
{
    /**
     * The amounts in this bag, indexed by currency code.
     *
     * @var BigRational[]
     */
    private $amounts = [];

    /**
     * Returns the amount in the given currency contained in the bag, as a rational number.
     *
     * @param Currency|string|int $currency The Currency instance, ISO currency code or ISO numeric currency code.
     *
     * @return BigRational
     */
    public function getAmount($currency) : BigRational
    {
        if (! $currency instanceof Currency) {
            $currency = Currency::of($currency);
        }

        $currencyCode = (string) $currency;

        return isset($this->amounts[$currencyCode])
            ? $this->amounts[$currencyCode]
            : BigRational::zero();
    }

    /**
     * Returns the amounts contained in this bag, as rational numbers, indexed by currency code.
     *
     * @return BigRational[]
{'fraction_non_alphanumeric': 0.10545621274644658, 'fraction_numerical': 0.0009170105456212746, 'mean_word_length': 2.588815789473684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '459932', 'n_tokens_mistral': 614, 'n_tokens_neox': 596, 'n_words': 191}