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

Code before:
    /**
     * @see https://app.lokalise.com/api2docs/curl/#transition-download-files-post
     */
    private function exportFiles(array $locales, array $domains): array
    {
        $response = $this->client->request('POST', 'files/export', [
            'json' => [
                'format' => 'symfony_xliff',
                'original_filenames' => true,
                'filter_langs' => array_values($locales),
                'filter_filenames' => array_map($this->getLokaliseFilenameFromDomain(...), $domains),
                'export_empty_as' => 'skip',
                'replace_breaks' => false,
            ],
        ]);

        $responseContent = $response->toArray(false);

        if (406 === $response->getStatusCode()
            && 'No keys found with specified filenames.' === $responseContent['error']['message']
        ) {
            return [];
        }

        if (200 !== $response->getStatusCode()) {
            if (($errorCode = $responseContent['error']['code'] ?? null) && self::PROJECT_TOO_BIG_STATUS_CODE === $errorCode) {
                if (!\extension_loaded('zip')) {
                    throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s". There are too many translations. You need to enable the "zip" extension to use asynchronous export.', $response->getContent(false)), $response);
                }

                return $this->exportFilesAsync($locales, $domains);
            }
            throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
        }

        // Lokalise returns languages with "-" separator, we need to reformat them to "_" separator.
        $reformattedLanguages = array_map(function ($language) {
            return str_replace('-', '_', $language);
        }, array_keys($responseContent['files']));

        return array_combine($reformattedLanguages, $responseContent['files']);
    }

    /**
     * @see https://developers.lokalise.com/reference/download-files-async
     */
    private function exportFilesAsync(array $locales, array $domains): array
    {
        $response = $this->client->request('POST', 'files/async-download', [
            'json' => [
                'format' => 'symfony_xliff',

Review comment (suggestion):
```suggestion
            if (self::PROJECT_TOO_BIG_STATUS_CODE !== ($responseContent['error']['code'] ?? null)) {
                throw ...
```

Code after:
     * @see https://app.lokalise.com/api2docs/curl/#transition-download-files-post
     */
    private function exportFiles(array $locales, array $domains): array
    {
        $response = $this->client->request('POST', 'files/export', [
            'json' => [
                'format' => 'symfony_xliff',
                'original_filenames' => true,
                'filter_langs' => array_values($locales),
                'filter_filenames' => array_map($this->getLokaliseFilenameFromDomain(...), $domains),
                'export_empty_as' => 'skip',
                'replace_breaks' => false,
            ],
        ]);

        $responseContent = $response->toArray(false);

        if (406 === $response->getStatusCode()
            && 'No keys found with specified filenames.' === $responseContent['error']['message']
        ) {
            return [];
        }

        if (200 !== $response->getStatusCode()) {
            if (self::PROJECT_TOO_BIG_STATUS_CODE !== ($responseContent['error']['code'] ?? null)) {
                throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s".', $response->getContent(false)), $response);
            }
            if (!\extension_loaded('zip')) {
                throw new ProviderException(\sprintf('Unable to export translations from Lokalise: "%s". Make sure that the "zip" extension is enabled.', $response->getContent(false)), $response);
            }

            return $this->exportFilesAsync($locales, $domains);
        }

        // Lokalise returns languages with "-" separator, we need to reformat them to "_" separator.
        $reformattedLanguages = array_map(function ($language) {
            return str_replace('-', '_', $language);
        }, array_keys($responseContent['files']));

        return array_combine($reformattedLanguages, $responseContent['files']);
    }

    /**
     * @see https://developers.lokalise.com/reference/download-files-async
     */
    private function exportFilesAsync(array $locales, array $domains): array
    {
        $response = $this->client->request('POST', 'files/async-download', [
            'json' => [
                'format' => 'symfony_xliff',
                'original_filenames' => true,