Completed
Push — master ( c28851...781c6a )
by Tobias
02:28
created

LocoClient::export()   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
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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\Localise;
11
12
use FAPI\Localise\Hydrator\ModelHydrator;
13
use FAPI\Localise\Hydrator\Hydrator;
14
use Http\Client\HttpClient;
15
16
/**
17
 * @author Tobias Nyholm <[email protected]>
18
 */
19
final class LocoClient
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
    /**
72
     * @return Api\Translation
73
     */
74
    public function translations(): Api\Translation
75
    {
76
        return new Api\Translation($this->httpClient, $this->hydrator, $this->requestBuilder);
77
    }
78
79
    /**
80
     * @return Api\Asset
81
     */
82
    public function asset(): Api\Asset
83
    {
84
        return new Api\Asset($this->httpClient, $this->hydrator, $this->requestBuilder);
85
    }
86
87
    /**
88
     * @return Api\Import
89
     */
90
    public function import(): Api\Import
91
    {
92
        return new Api\Import($this->httpClient, $this->hydrator, $this->requestBuilder);
93
    }
94
95
    /**
96
     * @return Api\Export
97
     */
98
    public function export(): Api\Export
99
    {
100
        return new Api\Export($this->httpClient, $this->hydrator, $this->requestBuilder);
101
    }
102
}
103