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 ( efcda2...1a4696 )
by Freek
02:11
created

ListUptimeMonitors::listSitesThatAreDown()   B

Complexity

Conditions 5
Paths 2

Size

Total Lines 33
Code Lines 18

Duplication

Lines 5
Ratio 15.15 %

Importance

Changes 0
Metric Value
cc 5
eloc 18
c 0
b 0
f 0
nc 2
nop 0
dl 5
loc 33
rs 8.439
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
    }
91
92
    public function listHealthySites()
93
    {
94
        $healthySites = SiteRepository::healthySites();
95
96
        if (!$healthySites->count()) {
97
            return;
98
        }
99
100
        $this->info('Healthy sites');
101
        $this->info('============');
102
103
        $rows = $healthySites->map(function (Site $site) {
104
            $url = $site->url;
105
106
            $reachable = ($site->uptime_status === UptimeStatus::UP) ? Emoji::ok() : Emoji::notOk();
107
108
            $onlineSince = $site->last_uptime_status_change_on->diffForHumans();
109
110 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...
111
                $sslCertificateFound = Emoji::ok();
112
                $sslCertificateExpirationDate = $site->ssl_certificate_expiration_date->diffForHumans();
113
                $sslCertificateIssuer = $site->ssl_certificate_issuer;
114
            }
115
116
117
            return compact('url', 'reachable', 'onlineSince', 'sslCertificateFound', 'sslCertificateExpirationDate', 'sslCertificateIssuer');
118
        });
119
120
        $titles = ['URL', 'Reachable', 'Online since', 'SSL Certifcate', 'SSL Expiration date', 'SSL Issuer'];
121
122
        $this->table($titles, $rows);
123
    }
124
125
126
}
127