From bdb38793e0bb190dc73fd7a3716fd15089e4bcf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20K=C3=A4mmerling?= Date: Mon, 29 Jan 2018 11:44:56 +0100 Subject: [PATCH] Implement Examples & Bugfixing --- examples/bootstrap.php | 5 +++ examples/servers/get_a_specifc_server.php | 7 ++++ examples/servers/get_all_server_types.php | 8 ++++ examples/servers/get_all_servers.php | 7 ++++ examples/servers/toggle_a_server.php | 27 +++++++++++++ src/HetznerAPIClient.php | 8 +++- src/Models/Actions/Action.php | 18 +++++---- src/Models/Actions/Actions.php | 8 ++-- src/Models/Datacenters/Datacenter.php | 11 +++-- src/Models/Datacenters/Datacenters.php | 8 ++-- src/Models/FloatingIps/FloatingIp.php | 1 + src/Models/FloatingIps/FloatingIps.php | 1 + src/Models/ISOs/ISO.php | 12 ++++-- src/Models/ISOs/ISOs.php | 8 ++-- src/Models/Images/Image.php | 33 ++++++++------- src/Models/Images/Images.php | 8 ++-- src/Models/Locations/Location.php | 9 +++-- src/Models/Locations/Locations.php | 8 ++-- src/Models/Model.php | 6 +-- src/Models/SSHKeys/SSHKey.php | 4 +- src/Models/SSHKeys/SSHKeys.php | 8 ++-- src/Models/Servers/Server.php | 49 ++++++++++++----------- src/Models/Servers/Servers.php | 13 +++--- src/Models/Servers/Types/ServerType.php | 10 ++--- src/Models/Servers/Types/ServerTypes.php | 10 ++--- 25 files changed, 185 insertions(+), 102 deletions(-) create mode 100644 examples/bootstrap.php create mode 100644 examples/servers/get_a_specifc_server.php create mode 100644 examples/servers/get_all_server_types.php create mode 100644 examples/servers/get_all_servers.php create mode 100644 examples/servers/toggle_a_server.php diff --git a/examples/bootstrap.php b/examples/bootstrap.php new file mode 100644 index 0000000..35852fb --- /dev/null +++ b/examples/bootstrap.php @@ -0,0 +1,5 @@ +get($serverId); +var_dump($server); \ No newline at end of file diff --git a/examples/servers/get_all_server_types.php b/examples/servers/get_all_server_types.php new file mode 100644 index 0000000..a6f32df --- /dev/null +++ b/examples/servers/get_all_server_types.php @@ -0,0 +1,8 @@ +all() as $serverType) { + echo $serverType->name.PHP_EOL; +} \ No newline at end of file diff --git a/examples/servers/get_all_servers.php b/examples/servers/get_all_servers.php new file mode 100644 index 0000000..48698d6 --- /dev/null +++ b/examples/servers/get_all_servers.php @@ -0,0 +1,7 @@ +all() as $server) { + echo 'ID: '.$server->id.' Name:'.$server->name.' Status: '.$server->status.PHP_EOL; +} \ No newline at end of file diff --git a/examples/servers/toggle_a_server.php b/examples/servers/toggle_a_server.php new file mode 100644 index 0000000..b13f702 --- /dev/null +++ b/examples/servers/toggle_a_server.php @@ -0,0 +1,27 @@ +get($serverId); +echo 'Server: '.$server->name.PHP_EOL; +echo "Perform Shutdown now:".PHP_EOL; +/** + * @var \LKDev\HetznerCloud\Models\Servers\Server $server + */ +$action = $server->shutdown(); + +echo "Reply from API: Action ID: ".$action->id.' '.$action->command.' '.$action->started.PHP_EOL; + +echo 'Wait some seconds that the server could shutdown.'.PHP_EOL; +sleep(5); +echo "Get the Server from the API:".PHP_EOL; +$server = $servers->get($serverId); +echo "Server status: ".$server->status.PHP_EOL; +echo "Let's start it again!"; +$server->powerOn(); +echo 'Wait some seconds that the server could startup.'.PHP_EOL; +sleep(5); +echo "Get the Server from the API:".PHP_EOL; +$server = $servers->get($serverId); +echo "Server status: ".$server->status.PHP_EOL; diff --git a/src/HetznerAPIClient.php b/src/HetznerAPIClient.php index 1c9df04..950118f 100644 --- a/src/HetznerAPIClient.php +++ b/src/HetznerAPIClient.php @@ -39,6 +39,7 @@ class HetznerAPIClient public function __construct(string $apiToken, $baseUrl = 'https://api.hetzner.cloud/v1/') { $this->apiToken = $apiToken; + $this->baseUrl = $baseUrl; self::$hetznerApiClient = $this; self::$httpClient = new GuzzleClient($this); } @@ -65,7 +66,9 @@ public function getBaseUrl(): string */ public static function throwError(ResponseInterface $response) { - throw new APIException($response); + var_dump(json_decode((string) $response->getBody())); + die(); + // throw new APIException($response, ->error->code); } /** @@ -75,8 +78,9 @@ public static function throwError(ResponseInterface $response) */ public static function hasError(ResponseInterface $response) { - if (property_exists($response, 'error') || $response->getStatusCode() !== 200) { + if ((property_exists($response, 'error')) || ($response->getStatusCode() <= 200 && $response->getStatusCode() >= 300)) { self::throwError($response); + return true; } diff --git a/src/Models/Actions/Action.php b/src/Models/Actions/Action.php index 3bea88f..84665a7 100644 --- a/src/Models/Actions/Action.php +++ b/src/Models/Actions/Action.php @@ -40,7 +40,7 @@ class Action extends Model public $resources; /** - * @var object|null + * @var |null */ public $error; @@ -58,7 +58,7 @@ class Action extends Model * @param string $started * @param string $finished * @param array $resources - * @param null|object $error + * @param null| $error */ public function __construct( int $id, @@ -66,8 +66,8 @@ public function __construct( int $progress, string $started, string $finished, - array $resources, - object $error, + array $resources = null, + $error = null, string $root_password = null ) { $this->id = $id; @@ -82,11 +82,15 @@ public function __construct( } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\Actions\Action|static */ - public static function parse(object $input) + public static function parse($input) { - return new self($input->id, $input->command, $input->status, $input->started, $input->finished, $input->resources, $input->error, $input->root_password); + if ($input == null) { + return null; + } + + return new self($input->id, $input->command, $input->progress, $input->status, $input->started, $input->finished, $input->resources, $input->error, (property_exists($input, 'root_password') ? $input->root_password : null)); } } \ No newline at end of file diff --git a/src/Models/Actions/Actions.php b/src/Models/Actions/Actions.php index 380680a..52d6725 100644 --- a/src/Models/Actions/Actions.php +++ b/src/Models/Actions/Actions.php @@ -58,10 +58,10 @@ public function get($actionId): Action } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->actions = collect($input->actions)->map(function ($action, $key) { return Action::parse($action); @@ -71,10 +71,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse($input) { return (new self())->setAdditionalData($input); } diff --git a/src/Models/Datacenters/Datacenter.php b/src/Models/Datacenters/Datacenter.php index 571fc6c..55f2432 100644 --- a/src/Models/Datacenters/Datacenter.php +++ b/src/Models/Datacenters/Datacenter.php @@ -61,8 +61,8 @@ public function __construct( string $name, string $description, Location $location, - array $server_types, - bool $recommendation + array $server_types = null, + bool $recommendation = null ) { $this->id = $id; $this->name = $name; @@ -74,11 +74,14 @@ public function __construct( } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\Datacenters\Datacenter|static */ - public static function parse(object $input) + public static function parse($input) { + if ($input == null) { + return null; + } return new self($input->id,$input->name,$input->description,Location::parse($input->location),$input->server_types,$input->recommendation); } } \ No newline at end of file diff --git a/src/Models/Datacenters/Datacenters.php b/src/Models/Datacenters/Datacenters.php index 66878cf..9bfe1a5 100644 --- a/src/Models/Datacenters/Datacenters.php +++ b/src/Models/Datacenters/Datacenters.php @@ -50,10 +50,10 @@ public function get(int $datacenterId): Datacenter } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->locations = collect($input->datacenters)->map(function ($datacenter, $key) { return Datacenter::parse($datacenter); @@ -63,10 +63,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse($input) { return (new self())->setAdditionalData($input); } diff --git a/src/Models/FloatingIps/FloatingIp.php b/src/Models/FloatingIps/FloatingIp.php index 23e5d3a..de70bdf 100644 --- a/src/Models/FloatingIps/FloatingIp.php +++ b/src/Models/FloatingIps/FloatingIp.php @@ -10,4 +10,5 @@ class FloatingIp { + // ToDo } \ No newline at end of file diff --git a/src/Models/FloatingIps/FloatingIps.php b/src/Models/FloatingIps/FloatingIps.php index 28e2f88..e28b3ae 100644 --- a/src/Models/FloatingIps/FloatingIps.php +++ b/src/Models/FloatingIps/FloatingIps.php @@ -10,4 +10,5 @@ class FloatingIps { + // ToDos } \ No newline at end of file diff --git a/src/Models/ISOs/ISO.php b/src/Models/ISOs/ISO.php index de11047..0ac076a 100644 --- a/src/Models/ISOs/ISO.php +++ b/src/Models/ISOs/ISO.php @@ -37,7 +37,7 @@ class ISO extends Model * @param string $description * @param string $type */ - public function __construct(int $id, string $name, string $description, string $type) + public function __construct(int $id = null, string $name = null, string $description = null, string $type = null) { $this->id = $id; $this->name = $name; @@ -47,11 +47,15 @@ public function __construct(int $id, string $name, string $description, string $ } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\ISOs\ISO|static */ - public static function parse(object $input) + public static function parse($input) { - return new self($input->id,$input->name,$input->description,$input->type); + if ($input == null) { + return null; + } + + return new self($input->id, $input->name, $input->description, $input->type); } } \ No newline at end of file diff --git a/src/Models/ISOs/ISOs.php b/src/Models/ISOs/ISOs.php index 4f120a3..d8249be 100644 --- a/src/Models/ISOs/ISOs.php +++ b/src/Models/ISOs/ISOs.php @@ -50,10 +50,10 @@ public function get(int $isoId): ISO } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->locations = collect($input->isos)->map(function ($iso, $key) { return ISO::parse($iso); @@ -63,10 +63,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse($input) { return (new self())->setAdditionalData($input); } diff --git a/src/Models/Images/Image.php b/src/Models/Images/Image.php index e8dbd9c..25f5e9b 100644 --- a/src/Models/Images/Image.php +++ b/src/Models/Images/Image.php @@ -101,18 +101,18 @@ class Image extends Model */ public function __construct( int $id, - string $type, - string $status, - string $name, - string $description, - float $imageSize, - int $diskSize, - string $created, - Server $createdFrom, - int $boundTo, - string $osFlavor, - string $osVersion, - bool $rapidDeploy + string $type = null, + string $status = null, + string $name = null, + string $description = null, + float $imageSize = null, + int $diskSize = null, + string $created = null, + Server $createdFrom = null, + int $boundTo = null, + string $osFlavor = null, + string $osVersion = null, + bool $rapidDeploy = null ) { $this->id = $id; $this->type = $type; @@ -168,11 +168,14 @@ public function delete(): bool } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\Images\Image|static */ - public static function parse(object $input) + public static function parse($input) { - return new self($input->id, $input->type, $input->status, $input->name, $input->description, $input->image_size, $input->disk_size, $input->created, Server::parse($input->created_from), $input->bound_to, $input->os_flavor, $input->os_version, $input->rapid_deploy); + if ($input == null) { + return null; + } + return new self($input->id, $input->type, $input->status, $input->name, $input->description, $input->image_size, $input->disk_size, $input->created, $input->created_from, $input->bound_to, $input->os_flavor, $input->os_version, $input->rapid_deploy); } } \ No newline at end of file diff --git a/src/Models/Images/Images.php b/src/Models/Images/Images.php index 8743354..7e3d846 100644 --- a/src/Models/Images/Images.php +++ b/src/Models/Images/Images.php @@ -49,10 +49,10 @@ public function get(int $imageId): Image } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->images = collect($input->images)->map(function ($image, $key) { return Image::parse($image); @@ -62,10 +62,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse($input) { return (new self())->setAdditionalData($input); } diff --git a/src/Models/Locations/Location.php b/src/Models/Locations/Location.php index 4af5245..c734004 100644 --- a/src/Models/Locations/Location.php +++ b/src/Models/Locations/Location.php @@ -81,11 +81,14 @@ public function __construct( } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\Locations\Location|static */ - public static function parse(object $input) + public static function parse($input) { - return new self($input->id, $input->name, $input->description, $input->city, $input->latitude, $input->longitude); + if ($input == null) { + return null; + } + return new self($input->id, $input->name, $input->description, $input->country, $input->city, $input->latitude, $input->longitude); } } \ No newline at end of file diff --git a/src/Models/Locations/Locations.php b/src/Models/Locations/Locations.php index 061042d..c07aea6 100644 --- a/src/Models/Locations/Locations.php +++ b/src/Models/Locations/Locations.php @@ -53,10 +53,10 @@ public function get(int $locationId): Location } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->locations = collect($input->locations)->map(function ($location, $key) { return Location::parse($location); @@ -66,10 +66,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse($input) { return (new self())->setAdditionalData($input); } diff --git a/src/Models/Model.php b/src/Models/Model.php index 13b218a..172ebf1 100644 --- a/src/Models/Model.php +++ b/src/Models/Model.php @@ -8,7 +8,7 @@ /** * */ -class Model +abstract class Model { /** * @var \LKDev\HetznerCloud\HetznerAPIClient @@ -33,8 +33,8 @@ public function __construct() } /** - * @param object $input + * @param $input * @return static */ - abstract public static function parse(object $input); + abstract public static function parse($input); } \ No newline at end of file diff --git a/src/Models/SSHKeys/SSHKey.php b/src/Models/SSHKeys/SSHKey.php index a656d55..3fd8879 100644 --- a/src/Models/SSHKeys/SSHKey.php +++ b/src/Models/SSHKeys/SSHKey.php @@ -87,10 +87,10 @@ public function delete():bool } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\SSHKeys\SSHKey|static */ - public static function parse(object $input) + public static function parse( $input) { return new self($input->id, $input->name, $input->fingerprint, $input->public_key); } diff --git a/src/Models/SSHKeys/SSHKeys.php b/src/Models/SSHKeys/SSHKeys.php index 2265522..ccf2472 100644 --- a/src/Models/SSHKeys/SSHKeys.php +++ b/src/Models/SSHKeys/SSHKeys.php @@ -50,10 +50,10 @@ public function get(int $sshKeyId): SSHKey{ } } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->sshKeys = collect($input->ssh_keys)->map(function ($sshKey, $key) { return SSHKey::parse($sshKey); @@ -62,10 +62,10 @@ public function setAdditionalData(object $input) return $this; } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse( $input) { return (new self())->setAdditionalData($input); } diff --git a/src/Models/Servers/Server.php b/src/Models/Servers/Server.php index 111f4b3..d26a939 100644 --- a/src/Models/Servers/Server.php +++ b/src/Models/Servers/Server.php @@ -116,10 +116,10 @@ public function setAdditionalData($data) $this->name = $data->name; $this->status = $data->status; $this->publicNet = $data->public_net; - $this->serverType = ServerType::parse($data->server_type); - $this->datacenter = Datacenter::parse($data->datacenter); - $this->image = Image::parse($data->image); - $this->iso = ISO::parse($data->iso); + $this->serverType = $data->server_type ?: ServerType::parse($data->server_type); + $this->datacenter = $data->datacenter ?: Datacenter::parse($data->datacenter); + $this->image = $data->image ?: Image::parse($data->image); + $this->iso = $data->iso ?: ISO::parse($data->iso); $this->rescueEnabled = $data->rescue_enabled; $this->locked = $data->locked; $this->backupWindow = $data->backup_window; @@ -140,7 +140,7 @@ public function powerOn(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/poweron')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -155,7 +155,7 @@ public function softReboot(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reboot')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -170,7 +170,7 @@ public function reset(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -185,7 +185,7 @@ public function shutdown(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/shutdown')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -200,7 +200,7 @@ public function powerOff(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/powerOff')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -215,7 +215,7 @@ public function resetRootPassword(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/reset_password')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -237,7 +237,7 @@ public function enableRescue($type = 'linux64', $ssh_keys = []): Action ], ]); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -252,7 +252,7 @@ public function disableRescue(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_rescue')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -295,7 +295,7 @@ public function rebuildFromImage(Image $image): Action ], ]); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -317,7 +317,7 @@ public function changeType(ServerType $serverType, bool $upgradeDisk = false): A ], ]); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -337,7 +337,7 @@ public function enableBackups(string $backupWindow = null): Action ], ]); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -352,7 +352,7 @@ public function disableBackups(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/disable_backup')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -372,7 +372,7 @@ public function attachISO(ISO $iso): Action ], ]); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -387,7 +387,7 @@ public function detachISO(): Action { $response = $this->httpClient->post($this->replaceServerIdInUri('servers/{id}/actions/detach_iso')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -409,7 +409,7 @@ public function changeReverseDNS(string $ip, string $dnsPtr): Action ], ]); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -439,7 +439,7 @@ public function delete(): Action { $response = $this->httpClient->delete($this->replaceServerIdInUri('servers/{id}')); if (! HetznerAPIClient::hasError($response)) { - return Action::parse(json_decode((string) $response->getBody()->action)); + return Action::parse(json_decode((string) $response->getBody())->action); } } @@ -459,7 +459,7 @@ public function changeName(string $name): Server ], ]); if (! HetznerAPIClient::hasError($response)) { - return Server::parse(json_decode((string) $response->getBody()->server)); + return Server::parse(json_decode((string) $response->getBody())->server); } } @@ -473,11 +473,14 @@ protected function replaceServerIdInUri(string $uri): string } /** - * @param object $input + * @param $input * @return \LKDev\HetznerCloud\Models\Servers\Server|static */ - public static function parse(object $input) + public static function parse($input) { + if ($input == null) { + return null; + } return (new self($input->id))->setAdditionalData($input); } } \ No newline at end of file diff --git a/src/Models/Servers/Servers.php b/src/Models/Servers/Servers.php index 23215be..7ce8984 100644 --- a/src/Models/Servers/Servers.php +++ b/src/Models/Servers/Servers.php @@ -99,24 +99,27 @@ public function create( } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData($input) { $this->servers = collect($input->servers)->map(function ($server, $key) { - return Server::parse($server); + if ($server != null) { + return Server::parse($server); + } })->toArray(); return $this; } /** - * @param object $input + * @param $input * @return static */ - public static function parse(object $input) + public static function parse($input) { + return (new self())->setAdditionalData($input); } } \ No newline at end of file diff --git a/src/Models/Servers/Types/ServerType.php b/src/Models/Servers/Types/ServerType.php index 114e4a3..fa3d80c 100644 --- a/src/Models/Servers/Types/ServerType.php +++ b/src/Models/Servers/Types/ServerType.php @@ -62,13 +62,13 @@ public function __construct(int $serverTypeId) } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData($input) { $this->name = $input->name; - $this->description = $input->descripton; + $this->description = $input->description; $this->cores = $input->cores; $this->memory = $input->memory; $this->disk = $input->disk; @@ -79,10 +79,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return self */ - public static function parse(object $input) + public static function parse( $input) { return (new self($input->id))->setAdditionalData($input); } diff --git a/src/Models/Servers/Types/ServerTypes.php b/src/Models/Servers/Types/ServerTypes.php index 479bf34..42f2a59 100644 --- a/src/Models/Servers/Types/ServerTypes.php +++ b/src/Models/Servers/Types/ServerTypes.php @@ -29,7 +29,7 @@ public function all(): array { $response = $this->httpClient->get('server_types'); if (! HetznerAPIClient::hasError($response)) { - return self::parse(json_decode((string) $response->getBody())); + return self::parse(json_decode((string) $response->getBody()))->serverTypes; } } @@ -47,10 +47,10 @@ public function get(int $serverTypeId): ServerType } /** - * @param object $input + * @param $input * @return $this */ - public function setAdditionalData(object $input) + public function setAdditionalData( $input) { $this->serverTypes = collect($input->server_types)->map(function ($serverType, $key) { return ServerType::parse($serverType); @@ -60,10 +60,10 @@ public function setAdditionalData(object $input) } /** - * @param object $input + * @param $input * @return $this|static */ - public static function parse(object $input) + public static function parse( $input) { return (new self())->setAdditionalData($input); }