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

ListDrivers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 10
cp 0
rs 10
wmc 4
lcom 1
cbo 4

1 Method

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