Completed
Push — 1.0 ( c1ae36...2d4770 )
by Vladimir
03:26 queued 01:11
created

ListDrivers   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 6 1
A handle() 0 19 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt\Commands;
6
7
use GuzzleHttp\Client;
8
use FondBot\Toolbelt\Command;
9
use Symfony\Component\Console\Helper\Table;
10
11
class ListDrivers extends Command
12
{
13 2
    protected function configure(): void
14
    {
15
        $this
16 2
            ->setName('driver:list')
17 2
            ->setDescription('Get list of all available drivers');
18 2
    }
19
20 1
    public function handle(): void
21
    {
22
        /** @var Client $http */
23 1
        $http = resolve(Client::class);
24 1
        $response = $http->get('https://fondbot.io/api/drivers');
25 1
        $items = json_decode((string) $response->getBody(), true);
26
27 1
        $drivers = collect($items)
28 1
            ->map(function ($item) {
29 1
                return [$item['name'], $item['package'], $item['official'] ? '✅' : '❌'];
30 1
            })
31
            ->toArray();
32
33
        $table = new Table($this->output);
34
        $table
35
            ->setHeaders(['Name', 'Package', 'Official'])
36
            ->setRows($drivers)
37
            ->render();
38
    }
39
}
40