public static function getFile()

in app/classes/ReleaseInsights/Utils.php [170:208]


    public static function getFile(string $url): string|bool
    {
        // Local file
        if (! isset(parse_url($url)['scheme'])) {
            // Does it exist ?
            if (! file_exists($url)) {
                return '';
            }

            return file_get_contents($url);
        }

        // We don't want to make external requests in Unit Tests
        // @codeCoverageIgnoreStart
        $client = new Client([
            'headers' => [
                'User-Agent' => 'WhatTrainIsItNow/1.0',
                'Referer'    => 'https://whattrainisitnow.com'
            ]
        ]);

        // We know that some queries fail for hg.mozilla.org but we deal with that in templates
        // We ignore warnings for 404 errors as we don't want to spam Sentry
        $response = $client->request('GET', $url, ['http_errors' => false]);

        // Request to Product-details failed (no answer from remote)
        // We prefer to die here because this data is essential to the whole app.
        if ($response->getStatusCode() != 200 && str_contains($url, 'product-details.mozilla.org')) {
            die("Key external resource {$url} currently not available, please try reloading the page.");
        }

        // Request failed, let's return an empty string for now
        if ($response->getStatusCode() != 200) {
            return '';
        }

        return $response->getBody()->getContents();
        // @codeCoverageIgnoreEnd
    }