ApiProvider::setClient()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Osnova\Api;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
8
class ApiProvider
9
{
10
    /** @var ClientInterface */
11
    protected $client;
12
13
    /**
14
     * ApiProvider constructor.
15
     *
16
     * @param ClientInterface|null $client
17
     */
18
    public function __construct(ClientInterface $client = null)
19
    {
20
        $this->client = $client;
21
    }
22
23
    /**
24
     * Get the HTTP client instance.
25
     *
26
     * @return ClientInterface
27
     */
28
    public function getClient()
29
    {
30
        if (is_null($this->client)) {
31
            return $this->client = $this->createClient();
32
        }
33
34
        return $this->client;
35
    }
36
37
    /**
38
     * Set new HTTP client instance.
39
     *
40
     * @param ClientInterface $client
41
     *
42
     * @return ApiProvider
43
     */
44
    public function setClient(ClientInterface $client)
45
    {
46
        $this->client = $client;
47
48
        return $this;
49
    }
50
51
    /**
52
     * Create new HTTP client.
53
     *
54
     * @return ClientInterface
55
     */
56
    public function createClient()
57
    {
58
        return new Client();
59
    }
60
}
61