Completed
Push — master ( 290f71...5c7d58 )
by Tobias
01:52
created

BillogramClient::logotype()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
/*
5
 * This software may be modified and distributed under the terms
6
 * of the MIT license. See the LICENSE file for details.
7
 */
8
9
namespace Billogram;
10
11
use Billogram\Api\Customer;
12
use Billogram\Api\Invoice;
13
use Billogram\Api\Item;
14
use Billogram\Api\LogoType;
15
use Billogram\Api\Report;
16
use Billogram\Api\Settings;
17
use Billogram\Hydrator\ModelHydrator;
18
use Billogram\Hydrator\Hydrator;
19
use Http\Client\HttpClient;
20
21
/**
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
final class BillogramClient
25
{
26
    /**
27
     * @var HttpClient
28
     */
29
    private $httpClient;
30
31
    /**
32
     * @var Hydrator
33
     */
34
    private $hydrator;
35
36
    /**
37
     * @var RequestBuilder
38
     */
39
    private $requestBuilder;
40
41
    /**
42
     * The constructor accepts already configured HTTP clients.
43
     * Use the configure method to pass a configuration to the Client and create an HTTP Client.
44
     *
45
     * @param HttpClient          $httpClient
46
     * @param Hydrator|null       $hydrator
47
     * @param RequestBuilder|null $requestBuilder
48
     */
49 15
    public function __construct(
50
        HttpClient $httpClient,
51
        Hydrator $hydrator = null,
52
        RequestBuilder $requestBuilder = null
53
    ) {
54 15
        $this->httpClient = $httpClient;
55 15
        $this->hydrator = $hydrator ?: new ModelHydrator();
56 15
        $this->requestBuilder = $requestBuilder ?: new RequestBuilder();
57 15
    }
58
59
    /**
60
     * @param HttpClientConfigurator $httpClientConfigurator
61
     * @param Hydrator|null          $hydrator
62
     * @param RequestBuilder|null    $requestBuilder
63
     *
64
     * @return BillogramClient
65
     */
66 15
    public static function configure(
67
        HttpClientConfigurator $httpClientConfigurator,
68
        Hydrator $hydrator = null,
69
        RequestBuilder $requestBuilder = null
70
    ): self {
71 15
        $httpClient = $httpClientConfigurator->createConfiguredClient();
72
73 15
        return new self($httpClient, $hydrator, $requestBuilder);
74
    }
75
76
    /**
77
     * @param string $apiKey
78
     *
79
     * @return BillogramClient
80
     */
81 1
    public static function create(string $username, string $apiKey): BillogramClient
82
    {
83 1
        $httpClientConfigurator = (new HttpClientConfigurator())->setAuth($username, $apiKey);
84
85 1
        return self::configure($httpClientConfigurator);
86
    }
87
88
    /**
89
     * @return Api\Customer
90
     */
91
    public function customers(): Customer
92
    {
93
        return new Api\Customer($this->httpClient, $this->hydrator, $this->requestBuilder);
94
    }
95
96
    /**
97
     * @return Api\Item
98
     */
99 5
    public function items(): Item
100
    {
101 5
        return new Api\Item($this->httpClient, $this->hydrator, $this->requestBuilder);
102
    }
103
104
    /**
105
     * @return Api\Invoice
106
     */
107 4
    public function invoices(): Invoice
108
    {
109 4
        return new Api\Invoice($this->httpClient, $this->hydrator, $this->requestBuilder);
110
    }
111
112
    /**
113
     * @return Api\Report
114
     */
115 2
    public function report(): Report
116
    {
117 2
        return new Api\Report($this->httpClient, $this->hydrator, $this->requestBuilder);
118
    }
119
120
    /**
121
     * @return Api\Settings
122
     */
123 2
    public function settings(): Settings
124
    {
125 2
        return new Api\Settings($this->httpClient, $this->hydrator, $this->requestBuilder);
126
    }
127
128
    /**
129
     * @return Api\LogoType
130
     */
131 2
    public function logotype(): LogoType
132
    {
133 2
        return new Api\LogoType($this->httpClient, $this->hydrator, $this->requestBuilder);
134
    }
135
}
136