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.

CreateMonitor::handle()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.2248
c 0
b 0
f 0
cc 5
nc 6
nop 0
1
<?php
2
3
namespace Spatie\UptimeMonitor\Commands;
4
5
use Spatie\UptimeMonitor\Models\Monitor;
6
use Spatie\Url\Url;
7
8
class CreateMonitor extends BaseCommand
9
{
10
    protected $signature = 'monitor:create {url}';
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\Conce...ractsWithIO::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
18
        if (! in_array($url->getScheme(), ['http', 'https'])) {
19
            if ($scheme = $this->choice("Which protocol needs to be used for checking `{$url}`?", [1 => 'https', 2 => 'http'], 1)) {
20
                $url = $url->withScheme($scheme);
0 ignored issues
show
Bug introduced by
It seems like $scheme defined by $this->choice("Which pro...ttps', 2 => 'http'), 1) on line 19 can also be of type array; however, Spatie\Url\Url::withScheme() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
21
            }
22
        }
23
24
        if ($this->confirm('Should we look for a specific string on the response?')) {
25
            $lookForString = $this->ask('Which string?');
26
        }
27
28
        $monitor = Monitor::create([
29
            'url' => trim($url, '/'),
30
            'look_for_string' => $lookForString ?? '',
31
            'uptime_check_method' => isset($lookForString) ? 'get' : 'head',
32
            'certificate_check_enabled' => $url->getScheme() === 'https',
33
            'uptime_check_interval_in_minutes' => config('uptime-monitor.uptime_check.run_interval_in_minutes'),
34
        ]);
35
36
        $this->warn("{$monitor->url} will be monitored!");
37
    }
38
}
39