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

Code before:

    /**
     * @throws MissingResourceException if the currency code has no numeric code
     */
    public static function getNumericCode(string $currency): int
    {
        return self::readEntry(['Alpha3ToNumeric', $currency], 'meta');
    }

    /**
     * @throws MissingResourceException if the numeric code does not exist
     */
    public static function forNumericCode(int $numericCode): array
    {
        return self::readEntry(['NumericToAlpha3', (string) $numericCode], 'meta');
    }

    /**
     * @param non-empty-string $country e.g. 'FR'
     * @param ?bool $legalTender if the currency must be a legal tender. Using null do not filter anything
     * @param bool $activeOnly exclude currencies that are not active on the given $date in countries
     * @param string $date The date string on which the check will be performed
     *
     * @throws MissingResourceException if the given $country does not exist
     *
     * @return array<non-empty-string, array{from?: non-empty-string, to?: non-empty-string, tender?: bool}>
     */
    public static function forCountry(
        string $country,
        ?bool $legalTender = true,
        bool $activeOnly = true,
        string $date = 'today',
    ): array {
        $currenciesMetadata = self::readEntry(['Map', $country], 'meta');

        $currencies = [];

        foreach ($currenciesMetadata as $currency => $currencyMetadata) {
            if (null !== $legalTender && $legalTender !== self::isLegalTender($currencyMetadata)) {
                continue;
            }

            if (!$activeOnly) {
                $currencies[$currency] = $currencyMetadata;

                continue;
            }

            if (!self::isActive($country, $currency, $currencyMetadata, $date)) {
                continue;
            }

Review comment (suggestion):
im not sure this is the proper return type compared to `getCurrencyCodes` and `forNumeric`, unexpected at least i think

Code after:

    /**
     * @throws MissingResourceException if the currency code has no numeric code
     */
    public static function getNumericCode(string $currency): int
    {
        return self::readEntry(['Alpha3ToNumeric', $currency], 'meta');
    }

    /**
     * @throws MissingResourceException if the numeric code does not exist
     */
    public static function forNumericCode(int $numericCode): array
    {
        return self::readEntry(['NumericToAlpha3', (string) $numericCode], 'meta');
    }

    /**
     * @param string             $country     e.g. 'FR'
     * @param ?bool              $legalTender If the currency must be a legal tender; null to not filter anything
     * @param ?bool              $active      Indicates whether the currency should always be active for the given $date; null to not filter anything
     * @param \DateTimeInterface $date        The date on which the check will be performed
     *
     * @return list<string> a list of unique currencies
     *
     * @throws MissingResourceException if the given $country does not exist
     */
    public static function forCountry(string $country, ?bool $legalTender = true, ?bool $active = true, \DateTimeInterface $date = new \DateTimeImmutable('today', new \DateTimeZone('Etc/UTC'))): array
    {
        $currencies = [];

        foreach (self::readEntry(['Map', $country], 'meta') as $currency => $currencyMetadata) {
            if (null !== $legalTender && $legalTender !== self::isLegalTender($currencyMetadata)) {
                continue;
            }

            if (null === $active) {
                $currencies[] = $currency;

                continue;
            }

            if (self::isDateActive($country, $currency, $currencyMetadata, $date) !== $active) {
                continue;
            }

            $currencies[] = $currency;
        }

        return $currencies;
    }