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

InstallDriver   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 32 4
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