Completed
Push — master ( 2f1c32...3dd624 )
by Vladimir
02:34
created

ListDrivers::handle()   B

Complexity

Conditions 4
Paths 5

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 15
c 1
b 0
f 0
nc 5
nop 2
dl 0
loc 22
ccs 0
cts 10
cp 0
crap 20
rs 8.9197
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\Channels\ChannelManager;
10
use GuzzleHttp\Exception\ClientException;
11
12
class ListDrivers extends Command
13
{
14
    protected $signature = 'driver:list';
15
    protected $description = 'List add installed drivers';
16
17
    public function handle(API $api, ChannelManager $manager): void
18
    {
19
        try {
20
            $installedDrivers = collect($manager->getDrivers())->keys()->toArray();
21
            $availableDrivers = $api->getDrivers();
22
23
            $rows = collect($availableDrivers)
24
                ->transform(function ($item) use ($installedDrivers) {
25
                    return [
26
                        $item['name'],
27
                        $item['package'],
28
                        $item['official'] ? '✅' : '❌',
29
                        in_array($item['name'], $installedDrivers, true) ? '✅' : '❌',
30
                    ];
31
                })
32
                ->toArray();
33
34
            $this->table(['Name', 'Package', 'Official', 'Installed'], $rows);
35
        } catch (ClientException $exception) {
36
            $this->error('Connection to FondBot API failed. Please check your internet connection and try again.');
37
        }
38
    }
39
}
40