Skip to content

Commit 4b2a5bd

Browse files
committed
Refactor GuzzleClient
The underlying GuzzleClient is marked as final since now around 5 years. Actually i completely missed that and therefore our GuzzleClient broke phpstan. The "new" GuzzleClient nolonger extends the old one. It is now simply a wrapper (passing call calls to the GuzzleClient)
1 parent 91a7083 commit 4b2a5bd

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/Clients/GuzzleClient.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,29 @@
55
use GuzzleHttp\Client;
66
use LKDev\HetznerCloud\HetznerAPIClient;
77

8-
class GuzzleClient extends Client
8+
class GuzzleClient
99
{
10+
protected Client $client;
11+
1012
/**
11-
* @param HetznerAPIClient $client
12-
* @param array $additionalGuzzleConfig
13+
* @param HetznerAPIClient $client
14+
* @param array $additionalGuzzleConfig
1315
*/
1416
public function __construct(HetznerAPIClient $client, $additionalGuzzleConfig = [])
1517
{
1618
$guzzleConfig = array_merge([
1719
'base_uri' => $client->getBaseUrl(),
1820
'headers' => [
19-
'Authorization' => 'Bearer '.$client->getApiToken(),
21+
'Authorization' => 'Bearer ' . $client->getApiToken(),
2022
'Content-Type' => 'application/json',
21-
'User-Agent' => ((strlen($client->getUserAgent()) > 0) ? $client->getUserAgent().' ' : '').'hcloud-php/'.HetznerAPIClient::VERSION,
23+
'User-Agent' => ((strlen($client->getUserAgent()) > 0) ? $client->getUserAgent() . ' ' : '') . 'hcloud-php/' . HetznerAPIClient::VERSION,
2224
],
2325
], $additionalGuzzleConfig);
24-
parent::__construct($guzzleConfig);
26+
$this->client = new Client($guzzleConfig);
27+
}
28+
29+
public function __call($name, $arguments)
30+
{
31+
return $this->client->$name(...$arguments);
2532
}
2633
}

src/Models/PlacementGroups/PlacementGroup.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace LKDev\HetznerCloud\Models\PlacementGroups;
44

5+
use GuzzleHttp\Client;
56
use LKDev\HetznerCloud\APIResponse;
67
use LKDev\HetznerCloud\HetznerAPIClient;
78
use LKDev\HetznerCloud\Models\Actions\Action;

0 commit comments

Comments
 (0)