Completed
Push — master ( 08753a...42665f )
by Sascha-Oliver
05:38
created

PhraseAppClient   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 7
dl 0
loc 72
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A configure() 0 9 1
A upload() 0 4 1
A locale() 0 4 1
A translation() 0 4 1
A key() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace FAPI\PhraseApp;
11
12
use FAPI\PhraseApp\Hydrator\Hydrator;
13
use FAPI\PhraseApp\Hydrator\ModelHydrator;
14
use Http\Client\HttpClient;
15
16
/**
17
 * @author Sascha-Oliver Prolic <[email protected]>
18
 */
19
final class PhraseAppClient
20
{
21
    /**
22
     * @var HttpClient
23
     */
24
    private $httpClient;
25
26
    /**
27
     * @var Hydrator
28
     */
29
    private $hydrator;
30
31
    /**
32
     * @var RequestBuilder
33
     */
34
    private $requestBuilder;
35
36
    /**
37
     * The constructor accepts already configured HTTP clients.
38
     * Use the configure method to pass a configuration to the Client and create an HTTP Client.
39
     *
40
     * @param HttpClient          $httpClient
41
     * @param Hydrator|null       $hydrator
42
     * @param RequestBuilder|null $requestBuilder
43
     */
44
    public function __construct(
45
        HttpClient $httpClient,
46
        Hydrator $hydrator = null,
47
        RequestBuilder $requestBuilder = null
48
    ) {
49
        $this->httpClient = $httpClient;
50
        $this->hydrator = $hydrator ?: new ModelHydrator();
51
        $this->requestBuilder = $requestBuilder ?: new RequestBuilder();
52
    }
53
54
    /**
55
     * @param HttpClientConfigurator $httpClientConfigurator
56
     * @param Hydrator|null          $hydrator
57
     * @param RequestBuilder|null    $requestBuilder
58
     *
59
     * @return ApiClient
60
     */
61
    public static function configure(
62
        HttpClientConfigurator $httpClientConfigurator,
63
        Hydrator $hydrator = null,
64
        RequestBuilder $requestBuilder = null
65
    ): self {
66
        $httpClient = $httpClientConfigurator->createConfiguredClient();
67
68
        return new self($httpClient, $hydrator, $requestBuilder);
69
    }
70
71
    public function upload(): Api\Upload
72
    {
73
        return new Api\Upload($this->httpClient, $this->hydrator, $this->requestBuilder);
74
    }
75
76
    public function locale(): Api\Locale
77
    {
78
        return new Api\Locale($this->httpClient, $this->hydrator, $this->requestBuilder);
79
    }
80
81
    public function translation(): Api\Translation
82
    {
83
        return new Api\Translation($this->httpClient, $this->hydrator, $this->requestBuilder);
84
    }
85
86
    public function key(): Api\Key
87
    {
88
        return new Api\Key($this->httpClient, $this->hydrator, $this->requestBuilder);
89
    }
90
}
91