Repository: symfony/symfony
File: src/Symfony/Component/Intl/Currencies.php (PHP)

Code before:
     * @param non-empty-string   $currency e.g. 'USD'
     * @param ?bool              $active   Indicates whether the currency should always be active for the given $date. Using null do not filter anything
     * @param \DateTimeInterface $date     The date that will be checked when $active is set to true
     */
    public static function isValidInCountry(
        string $country,
        string $currency,
        ?bool $legalTender = true,
        ?bool $active = true,
        \DateTimeInterface $date = new \DateTimeImmutable('today', new \DateTimeZone('Etc/UTC')),
    ): bool {
        try {
            $currencyMetadata = self::readEntry(['Map', $country, $currency], 'meta');
        } catch (MissingResourceException) {
            return false;
        }

        if (null !== $legalTender && $legalTender !== self::isLegalTender($currencyMetadata)) {
            return false;
        }

        if (null === $active) {
            return true;
        }

        return $active === self::isActive($country, $currency, $currencyMetadata, $date);
    }

    /**
     * @param array{tender?: bool} $currencyMetadata When the `tender` property does not exist, it means it is a legal tender
     */
    private static function isLegalTender(array $currencyMetadata): bool
    {
        return !\array_key_exists('tender', $currencyMetadata) || false !== $currencyMetadata['tender'];
    }

    /**
     * @param non-empty-string                                      $country          e.g. 'FR'
     * @param non-empty-string                                      $currency         e.g. 'USD'
     * @param array{from?: non-empty-string, to?: non-empty-string} $currencyMetadata
     * @param \DateTimeInterface                                    $date             The date on which the check will be performed
     */
    private static function isActive(
        string $country,
        string $currency,
        array $currencyMetadata,
        \DateTimeInterface $date = new \DateTimeImmutable('today', new \DateTimeZone('Etc/UTC')),
    ): bool {
        if (!\array_key_exists('from', $currencyMetadata)) {
            // Note: currencies that are not legal tender don't have often validity dates.
            throw new \RuntimeException("Cannot check whether the currency $currency is active or not in $country because they are no validity dates available.");

Review comment (suggestion):
```suggestion
        return self::isActive($country, $currency, $currencyMetadata, $date) === $active;
```

Code after:
     */
    public static function isValidInCountry(string $country, string $currency, ?bool $legalTender = true, ?bool $active = true, \DateTimeInterface $date = new \DateTimeImmutable('today', new \DateTimeZone('Etc/UTC'))): bool
    {
        if (!self::exists($currency)) {
            throw new \InvalidArgumentException("The currency $currency does not exist.");
        }

        try {
            $currencyMetadata = self::readEntry(['Map', $country, $currency], 'meta');
        } catch (MissingResourceException) {
            return false;
        }

        if (null !== $legalTender && $legalTender !== self::isLegalTender($currencyMetadata)) {
            return false;
        }

        if (null === $active) {
            return true;
        }

        return self::isDateActive($country, $currency, $currencyMetadata, $date) === $active;
    }

    /**
     * @param array{tender?: bool} $currencyMetadata When the `tender` property does not exist, it means it is a legal tender
     */
    private static function isLegalTender(array $currencyMetadata): bool
    {
        return !\array_key_exists('tender', $currencyMetadata) || false !== $currencyMetadata['tender'];
    }

    /**
     * @param string                            $country          e.g. 'FR'
     * @param string                            $currency         e.g. 'USD'
     * @param array{from?: string, to?: string} $currencyMetadata
     * @param \DateTimeInterface                $date             The date on which the check will be performed
     */
    private static function isDateActive(string $country, string $currency, array $currencyMetadata, \DateTimeInterface $date): bool
    {
        if (!\array_key_exists('from', $currencyMetadata)) {
            // Note: currencies that are not legal tender don't have often validity dates.
            throw new \RuntimeException("Cannot check whether the currency $currency is active or not in $country because they are no validity dates available.");
        }

        $from = \DateTimeImmutable::createFromFormat('Y-m-d', $currencyMetadata['from']);

        if (\array_key_exists('to', $currencyMetadata)) {
            $to = \DateTimeImmutable::createFromFormat('Y-m-d', $currencyMetadata['to']);
        } else {
            $to = null;