Completed
Push — master ( 7d3761...62ec31 )
by Jérémy
03:30
created

ClientBuilder::createClientV3()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JDecool\Clubhouse;
6
7
use Http\{
8
    Client\Common\HttpMethodsClient,
9
    Client\HttpClient,
10
    Discovery\HttpClientDiscovery,
11
    Discovery\MessageFactoryDiscovery,
12
    Message\MessageFactory
13
};
14
use RuntimeException;
15
16
class ClientBuilder
17
{
18
    public const V1 = 'v1';
19
    public const V2 = 'v2';
20
    public const V3 = 'v3';
21
    public const BETA = 'beta';
22
23
    private $httpClient;
24
    private $messageFactory;
25
26
    public function __construct(?HttpClient $httpClient = null, ?MessageFactory $messageFactory = null)
27
    {
28
        $this->httpClient = $httpClient ?? HttpClientDiscovery::find();
29
        $this->messageFactory = $messageFactory ?? MessageFactoryDiscovery::find();
30
    }
31
32
    public function createClientV1(string $token): Client
33
    {
34
        return $this->create(self::V1, $token);
35
    }
36
37
    public function createClientV2(string $token): Client
38
    {
39
        return $this->create(self::V2, $token);
40
    }
41
42
    public function createClientV3(string $token): Client
43
    {
44
        return $this->create(self::V3, $token);
45
    }
46
47
    public function createClientBeta(string $token): Client
48
    {
49
        return $this->create(self::BETA, $token);
50
    }
51
52
    public function create(string $version, string $token): Client
53
    {
54
        $http = new HttpMethodsClient($this->httpClient, $this->messageFactory);
55
56
        switch ($version) {
57
            case self::V1:
58
                return Client::createV1($http, $token);
59
60
            case self::V2:
61
                return Client::createV2($http, $token);
62
63
            case self::V3:
64
                return Client::createV3($http, $token);
65
66
            case self::BETA:
67
                return Client::createBeta($http, $token);
68
        }
69
70
        throw new RuntimeException("Version '$version' is not supported.");
71
    }
72
}
73