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 (#154)
by Daniel
49:51 queued 14:35
created

CreateMonitor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 25 6
1
<?php
2
3
namespace Spatie\UptimeMonitor\Commands;
4
5
use Spatie\Url\Url;
6
use Spatie\UptimeMonitor\Models\Monitor;
7
8
class CreateMonitor extends BaseCommand
9
{
10
    protected $signature = 'monitor:create {url} {--N|no-trim : Don\'t trim the trailing slash on URL input.}';
11
12
    protected $description = 'Create a monitor';
13
14
    public function handle()
15
    {
16
        $url = Url::fromString($this->argument('url'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('url') targeting Illuminate\Console\Command::argument() can also be of type array or null; however, Spatie\Url\Url::fromString() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
17
        $noTrimUrl = $this->option('no-trim');
18
19
        if (! in_array($url->getScheme(), ['http', 'https'])) {
20
            if ($scheme = $this->choice("Which protocol needs to be used for checking `{$url}`?", [1 => 'https', 2 => 'http'], 1)) {
21
                $url = $url->withScheme($scheme);
22
            }
23
        }
24
25
        if ($this->confirm('Should we look for a specific string on the response?')) {
26
            $lookForString = $this->ask('Which string?');
27
        }
28
29
        $monitor = Monitor::create([
30
            'url' => $noTrimUrl ? $url : trim($url, '/'),
31
            'look_for_string' => $lookForString ?? '',
32
            'uptime_check_method' => isset($lookForString) ? 'get' : 'head',
33
            'certificate_check_enabled' => $url->getScheme() === 'https',
34
            'uptime_check_interval_in_minutes' => config('uptime-monitor.uptime_check.run_interval_in_minutes'),
35
        ]);
36
37
        $this->warn("{$monitor->url} will be monitored!");
38
    }
39
}
40