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

BaseCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 77.78%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
dl 0
loc 35
c 1
b 0
f 0
ccs 14
cts 18
cp 0.7778
rs 10

4 Methods

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