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

API   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getDrivers() 0 6 1
A findDriver() 0 6 1
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