Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/HetznerAPIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class HetznerAPIClient
/**
* @var \LKDev\HetznerCloud\Clients\GuzzleClient
*/
protected $httpClient;
protected GuzzleClient $httpClient;

/**
* @param string $apiToken
Expand Down Expand Up @@ -123,17 +123,17 @@ public function setBaseUrl(string $baseUrl): self
}

/**
* @return Client
* @return GuzzleClient
*/
public function getHttpClient(): Client
public function getHttpClient(): GuzzleClient
{
return $this->httpClient;
}

/**
* @return Client
* @return GuzzleClient
*/
public function setHttpClient(Client $client): self
public function setHttpClient(GuzzleClient $client): self
{
$this->httpClient = $client;

Expand Down
11 changes: 6 additions & 5 deletions src/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
namespace LKDev\HetznerCloud\Models;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;

abstract class Model
{
/**
* @var \GuzzleHttp\Client
* @var GuzzleClient
*/
protected $httpClient;

/**
* Model constructor.
*
* @param Client $httpClient
* @param GuzzleClient $httpClient
*/
public function __construct(?Client $httpClient = null)
public function __construct(?GuzzleClient $httpClient = null)
{
$this->httpClient = $httpClient == null ? HetznerAPIClient::$instance->getHttpClient() : $httpClient;
}
Expand All @@ -34,9 +35,9 @@ public static function parse($input)
/**
* Replaces or sets the http client.
*
* @param Client $httpClient
* @param GuzzleClient $httpClient
*/
public function setHttpClient(?Client $httpClient = null)
public function setHttpClient(?GuzzleClient $httpClient = null)
{
$this->httpClient = $httpClient;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Networks/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace LKDev\HetznerCloud\Models\Networks;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\APIResponse;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Actions\Action;
use LKDev\HetznerCloud\Models\Contracts\Resource;
Expand Down Expand Up @@ -71,9 +71,9 @@ class Network extends Model implements Resource
* Network constructor.
*
* @param int $id
* @param Client|null $httpClient
* @param GuzzleClient|null $httpClient
*/
public function __construct(int $id, ?Client $httpClient = null)
public function __construct(int $id, ?GuzzleClient $httpClient = null)
{
$this->id = $id;
parent::__construct($httpClient);
Expand Down
10 changes: 5 additions & 5 deletions src/Models/Networks/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LKDev\HetznerCloud\Models\Networks;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\Models\Model;

/**
Expand All @@ -24,9 +24,9 @@ class Route extends Model
*
* @param string $destination
* @param string $gateway
* @param Client|null $client
* @param GuzzleClient|null $client
*/
public function __construct(string $destination, string $gateway, ?Client $client = null)
public function __construct(string $destination, string $gateway, ?GuzzleClient $client = null)
{
$this->destination = $destination;
$this->gateway = $gateway;
Expand All @@ -35,10 +35,10 @@ public function __construct(string $destination, string $gateway, ?Client $clien

/**
* @param $input
* @param Client|null $client
* @param GuzzleClient|null $client
* @return array|Model
*/
public static function parse($input, ?Client $client = null)
public static function parse($input, ?GuzzleClient $client = null)
{
return collect($input)->map(function ($route) use ($client) {
return new self($route->destination, $route->gateway, $client);
Expand Down
10 changes: 5 additions & 5 deletions src/Models/Networks/Subnet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace LKDev\HetznerCloud\Models\Networks;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\Models\Model;

/**
Expand Down Expand Up @@ -36,9 +36,9 @@ class Subnet extends Model
* @param string $ipRange
* @param string $networkZone
* @param string $gateway
* @param Client|null $client
* @param GuzzleClient|null $client
*/
public function __construct(string $type, string $ipRange, string $networkZone, ?string $gateway = null, ?Client $client = null)
public function __construct(string $type, string $ipRange, string $networkZone, ?string $gateway = null, ?GuzzleClient $client = null)
{
$this->type = $type;
$this->ipRange = $ipRange;
Expand All @@ -49,10 +49,10 @@ public function __construct(string $type, string $ipRange, string $networkZone,

/**
* @param $input
* @param Client|null $client
* @param GuzzleClient|null $client
* @return array|Model
*/
public static function parse($input, ?Client $client = null)
public static function parse($input, ?GuzzleClient $client = null)
{
return collect($input)->map(function ($subnet) use ($client) {
return new self($subnet->type, $subnet->ip_range, $subnet->network_zone, $subnet->gateway, $client);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/PlacementGroups/PlacementGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace LKDev\HetznerCloud\Models\PlacementGroups;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\APIResponse;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Actions\Action;
use LKDev\HetznerCloud\Models\Contracts\Resource;
Expand Down Expand Up @@ -49,9 +49,9 @@ class PlacementGroup extends Model implements Resource
* PlacementGroup constructor.
*
* @param int $id
* @param Client|null $httpClient
* @param GuzzleClient|null $httpClient
*/
public function __construct(int $id, ?Client $httpClient = null)
public function __construct(int $id, ?GuzzleClient $httpClient = null)
{
$this->id = $id;
parent::__construct($httpClient);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Servers/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace LKDev\HetznerCloud\Models\Servers;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\APIResponse;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Actions\Action;
use LKDev\HetznerCloud\Models\Contracts\Resource;
Expand Down Expand Up @@ -180,9 +180,9 @@ class Server extends Model implements Resource

/**
* @param int $serverId
* @param Client|null $httpClient
* @param GuzzleClient|null $httpClient
*/
public function __construct(int $serverId, ?Client $httpClient = null)
public function __construct(int $serverId, ?GuzzleClient $httpClient = null)
{
$this->id = $serverId;
parent::__construct($httpClient);
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Volumes/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace LKDev\HetznerCloud\Models\Volumes;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\APIResponse;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Actions\Action;
use LKDev\HetznerCloud\Models\Contracts\Resource;
Expand Down Expand Up @@ -65,9 +65,9 @@ class Volume extends Model implements Resource

/**
* @param int $volumeId
* @param Client|null $httpClient
* @param GuzzleClient|null $httpClient
*/
public function __construct(?int $volumeId = null, ?Client $httpClient = null)
public function __construct(?int $volumeId = null, ?GuzzleClient $httpClient = null)
{
$this->id = $volumeId;
parent::__construct($httpClient);
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace LKDev\Tests;

use GuzzleHttp\Client;
use GuzzleHttp\Handler\MockHandler;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;

abstract class TestCase extends \PHPUnit\Framework\TestCase
Expand All @@ -28,8 +28,8 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
public function setUp(): void
{
$this->mockHandler = new MockHandler();
$this->hetznerApi = new HetznerAPIClient('abcdef', 'http://localhost:4000/v1/');
$this->hetznerApi->setHttpClient(new Client(['handler' => $this->mockHandler]));
$this->hetznerApi = new HetznerAPIClient('abcdef', '');
$this->hetznerApi->setHttpClient(new GuzzleClient($this->hetznerApi, ['handler' => $this->mockHandler]));
}

public function tearDown(): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/BasicClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace LKDev\Tests\Unit;

use GuzzleHttp\Client;
use LKDev\HetznerCloud\Clients\GuzzleClient;
use LKDev\HetznerCloud\HetznerAPIClient;
use LKDev\HetznerCloud\Models\Actions\Actions;
use LKDev\HetznerCloud\Models\Datacenters\Datacenters;
Expand Down Expand Up @@ -61,7 +61,7 @@ public function testSetUserAgent()
public function testSetHttpClient()
{
$client = new HetznerAPIClient('IAmTheTestToken', '');
$httpClient = new Client();
$httpClient = new GuzzleClient($client);
$client->setHttpClient($httpClient);
$this->assertEquals($httpClient, $client->getHttpClient());
}
Expand Down