Passed
Push — master ( d1dc62...a1972e )
by Guillaume
08:28
created

BaseCommand::requestedAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

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