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

ListDrivers::handle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 1
nop 0
dl 0
loc 19
ccs 8
cts 8
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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