Passed
Push — master ( 9ef401...bcbcca )
by Guillaume
07:29
created

BaseCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 76.47%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
eloc 14
c 2
b 1
f 0
dl 0
loc 34
ccs 13
cts 17
cp 0.7647
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 4 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 18
    public function handle()
12
    {
13 18
        $docset = $this->requestedDocset();
14 18
        $action = $this->requestedAction();
15
16 18
        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 18
        $this->warn('The doc requested does not seem to be supported.');
25
26 18
        return 1;
27
    }
28
29 18
    protected function requestedDocset()
30
    {
31 18
        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 18
    protected function requestedAction()
35
    {
36 18
        return $this->getName();
37
    }
38
39 18
    protected function isSupported()
40
    {
41 18
        return class_exists("Godbout\\DashDocsetBuilder\\Docsets\\" . $this->requestedDocset())
42 18
            || class_exists("App\\Docsets\\" . $this->requestedDocset());
43
    }
44
}
45