Passed
Push — master ( a85aeb...922d24 )
by Vladimir
08:38
created

ListDrivers::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
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 Http\Client\HttpClient;
8
use FondBot\Toolbelt\Command;
9
use Http\Message\RequestFactory;
10
use Symfony\Component\Console\Helper\Table;
11
12
class ListDrivers extends Command
13
{
14 2
    protected function configure(): void
15
    {
16
        $this
17 2
            ->setName('driver:list')
18 2
            ->setDescription('Get list of all available drivers');
19 2
    }
20
21 1
    public function handle(): void
22
    {
23
        /** @var HttpClient $http */
24 1
        $http = resolve(HttpClient::class);
25
        /** @var RequestFactory $requestFactory */
26 1
        $requestFactory = resolve(RequestFactory::class);
27
28 1
        $request = $requestFactory->createRequest('GET', 'https://fondbot.com/api/drivers');
29
30 1
        $response = $http->sendRequest($request);
31
32 1
        $items = json_decode((string) $response->getBody(), true);
33
34 1
        $drivers = collect($items)
35 1
            ->map(function ($item) {
36 1
                return [$item['name'], $item['package'], $item['official'] ? '✅' : '❌'];
37 1
            })
38 1
            ->toArray();
39
40 1
        $table = new Table($this->output);
41
        $table
42 1
            ->setHeaders(['Name', 'Package', 'Official'])
43 1
            ->setRows($drivers)
44 1
            ->render();
45 1
    }
46
}
47