Completed
Push — master ( 816440...cac82f )
by Vladimir
12:37
created

InstallDriver::handle()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 16
nc 4
nop 2
dl 0
loc 32
ccs 0
cts 13
cp 0
crap 20
rs 8.5806
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt;
6
7
use FondBot\Foundation\API;
8
use Illuminate\Console\Command;
9
use FondBot\Foundation\Composer;
10
11
class InstallDriver extends Command
12
{
13
    protected $signature = 'fondbot:driver-install 
14
                            {name : Driver name to be installed}';
15
16
    protected $description = 'Install driver';
17
18
    public function handle(API $api, Composer $composer): void
19
    {
20
        // Check if package is listed in store
21
        $name = $this->argument('name');
22
        $driver = $api->findDriver($this->argument('name'));
0 ignored issues
show
Bug introduced by
It seems like $this->argument('name') targeting Illuminate\Console\Command::argument() can also be of type array; however, FondBot\Foundation\API::findDriver() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
23
24
        if ($driver === null) {
25
            $this->error('"'.$name.'" is not found in the available drivers list.');
26
27
            exit(0);
28
        }
29
30
        if ($composer->installed($driver['package'])) {
31
            $this->error('Driver is already installed.');
32
33
            return;
34
        }
35
36
        // Install driver
37
        $this->info('Installing driver...');
38
39
        $result = $composer->install($driver['package'], function ($_, $line) use (&$output) {
40
            $output .= $line;
41
        });
42
43
        if ($result !== 0) {
44
            $this->error($output);
45
            exit($result);
46
        }
47
48
        $this->info('Driver installed.');
49
    }
50
}
51