Passed
Push — master ( 636760...d1dc62 )
by Guillaume
08:55
created

BaseCommand::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.1707

Importance

Changes 0
Metric Value
cc 3
eloc 14
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 24
ccs 11
cts 15
cp 0.7332
crap 3.1707
rs 9.7998
1
<?php
2
3
namespace Godbout\DashDocsetBuilder\Commands;
4
5
use Godbout\DashDocsetBuilder\Services\DocsetBuilder;
6
use Godbout\DashDocsetBuilder\Services\DocsetNewer;
7
use Illuminate\Support\Str;
8
use LaravelZero\Framework\Commands\Command;
9
10
abstract class BaseCommand extends Command
11
{
12 36
    public function handle()
13
    {
14 36
        $docset = $this->requestedDocset();
15 36
        $action = $this->requestedAction();
16
17 36
        if ($action === 'new') {
18
            $this->info('New Docset started');
19
            (new DocsetBuilder(null, $this))->new();
20
            $this->info('New Docset finished');
21
22
            return;
23
        }
24
25 36
        if ($this->isSupported()) {
26 18
            $this->info(Str::ucfirst("$action started"));
27 18
            (new DocsetBuilder(new $docset(), $this))->$action();
28 18
            $this->info(Str::ucfirst("$action finished"));
29
30 18
            return;
31
        }
32
33 24
        $this->warn('The doc requested does not seem to be supported.');
34
35 24
        return 1;
36
    }
37
38 36
    protected function requestedDocset()
39
    {
40 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

40
        $classBasename = Str::studly(/** @scrutinizer ignore-type */ $this->argument('doc'));
Loading history...
41
42 36
        return class_exists("App\\Docsets\\$classBasename")
43
            ? "App\\Docsets\\$classBasename"
44 36
            : "Godbout\\DashDocsetBuilder\\Docsets\\$classBasename";
45
    }
46
47 36
    protected function requestedAction()
48
    {
49 36
        return $this->getName();
50
    }
51
52 36
    protected function isSupported()
53
    {
54 36
        return class_exists($this->requestedDocset());
55
    }
56
}
57