Completed
Push — master ( 06f997...84d5d5 )
by Vladimir
03:43
created

ListDriversCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 17
dl 0
loc 25
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Console;
6
7
use FondBot\Foundation\Api;
8
use Illuminate\Console\Command;
9
use FondBot\Channels\ChannelManager;
10
use GuzzleHttp\Exception\ClientException;
11
12
class ListDriversCommand extends Command
13
{
14
    protected $signature = 'fondbot: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