Passed
Push — master ( bcbcca...8fb468 )
by Guillaume
08:29
created

BaseCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 6
eloc 16
dl 0
loc 37
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 2
A requestedAction() 0 3 1
A requestedDocset() 0 7 2
A isSupported() 0 3 1
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