Passed
Push — master ( de3cce...9ef401 )
by Guillaume
07:53
created

BaseCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Godbout\DashDocsetBuilder\Commands;
4
5
use Illuminate\Support\Str;
6
use LaravelZero\Framework\Commands\Command;
7
use Godbout\DashDocsetBuilder\Services\DocsetBuilder;
8
9
abstract class BaseCommand extends Command
10
{
11 36
    public function handle()
12
    {
13 36
        $docset = $this->requestedDocset();
14 36
        $action = $this->requestedAction();
15
16 36
        if ($this->isSupported()) {
17
            $this->info(Str::ucfirst("$action started"));
18
            (new DocsetBuilder(new $docset(), $this))->$action();
19
            $this->info(Str::ucfirst("$action finished"));
20
21
            return;
22
        }
23
24 36
        $this->warn('The doc requested does not seem to be supported.');
25
26 36
        return 1;
27
    }
28
29 36
    protected function requestedDocset()
30
    {
31 36
        return Str::studly($this->argument('doc'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('doc') can also be of type string[]; however, parameter $value of Illuminate\Support\Str::studly() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
        return Str::studly(/** @scrutinizer ignore-type */ $this->argument('doc'));
Loading history...
32
    }
33
34 36
    protected function requestedAction()
35
    {
36 36
        return $this->getName();
37
    }
38
39 36
    protected function isSupported()
40
    {
41 36
        return class_exists(
42 36
            "Godbout\\DashDocsetBuilder\\Docsets\\" . $this->requestedDocset()
43 36
            || "App\\Docsets\\" . $this->requestedDocset()
44
        );
45
    }
46
}
47