Repository: symfony/symfony
File: src/Symfony/Component/Intl/Data/Generator/CurrencyDataGenerator.php (PHP)

Code before:
     */
    private function generateCurrencyMap(mixed $supplementalDataBundle): array
    {
        /**
         * @var list<non-empty-string, list<non-empty-string, array{
         *       from?: non-empty-string,
         *       to?: non-empty-string,
         *       tender?: false
         *      }>>  $regionsData
         */
        $regionsData = [];

        /**
         * The key is the country iso3166 identifier (e.g. "CH").
         *
         * @var array<non-empty-string, \ResourceBundle> $regions
         */
        $regions = iterator_to_array($supplementalDataBundle['CurrencyMap']);

        foreach ($regions as $regionId => $region) {
            /**
             * @var list<\ResourceBundle> $currencies
             */
            $currencies = iterator_to_array($region);

            foreach ($currencies as $metadata) {
                /**
                 * Note 1: The "to" property (if present) is always greater than "from".
                 * Note 2: The "to" property may be missing if the currency is still in use.
                 * Note 3: The "tender" property indicates whether the country legally recognizes the currency within
                 *         its borders. This property is explicitly set to `false` only if that is not the case;
                 *         otherwise, it is `true` by default.
                 * Note 4: The "from" and "to" dates are not stored as strings; they are stored as a pair of integers.
                 * Note 5: The "to" property may be missing if "tender" is set to `false`.
                 *
                 * @var array{
                 *        from?: array{0: int, 1: int},
                 *        to?: array{0: int, 2: int},
                 *        tender?: bool,
                 *        id: non-empty-string
                 *      } $metadata
                 */
                $metadata = iterator_to_array($metadata);

                $id = $metadata['id'];

                unset($metadata['id']);

                if (\array_key_exists($id, self::DENYLIST)) {
                    continue;
                }

Review comment (suggestion):
```suggestion
            foreach (iterator_to_array($region) as $metadata) {
```

Code after:
                        throw new \RuntimeException('Unexpected boolean value for tender attribute.');
                    }
                }

                $regionsData[$regionId][$id] = $metadata;
            }

            // Do not exclude countries with no currencies or excluded currencies (e.g. Antartica)
            $regionsData[$regionId] ??= [];
        }

        return $regionsData;
    }

    private function generateAlpha3ToNumericMapping(ArrayAccessibleResourceBundle $numericCodesBundle, array $currencyCodes): array
    {
        $alpha3ToNumericMapping = iterator_to_array($numericCodesBundle['codeMap']);

        asort($alpha3ToNumericMapping);

        // Filter unknown currencies (e.g. "AYM")
        return array_intersect_key($alpha3ToNumericMapping, array_flip($currencyCodes));
    }

    private function generateNumericToAlpha3Mapping(array $alpha3ToNumericMapping): array
    {
        $numericToAlpha3Mapping = [];

        foreach ($alpha3ToNumericMapping as $alpha3 => $numeric) {
            // Make sure that the mapping is stored as table and not as array
            $numeric = (string) $numeric;

            if (!isset($numericToAlpha3Mapping[$numeric])) {
                $numericToAlpha3Mapping[$numeric] = [];
            }

            $numericToAlpha3Mapping[$numeric][] = $alpha3;
        }

        return $numericToAlpha3Mapping;
    }

    /**
     * Decodes ICU "date pair" into a DateTimeImmutable (UTC).
     *
     * ICU stores UDate = milliseconds since 1970-01-01T00:00:00Z in a signed 64-bit.
     *
     * @param array{0: int, 1: int} $pair
     */
    private static function icuPairToDate(array $pair): string
    {