Skip to content

Commit f4724c1

Browse files
authored
Merge pull request #135 from Sysix/interfaces
added ApiInterface, make request protected and use getRequest() instead
2 parents 19ced0c + 6158c94 commit f4724c1

39 files changed

+206
-175
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'multiline_comment_opening_closing' => true,
1515
'multiline_whitespace_before_semicolons' => true,
1616
'native_type_declaration_casing' => true,
17+
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
1718
'no_alias_functions' => true,
1819
'no_alias_language_construct_call' => true,
1920
'no_alternative_syntax' => true,

src/Api.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
namespace Sysix\LexOffice;
66

7+
use GuzzleHttp\Psr7\Request;
78
use GuzzleHttp\Psr7\Uri;
9+
use Psr\Http\Client\ClientInterface;
10+
use Psr\Http\Message\RequestInterface;
11+
use Psr\Http\Message\ResponseInterface;
12+
use Psr\Http\Message\UriInterface;
13+
use SensitiveParameter;
814
use Sysix\LexOffice\Clients\Contact;
915
use Sysix\LexOffice\Clients\Country;
1016
use Sysix\LexOffice\Clients\CreditNote;
@@ -21,30 +27,22 @@
2127
use Sysix\LexOffice\Clients\RecurringTemplate;
2228
use Sysix\LexOffice\Clients\Voucher;
2329
use Sysix\LexOffice\Clients\VoucherList;
24-
use GuzzleHttp\Psr7\Request;
25-
use Psr\Http\Client\ClientInterface;
26-
use Psr\Http\Message\RequestInterface;
27-
use Psr\Http\Message\ResponseInterface;
28-
use Psr\Http\Message\UriInterface;
29-
use SensitiveParameter;
30+
use Sysix\LexOffice\Interfaces\ApiInterface;
3031

31-
class Api
32+
class Api implements ApiInterface
3233
{
3334
public string $apiUrl = 'https://api.lexoffice.io';
3435

3536
protected string $apiVersion = 'v1';
3637

37-
public RequestInterface $request;
38+
protected RequestInterface $request;
3839

3940
public function __construct(
4041
#[SensitiveParameter] protected string $apiKey,
4142
protected ClientInterface $client
4243
) {
4344
}
4445

45-
/**
46-
* @param string[] $headers
47-
*/
4846
public function newRequest(string $method, string $resource, array $headers = []): self
4947
{
5048
$this->setRequest(
@@ -71,16 +69,21 @@ public function setRequest(RequestInterface $request): self
7169
return $this;
7270
}
7371

74-
protected function createApiUri(string $resource): UriInterface
72+
public function getRequest(): RequestInterface
7573
{
76-
return new Uri($this->apiUrl . '/' . $this->apiVersion . '/' . $resource);
74+
return $this->request;
7775
}
7876

7977
public function getResponse(): ResponseInterface
8078
{
8179
return $this->client->sendRequest($this->request);
8280
}
8381

82+
protected function createApiUri(string $resource): UriInterface
83+
{
84+
return new Uri($this->apiUrl . '/' . $this->apiVersion . '/' . $resource);
85+
}
86+
8487
public function contact(): Contact
8588
{
8689
return new Contact($this);

src/BaseClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
namespace Sysix\LexOffice;
66

77
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\Interfaces\ApiInterface;
9+
use Sysix\LexOffice\Interfaces\ClientInterface;
810

911
abstract class BaseClient implements ClientInterface
1012
{
1113
protected string $resource;
1214

1315
public function __construct(
14-
protected Api $api
16+
protected ApiInterface $api
1517
) {
1618
}
1719

src/ClientInterface.php

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/Clients/Country.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
87
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
99

1010
class Country extends BaseClient
1111
{

src/Clients/Event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7+
use Psr\Http\Message\ResponseInterface;
78
use Sysix\LexOffice\BaseClient;
89
use Sysix\LexOffice\Clients\Traits\CreateTrait;
910
use Sysix\LexOffice\Clients\Traits\DeleteTrait;
10-
use Psr\Http\Message\ResponseInterface;
1111

1212
class Event extends BaseClient
1313
{

src/Clients/File.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
8-
use Sysix\LexOffice\Exceptions\LexOfficeApiException;
97
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
109
use Sysix\LexOffice\Config\FileClientConfig;
10+
use Sysix\LexOffice\Exceptions\LexOfficeApiException;
1111
use Sysix\LexOffice\Utils;
1212

1313
class File extends BaseClient
@@ -18,7 +18,7 @@ public function get(string $id, string $acceptHeader = '*/*'): ResponseInterface
1818
{
1919
$this->api->newRequest('GET', $this->resource . '/' . rawurlencode($id));
2020

21-
$this->api->request = $this->api->request->withHeader('Accept', $acceptHeader);
21+
$this->api->setRequest($this->api->getRequest()->withHeader('Accept', $acceptHeader));
2222

2323
return $this->api->getResponse();
2424
}
@@ -44,7 +44,7 @@ public function upload(string $filepath, string $type): ResponseInterface
4444
'Content-Type' => 'multipart/form-data; boundary=' . $body->getBoundary()
4545
]);
4646

47-
$api->request = $api->request->withBody($body);
47+
$api->setRequest($api->getRequest()->withBody($body));
4848

4949
return $api->getResponse();
5050
}

src/Clients/PaymentCondition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
87
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
99

1010
class PaymentCondition extends BaseClient
1111
{

src/Clients/PostingCategory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
87
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
99

1010
class PostingCategory extends BaseClient
1111
{

src/Clients/Profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Sysix\LexOffice\Clients;
66

7-
use Sysix\LexOffice\BaseClient;
87
use Psr\Http\Message\ResponseInterface;
8+
use Sysix\LexOffice\BaseClient;
99

1010
class Profile extends BaseClient
1111
{

0 commit comments

Comments
 (0)