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 ( e97bb7...5f2eb5 )
by Pascal
10:40 queued 09:38
created

AbstractSslCertificateChecker::run()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 4
nc 4
nop 0
1
<?php
2
3
namespace ProtoneMedia\ApiHealth\Checkers;
4
5
use Spatie\SslCertificate\Downloader;
6
use Spatie\SslCertificate\Exceptions\CouldNotDownloadCertificate;
7
use Spatie\SslCertificate\Exceptions\InvalidUrl;
8
9
abstract class AbstractSslCertificateChecker extends AbstractChecker
10
{
11
    /**
12
     * The Spatie SSL downloader.
13
     *
14
     * @var \Spatie\SslCertificate\Downloader $downloader
15
     */
16
    protected $downloader;
17
18
    /**
19
     * The hostname that must be checked.
20
     *
21
     * @var string
22
     */
23
    protected $hostname;
24
25
    /**
26
     * The port to request the certificate on.
27
     *
28
     * @var string
29
     */
30
    protected $port = 443;
31
32
    /**
33
     * Creates a new instance of this checker with a Ssl Certificate Downloader.
34
     *
35
     * @param \Spatie\SslCertificate\Downloader $downloader
36
     */
37
    public function __construct(Downloader $downloader)
38
    {
39
        $this->downloader = $downloader;
40
    }
41
42
    /**
43
     * Requests the URL and handles any thrown exceptions.
44
     *
45
     * @return null
46
     */
47
    public function run()
48
    {
49
        try {
50
            $certificate = $this->downloader->usingPort($this->port)->forHost($this->hostname);
51
        } catch (InvalidUrl $urlException) {
52
            throw new CheckerHasFailed("Could not check the Ssl Certificate for \"{$this->hostname}\": {$urlException->getMessage()}");
53
        } catch (CouldNotDownloadCertificate $downloadException) {
54
            throw new CheckerHasFailed("Could not download the Ssl Certificate for \"{$this->hostname}\": {$downloadException->getMessage()}");
55
        }
56
57
        if ($certificate->isValid()) {
58
            return;
59
        }
60
61
        throw new CheckerHasFailed("The Ssl Certificate for \"{$this->hostname}\" is not valid. The expiration date is {$certificate->expirationDate()}.");
62
    }
63
}
64