Passed
Push — master ( bcbcca...8fb468 )
by Guillaume
08:29
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 18
            $this->info(Str::ucfirst("$action started"));
18 18
            (new DocsetBuilder(new $docset(), $this))->$action();
19 18
            $this->info(Str::ucfirst("$action finished"));
20
21 18
            return;
22
        }
23
24 24
        $this->warn('The doc requested does not seem to be supported.');
25
26 24
        return 1;
27
    }
28
29 36
    protected function requestedDocset()
30
    {
31 36
        $classBasename = 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
        $classBasename = Str::studly(/** @scrutinizer ignore-type */ $this->argument('doc'));
Loading history...
32
33 36
        return class_exists("App\\Docsets\\$classBasename")
34
            ? "App\\Docsets\\$classBasename"
35 36
            : "Godbout\\DashDocsetBuilder\\Docsets\\$classBasename";
36
    }
37
38 36
    protected function requestedAction()
39
    {
40 36
        return $this->getName();
41
    }
42
43 36
    protected function isSupported()
44
    {
45 36
        return class_exists($this->requestedDocset());
46
    }
47
}
48