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 ( e4bf89...f3fb4c )
by Freek
01:59
created

CheckSslCertificates   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 13.89 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 5 27 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\SslCertificate\Exceptions\CouldNotDownloadCertificate;
6
use Spatie\SslCertificate\SslCertificate;
7
use Spatie\UptimeMonitor\Models\Site;
8
use Spatie\UptimeMonitor\SiteRepository;
9
10
class CheckSslCertificates extends BaseCommand
11
{
12
    protected $signature = 'sites:check-ssl
13
                           {--url= : Only check these urls}';
14
15
16
    protected $description = 'Check the ssl certificates of all sites';
17
18
    public function handle()
19
    {
20
        $sites = SiteRepository::getAllForSslCheck();
21
22 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...
23
            $sites = $sites->filter(function(Site $site) use ($url) {
24
                return in_array((string)$site->url, explode(',', $url));
25
            });
26
        };
27
28
        $this->comment('Start checking the ssl certificate of '.count($sites).' sites...');
29
30
        $sites->each(function (Site $site) {
31
            $this->info("Checking ssl-certificate of {$site->url}");
32
33
            try {
34
                $certificate = SslCertificate::createForHostName($site->url->getHost());
35
36
                $site->updateWithCertificate($certificate);
37
            } catch (CouldNotDownloadCertificate $exception) {
38
                $this->error("Could not download certifcate of {$site->url} because: {$exception->getMessage()}");
39
                $site->updateWithCertificateException($exception);
40
            }
41
        });
42
43
        $this->info('All done!');
44
    }
45
}
46