• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orchestral / dusk-updater-api / 13359930187

16 Feb 2025 11:41PM UTC coverage: 78.261%. Remained the same
13359930187

push

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

0 of 2 new or added lines in 1 file covered. (0.0%)

72 of 92 relevant lines covered (78.26%)

4.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/src/HttpClient.php
1
<?php
2

3
namespace Orchestra\DuskUpdaterApi;
4

5
use Exception;
6
use GuzzleHttp\Client;
7
use GuzzleHttp\Psr7\Utils;
8

9
class HttpClient
10
{
11
    /**
12
     * HTTP Client implementation.
13
     *
14
     * @var \GuzzleHttp\Client|null
15
     */
16
    public static $instance;
17

18
    /**
19
     * HTTP Proxy configuration.
20
     */
21
    public static ?string $proxy = null;
22

23
    /**
24
     * SSL Verification configuration.
25
     */
26
    public static bool $verifySsl = true;
27

28
    /**
29
     * Download from URL.
30
     *
31
     * @throws \Exception
32
     */
33
    public static function download(string $url, string $destination): void
34
    {
35
        $client = static::$instance ?? new Client;
×
36

37
        $resource = Utils::tryFopen($destination, 'w');
×
38

39
        $response = $client->get($url, array_merge([
×
40
            'sink' => $resource,
×
41
            'verify' => static::$verifySsl,
×
42
        ], array_filter([
×
43
            'proxy' => static::$proxy,
×
44
        ])));
×
45

46
        if ($response->getStatusCode() < 200 || $response->getStatusCode() > 299) {
×
NEW
47
            throw new Exception(\sprintf('Unable to download from [%s]', $url));
×
48
        }
49
    }
50

51
    /**
52
     * Get contents from URL.
53
     *
54
     * @throws \Exception
55
     */
56
    public static function fetch(string $url): string
57
    {
58
        $client = static::$instance ?? new Client;
8✔
59

60
        $response = $client->get($url, array_merge([
8✔
61
            'verify' => static::$verifySsl,
8✔
62
        ], array_filter([
8✔
63
            'proxy' => static::$proxy,
8✔
64
        ])));
8✔
65

66
        if ($response->getStatusCode() < 200 || $response->getStatusCode() > 299) {
8✔
NEW
67
            throw new Exception(\sprintf('Unable to fetch contents from [%s]', $url));
×
68
        }
69

70
        return (string) $response->getBody();
8✔
71
    }
72

73
    /**
74
     * Flush current state to default.
75
     */
76
    public static function flushState(): void
77
    {
78
        static::$instance = null;
15✔
79
        static::$proxy = null;
15✔
80
        static::$verifySsl = true;
15✔
81
    }
82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc