Passed
Push — master ( 30520d...33f18a )
by Vladimir
03:04
created

InstallDriverCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 18
dl 0
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 31 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt;
6
7
use FondBot\Foundation\API;
8
use FondBot\Foundation\Kernel;
9
use Illuminate\Console\Command;
10
use FondBot\Foundation\Composer;
11
12
class InstallDriverCommand extends Command
13
{
14
    protected $signature = 'fondbot:driver:install 
15
                            {name : Driver name to be installed}';
16
17
    protected $description = 'Install driver';
18
19
    public function handle(API $api, Composer $composer): void
20
    {
21
        // Check if package is listed in store
22
        $name = $this->argument('name');
23
        $driver = $api->findDriver($this->argument('name'));
24
25
        if ($driver === null) {
26
            $this->error('"'.$name.'" is not found in the available drivers list or is not yet supported by current FondBot version ('.Kernel::VERSION.').');
0 ignored issues
show
Bug introduced by
Are you sure $name of type null|string|array can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
            $this->error('"'./** @scrutinizer ignore-type */ $name.'" is not found in the available drivers list or is not yet supported by current FondBot version ('.Kernel::VERSION.').');
Loading history...
27
28
            exit(0);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
29
        }
30
31
        if ($composer->installed($driver['package'])) {
32
            $this->error('Driver is already installed.');
33
34
            return;
35
        }
36
37
        // Install driver
38
        $this->info('Installing driver...');
39
40
        $result = $composer->install($driver['package'], function ($_, $line) use (&$output) {
41
            $output .= $line;
42
        });
43
44
        if ($result !== 0) {
45
            $this->error($output);
46
            exit($result);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
47
        }
48
49
        $this->info('Driver installed. ✔');
50
    }
51
}
52