Repository: symfony/symfony
File: src/Symfony/Component/Translation/Bridge/Lokalise/LokaliseProvider.php (PHP)

Code before:
                $zip->close();
            }

            $fileContents = $this->getFileContents($extractPath);

            // Lokalise returns languages with "-" separator, we need to reformat them to "_" separator.
            /** @var array<array-key, array-key> $reformattedLanguages */
            $reformattedLanguages = array_map(static fn ($language) => str_replace('-', '_', $language), array_keys($fileContents));

            return array_combine($reformattedLanguages, $fileContents);
        } finally {
            unlink($newfile);
            $this->removeDir($extractPath);
        }
    }

    private function getFileContents(string $dir, string $baseDir = ''): array
    {
        $fileContents = [];
        foreach (scandir($dir) as $filename) {
            if (\in_array($filename, ['.', '..'])) {
                continue;
            }
            $path = \sprintf('%s%s%s', $dir, \DIRECTORY_SEPARATOR, $filename);
            if (is_dir($path)) {
                $fileContents = array_merge($fileContents, $this->getFileContents($path, $filename));
                continue;
            }
            $fileContents[$baseDir][$filename]['content'] = file_get_contents($path);
        }

        return $fileContents;
    }

    private function removeDir(string $dir): void
    {
        $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($files as $file) {
            if ($file->isDir()) {
                rmdir($file->getPathname());
            } else {
                unlink($file->getPathname());
            }
        }
        rmdir($dir);
    }

    private function createKeys(array $keys, string $domain): array
    {
        $keysToCreate = [];

Review comment (suggestion):
Let's change the implementation of the method and let's not pretend this can handle arbitrary recursive unzipped content
we can do a two levels read of the dir: level 1 = languages, str_replace included, level 2 = content


Code after:
            }

            return $this->getZipContents($extractPath);
        } finally {
            if (is_resource($h)) {
                fclose($h);
            }
            @unlink($zipFile);
            $this->removeDir($extractPath);
        }
    }

    private function getZipContents(string $dir): array
    {
        $contents = [];
        foreach (scandir($dir) as $lang) {
            if (\in_array($lang, ['.', '..'], true)) {
                continue;
            }
            $path = $dir.'/'.$lang;
            // Lokalise returns languages with "-" separator, we need to reformat them to "_" separator.
            $lang = str_replace('-', '_', $lang);
            foreach (scandir($path) as $name) {
                if (!\in_array($name, ['.', '..'], true)) {
                    $contents[$lang][$name]['content'] = file_get_contents($path.'/'.$name);
                }
            }
        }

        return $contents;
    }

    private function removeDir(string $dir): void
    {
        if (!is_dir($dir)) {
            return;
        }
        $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($files as $file) {
            if ($file->isDir()) {
                rmdir($file->getPathname());
            } else {
                unlink($file->getPathname());
            }
        }
        rmdir($dir);
    }

    private function createKeys(array $keys, string $domain): array
    {