Completed
Push — master ( 816440...cac82f )
by Vladimir
12:37
created

API::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Foundation;
6
7
use GuzzleHttp\Client;
8
use Illuminate\Support\Collection;
9
10
class API
11
{
12
    public const URL = 'https://fondbot.io/api';
13
14
    private $client;
15
16
    public function __construct(Client $client)
17
    {
18
        $this->client = $client;
19
    }
20
21
    public function getDrivers(): Collection
22
    {
23
        $response = $this->client->get(self::URL.'/drivers', ['form_params' => ['version' => Kernel::VERSION]]);
24
25
        return collect(json_decode((string) $response->getBody(), true));
26
    }
27
28
    public function findDriver(string $name): ?array
29
    {
30
        return $this->getDrivers()->first(function ($item) use ($name) {
31
            return $item['name'] === $name;
32
        });
33
    }
34
}
35