LocoClient   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 82
ccs 0
cts 32
cp 0
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A export() 0 3 1
A import() 0 3 1
A configure() 0 8 1
A __construct() 0 8 3
A translations() 0 3 1
A asset() 0 3 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\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 LocoClient
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