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.

CheckCertificates   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 15.63 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 5
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 5 24 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Spatie\UptimeMonitor\Commands;
4
5
use Spatie\UptimeMonitor\Models\Enums\CertificateStatus;
6
use Spatie\UptimeMonitor\Models\Monitor;
7
use Spatie\UptimeMonitor\MonitorRepository;
8
9
class CheckCertificates extends BaseCommand
10
{
11
    protected $signature = 'monitor:check-certificate
12
                           {--url= : Only check these urls}';
13
14
    protected $description = 'Check the certificates of all sites';
15
16
    public function handle()
17
    {
18
        $monitors = MonitorRepository::getForCertificateCheck();
19
20 View Code Duplication
        if ($url = $this->option('url')) {
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...
21
            $monitors = $monitors->filter(function (Monitor $monitor) use ($url) {
22
                return in_array((string) $monitor->url, explode(',', $url));
23
            });
24
        }
25
26
        $this->comment('Start checking the certificates of '.count($monitors).' monitors...');
27
28
        $monitors->each(function (Monitor $monitor) {
29
            $this->info("Checking certificate of {$monitor->url}");
30
31
            $monitor->checkCertificate();
32
33
            if ($monitor->certificate_status !== CertificateStatus::VALID) {
34
                $this->error("Could not download certificate of {$monitor->url} because: {$monitor->certificate_check_failure_reason}");
35
            }
36
        });
37
38
        $this->info('All done!');
39
    }
40
}
41