1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\UptimeMonitor\Commands\UptimeMonitorLists; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Spatie\UptimeMonitor\Helpers\Emoji; |
7
|
|
|
use Spatie\UptimeMonitor\Models\Site; |
8
|
|
|
use Spatie\UptimeMonitor\SiteRepository; |
9
|
|
|
|
10
|
|
|
class DownSites |
11
|
|
|
{ |
12
|
|
|
protected $output; |
13
|
|
|
|
14
|
|
|
public function __construct(Command $output) |
15
|
|
|
{ |
16
|
|
|
$this->output = $output; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function display() |
20
|
|
|
{ |
21
|
|
|
$downSites = SiteRepository::downSites(); |
22
|
|
|
|
23
|
|
|
if (! $downSites->count()) { |
24
|
|
|
return; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
$this->output->info('Sites that are down'); |
28
|
|
|
$this->output->info('==================='); |
29
|
|
|
|
30
|
|
View Code Duplication |
$rows = $downSites->map(function (Site $site) { |
|
|
|
|
31
|
|
|
$url = $site->url; |
32
|
|
|
|
33
|
|
|
$reachable = $site->reachableAsEmoji; |
34
|
|
|
|
35
|
|
|
$offlineSince = $site->formattedLastUpdatedStatusChangeDate; |
36
|
|
|
|
37
|
|
|
$reason = $site->chunkedLastFailureReason; |
38
|
|
|
|
39
|
|
|
if ($site->check_ssl_certificate) { |
40
|
|
|
$sslCertificateFound = Emoji::ok(); |
41
|
|
|
$sslCertificateExpirationDate = $site->formattedSslCertificateExpirationDate; |
42
|
|
|
$sslCertificateIssuer = $site->ssl_certificate_issuer; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
return compact('url', 'reachable', 'offlineSince', 'reason', 'sslCertificateFound', 'sslCertificateExpirationDate', 'sslCertificateIssuer'); |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$titles = ['URL', 'Reachable', 'Offline since', 'Reason', 'SSL Certificate', 'SSL Expiration date', 'SSL Issuer']; |
49
|
|
|
|
50
|
|
|
$this->output->table($titles, $rows); |
51
|
|
|
} |
52
|
|
|
} |
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.