ApiProvider::createClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Linode\Api;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
use Zurbaev\ApiClient\Contracts\ApiProviderInterface;
8
9
class ApiProvider implements ApiProviderInterface
10
{
11
    const BASE_URI = 'https://api.linode.com/v4/';
12
13
    /**
14
     * @var string
15
     */
16
    protected $token;
17
18
    /**
19
     * @var ClientInterface
20
     */
21
    protected $client;
22
23
    /**
24
     * ApiProvider constructor.
25
     *
26
     * @param string $token
27
     */
28
    public function __construct(string $token)
29
    {
30
        $this->token = $token;
31
    }
32
33
    public function getClient(): ClientInterface
34
    {
35
        if (!is_null($this->client)) {
36
            return $this->client;
37
        }
38
39
        return $this->client = $this->createClient();
40
    }
41
42
    public function createClient(): ClientInterface
43
    {
44
        return new Client([
45
            'base_uri' => static::BASE_URI,
46
            'headers' => [
47
                'Accept' => 'application/json',
48
                'Authorization' => 'Bearer '.$this->token,
49
                'Content-Type' => 'application/json',
50
            ],
51
        ]);
52
    }
53
}
54