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
Pull Request — master (#23)
by Freek
03:57 queued 02:01
created

ListUptimeMonitors::listSitesWithSslProblems()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 2
nop 0
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\UptimeMonitor\Commands;
4
5
use Illuminate\Console\Command;
6
use Spatie\UptimeMonitor\Helpers\Emoji;
7
use Spatie\UptimeMonitor\Models\Enums\UptimeStatus;
8
use Spatie\UptimeMonitor\Models\Site;
9
use Spatie\UptimeMonitor\SiteRepository;
10
11
class ListUptimeMonitors extends Command
12
{
13
    /**
14
     * The name and signature of the console command.
15
     *
16
     * @var string
17
     */
18
    protected $signature = 'uptime-monitor:list';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'List all uptime monitors';
26
27
    public function handle()
28
    {
29
        $this->listSitesThatAreDown();
30
        $this->listSitesWithSslProblems();
31
        $this->listHealthySites();
32
    }
33
34
    public function listSitesThatAreDown()
35
    {
36
        $downSites = SiteRepository::downSites();
37
38
        if (! $downSites->count()) {
39
            return;
40
        }
41
42
        $this->info('Sites that are down');
43
        $this->info('===================');
44
45
        $rows = $downSites->map(function (Site $site) {
46
            $url = $site->url;
47
48
            $reachable = ($site->uptime_status === UptimeStatus::UP) ? Emoji::ok() : Emoji::notOk();
49
50
            $offlineSince = $site->last_uptime_status_change_on->diffForHumans();
51
52
            $reason = $site->last_failure_reason != '' ? chunk_split($site->last_failure_reason, 15, "\n") : '';
53
54 View Code Duplication
            if ($site->check_ssl_certificate) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55
                $sslCertificateFound = Emoji::ok();
56
                $sslCertificateExpirationDate = $site->ssl_certificate_expiration_date->diffForHumans();
57
                $sslCertificateIssuer = $site->ssl_certificate_issuer;
58
            }
59
60
            return compact('url', 'reachable', 'offlineSince', 'reason', 'sslCertificateFound', 'sslCertificateExpirationDate', 'sslCertificateIssuer');
61
        });
62
63
        $titles = ['URL', 'Reachable', 'Offine since', 'Reason', 'SSL Certifcate', 'SSL Expiration date', 'SSL Issuer'];
64
65
        $this->table($titles, $rows);
66
    }
67
68
    protected function listSitesWithSslProblems()
69
    {
70
        $sitesWithSslProblems = SiteRepository::withSslProblems();
71
72
        if (! $sitesWithSslProblems->count()) {
73
            return;
74
        }
75
76
        $rows = $sitesWithSslProblems->map(function (Site $site) {
0 ignored issues
show
Unused Code introduced by
$rows is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
            $url = $site->url;
78
79
            $reachable = ($site->uptime_status === UptimeStatus::UP) ? Emoji::ok() : Emoji::notOk();
80
81
            $sslCertificateFound = Emoji::notOk();
82
            $sslCertificateExpirationDate = $site->ssl_certificate_expiration_date ? $site->ssl_certificate_expiration_date->diffForHumans() : '';
83
            $sslCertificateIssuer = $site->ssl_certificate_issuer ?? 'Unknown';
84
85
86
            return compact('url', 'reachable', 'sslCertificateFound', 'sslCertificateExpirationDate', 'sslCertificateIssuer');
87
        });
88
    }
89
90
    public function listHealthySites()
91
    {
92
        $healthySites = SiteRepository::healthySites();
93
94
        if (! $healthySites->count()) {
95
            return;
96
        }
97
98
        $this->info('Healthy sites');
99
        $this->info('============');
100
101
        $rows = $healthySites->map(function (Site $site) {
102
            $url = $site->url;
103
104
            $reachable = ($site->uptime_status === UptimeStatus::UP) ? Emoji::ok() : Emoji::notOk();
105
106
            $onlineSince = $site->last_uptime_status_change_on->diffForHumans();
107
108 View Code Duplication
            if ($site->check_ssl_certificate) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
109
                $sslCertificateFound = Emoji::ok();
110
                $sslCertificateExpirationDate = $site->ssl_certificate_expiration_date->diffForHumans();
111
                $sslCertificateIssuer = $site->ssl_certificate_issuer;
112
            }
113
114
115
            return compact('url', 'reachable', 'onlineSince', 'sslCertificateFound', 'sslCertificateExpirationDate', 'sslCertificateIssuer');
116
        });
117
118
        $titles = ['URL', 'Reachable', 'Online since', 'SSL Certifcate', 'SSL Expiration date', 'SSL Issuer'];
119
120
        $this->table($titles, $rows);
121
    }
122
}
123