<commit_before><?php

declare(strict_types=1);

namespace Money;

use InvalidArgumentException;
use JsonSerializable;
use Money\Calculator\BcMathCalculator;

use function array_fill;
use function array_keys;
use function array_map;
use function array_sum;
use function count;
use function filter_var;
use function floor;
use function is_int;
use function max;
use function str_pad;
use function strlen;
use function substr;

use const FILTER_VALIDATE_INT;
use const PHP_ROUND_HALF_DOWN;
use const PHP_ROUND_HALF_EVEN;
use const PHP_ROUND_HALF_ODD;
use const PHP_ROUND_HALF_UP;

/**
 * Money Value Object.
 *
 * @psalm-immutable
 */
final class Money implements JsonSerializable
{
    use MoneyFactory;

    public const ROUND_HALF_UP = PHP_ROUND_HALF_UP;

    public const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN;

    public const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN;

    public const ROUND_HALF_ODD = PHP_ROUND_HALF_ODD;

    public const ROUND_UP = 5;

    public const ROUND_DOWN = 6;

    public const ROUND_HALF_POSITIVE_INFINITY = 7;

    public const ROUND_HALF_NEGATIVE_INFINITY = 8;

    /**
     * Internal value.
     *
     * @psalm-var numeric-string
     */
    private string $amount;

    private Currency $currency;

    /**
     * @var Calculator
     * @psalm-var class-string<Calculator>
     */
    private static string $calculator = BcMathCalculator::class;

    /**
     * @param int|string $amount Amount, expressed in the smallest units of $currency (eg cents)
     * @psalm-param int|numeric-string $amount
     *
     * @throws InvalidArgumentException If amount is not integer.
     */
    public function __construct(int|string $amount, Currency $currency)
    {
        $this->currency = $currency;

        if (filter_var($amount, FILTER_VALIDATE_INT) === false) {
            $numberFromString = Number::fromString((string) $amount);
            if (! $numberFromString->isInteger()) {
                throw new InvalidArgumentException('Amount must be an integer(ish) value');
            }

            $this->amount = $numberFromString->getIntegerPart();

            return;
        }

        $this->amount = (string) $amount;
    }

    /**
     * Checks whether a Money has the same Currency as this.
     */
    public function isSameCurrency(Money ...$others): bool
    {
        foreach ($others as $other) {<commit_msg>The comment is slightly different from the class 'MoneyFactory'<commit_after><?php

declare(strict_types=1);

namespace Money;

use InvalidArgumentException;
use JsonSerializable;
use Money\Calculator\BcMathCalculator;

use function array_fill;
use function array_keys;
use function array_map;
use function array_sum;
use function count;
use function filter_var;
use function floor;
use function is_int;
use function max;
use function str_pad;
use function strlen;
use function substr;

use const FILTER_VALIDATE_INT;
use const PHP_ROUND_HALF_DOWN;
use const PHP_ROUND_HALF_EVEN;
use const PHP_ROUND_HALF_ODD;
use const PHP_ROUND_HALF_UP;

/**
 * Money Value Object.
 *
 * @psalm-immutable
 */
final class Money implements JsonSerializable
{
    use MoneyFactory;

    public const ROUND_HALF_UP = PHP_ROUND_HALF_UP;

    public const ROUND_HALF_DOWN = PHP_ROUND_HALF_DOWN;

    public const ROUND_HALF_EVEN = PHP_ROUND_HALF_EVEN;

    public const ROUND_HALF_ODD = PHP_ROUND_HALF_ODD;

    public const ROUND_UP = 5;

    public const ROUND_DOWN = 6;

    public const ROUND_HALF_POSITIVE_INFINITY = 7;

    public const ROUND_HALF_NEGATIVE_INFINITY = 8;

    /**
     * Internal value.
     *
     * @psalm-var numeric-string
     */
    private string $amount;

    private Currency $currency;

    /**
     * @var Calculator
     * @psalm-var class-string<Calculator>
     */
    private static string $calculator = BcMathCalculator::class;

    /**
     * @param int|string $amount Amount, expressed in the smallest units of $currency (eg cents)
     * @psalm-param int|numeric-string $amount
     *
     * @throws InvalidArgumentException If amount is not integer(ish).
     */
    public function __construct(int|string $amount, Currency $currency)
    {
        $this->currency = $currency;

        if (filter_var($amount, FILTER_VALIDATE_INT) === false) {
            $numberFromString = Number::fromString((string) $amount);
            if (! $numberFromString->isInteger()) {
                throw new InvalidArgumentException('Amount must be an integer(ish) value');
            }

            $this->amount = $numberFromString->getIntegerPart();

            return;
        }

        $this->amount = (string) $amount;
    }

    /**
     * Checks whether a Money has the same Currency as this.
     */
    public function isSameCurrency(Money ...$others): bool
    {
        foreach ($others as $other) {
{'fraction_non_alphanumeric': 0.08819226750261233, 'fraction_numerical': 0.0020898641588296763, 'mean_word_length': 3.165361183637946, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '2074250', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1453, 'n_words': 400}