GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 279458...eeca96 )
by Freek
01:59
created

Downloader::downloadCertificateFromUrl()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 34
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 4
nop 2
dl 0
loc 34
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\SslCertificate;
4
5
use Spatie\SslCertificate\Exceptions\CouldNotDownloadCertificate;
6
use Throwable;
7
8
class Downloader
9
{
10
    public static function downloadCertificateFromUrl(string $url, int $timeout = 30): array
11
    {
12
        $hostName = (new Url($url))->getHostName();
13
14
        $streamContext = stream_context_create([
15
            'ssl' => [
16
                'capture_peer_cert' => true,
17
            ],
18
        ]);
19
20
        try {
21
            $client = stream_socket_client(
22
            "ssl://{$hostName}:443",
23
            $errorNumber,
24
            $errorDescription,
25
            $timeout,
26
            STREAM_CLIENT_CONNECT,
27
            $streamContext);
28
        } catch (Throwable $thrown) {
29
            if (str_contains($thrown->getMessage(), 'getaddrinfo failed')) {
30
                throw CouldNotDownloadCertificate::hostDoesNotExist($hostName);
31
            }
32
33
            if (str_contains($thrown->getMessage(), 'error:14090086')) {
34
                throw CouldNotDownloadCertificate::noCertifcateInstalled($hostName);
35
            }
36
37
            throw CouldNotDownloadCertificate::unknownError($hostName, $thrown->getMessage());
38
        }
39
40
        $response = stream_context_get_params($client);
41
42
        return openssl_x509_parse($response['options']['ssl']['peer_certificate']);
43
    }
44
}
45