Completed
Push — master ( 2a88b7...1fad07 )
by Vladimir
06:33
created

Kernel::getPath()   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 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace FondBot\Toolbelt;
6
7
use GuzzleHttp\Client;
8
use League\Container\Container;
9
10
class Kernel
11
{
12
    private $container;
13
14
    public function __construct(Container $container)
15
    {
16
        $this->container = $container;
17
    }
18
19
    public function getPath(string $path = ''): string
20
    {
21
        return $this->resolve('base_path').'/'.$path;
22
    }
23
24
    /**
25
     * Resolve from container.
26
     *
27
     * @param string $class
28
     *
29
     * @return mixed
30
     * @throws \Psr\Container\ContainerExceptionInterface
31
     */
32
    public function resolve(string $class)
33
    {
34
        return $this->container->get($class);
35
    }
36
37
    /**
38
     * Get all available drivers.
39
     *
40
     * @return array
41
     *
42
     * @throws \RuntimeException
43
     * @throws \Psr\Container\ContainerExceptionInterface
44
     */
45
    public function getDrivers(): array
46
    {
47
        /** @var Client $http */
48
        $http = $this->resolve(Client::class);
49
50
        $response = $http->get('https://store.fondbot.com/api/drivers');
51
52
        return json_decode($response->getBody()->getContents(), true);
53
    }
54
}
55