diff --git a/src/Models/DeprecationInfo.php b/src/Models/DeprecationInfo.php new file mode 100644 index 00000000..5f4ce591 --- /dev/null +++ b/src/Models/DeprecationInfo.php @@ -0,0 +1,36 @@ +announced = $announced; + $this->unavailableAfter = $unavailableAfter; + parent::__construct(); + } + + /** + * @param $input + * @return self|null + */ + public static function parse($input): ?self + { + if ($input === null) { + return null; + } + + return new self($input->announced, $input->unavailable_after); + } +} diff --git a/src/Models/Servers/Types/ServerType.php b/src/Models/Servers/Types/ServerType.php index 71851d6e..89aa0a62 100644 --- a/src/Models/Servers/Types/ServerType.php +++ b/src/Models/Servers/Types/ServerType.php @@ -2,6 +2,7 @@ namespace LKDev\HetznerCloud\Models\Servers\Types; +use LKDev\HetznerCloud\Models\DeprecationInfo; use LKDev\HetznerCloud\Models\Model; use LKDev\HetznerCloud\Models\Prices\Prices; use LKDev\HetznerCloud\Models\Prices\ServerTypePrice; @@ -63,6 +64,16 @@ class ServerType extends Model */ public $architecture; + /** + * @var bool + */ + public $deprecated; + + /** + * @var DeprecationInfo|null + */ + public $deprecation; + /** * ServerType constructor. * @@ -91,6 +102,8 @@ public function setAdditionalData($input) $this->storageType = $input->storage_type ?? null; $this->cpuType = $input->cpu_type ?? null; $this->architecture = property_exists($input, 'architecture') ? $input->architecture : null; + $this->deprecated = $input->deprecated ?? false; + $this->deprecation = property_exists($input, 'deprecation') ? DeprecationInfo::parse($input->deprecation) : null; return $this; } diff --git a/tests/Unit/Models/ServerTypes/fixtures/server_type.json b/tests/Unit/Models/ServerTypes/fixtures/server_type.json index e1940555..78b03dae 100644 --- a/tests/Unit/Models/ServerTypes/fixtures/server_type.json +++ b/tests/Unit/Models/ServerTypes/fixtures/server_type.json @@ -8,6 +8,7 @@ "memory": 1, "disk": 24, "deprecated": false, + "deprecation": null, "prices": [ { "location": "fsn1", diff --git a/tests/Unit/Models/ServerTypes/fixtures/server_types.json b/tests/Unit/Models/ServerTypes/fixtures/server_types.json index 00195102..77b5714f 100644 --- a/tests/Unit/Models/ServerTypes/fixtures/server_types.json +++ b/tests/Unit/Models/ServerTypes/fixtures/server_types.json @@ -9,6 +9,7 @@ "memory": 1, "disk": 24, "deprecated": false, + "deprecation": null, "prices": [ { "location": "fsn1", diff --git a/tests/Unit/Models/Servers/Types/ServerTypeTest.php b/tests/Unit/Models/Servers/Types/ServerTypeTest.php index 8614f7b6..5073ff9c 100644 --- a/tests/Unit/Models/Servers/Types/ServerTypeTest.php +++ b/tests/Unit/Models/Servers/Types/ServerTypeTest.php @@ -2,6 +2,7 @@ namespace LKDev\Tests\Unit\Models\Servers\Types; +use LKDev\HetznerCloud\Models\DeprecationInfo; use LKDev\HetznerCloud\Models\Prices\ServerTypePrice; use LKDev\HetznerCloud\Models\Servers\Types\ServerType; use LKDev\Tests\TestCase; @@ -22,6 +23,8 @@ public function testParse() $this->assertEquals('local', $serverType->storageType); $this->assertEquals('shared', $serverType->cpuType); $this->assertNull($serverType->architecture); + $this->assertFalse($serverType->deprecated); + $this->assertNull($serverType->deprecation); $inputWithPrice = $tmp->server->server_type; $inputWithPrice->price = $inputWithPrice->prices[0]; @@ -29,4 +32,31 @@ public function testParse() $this->assertInstanceOf(ServerTypePrice::class, $serverTypeWithPrice->price); $this->assertEquals('fsn1', $serverTypeWithPrice->price->location); } + + public function testParseWithDeprecation() + { + $input = json_decode('{ + "id": 2, + "name": "cx11-ceph", + "description": "CX11 (Ceph)", + "cores": 1, + "memory": 1, + "disk": 25, + "deprecated": true, + "deprecation": { + "announced": "2023-06-01T00:00:00Z", + "unavailable_after": "2023-09-01T00:00:00Z" + }, + "prices": [], + "storage_type": "network", + "cpu_type": "shared", + "architecture": "x86" + }'); + + $serverType = ServerType::parse($input); + $this->assertTrue($serverType->deprecated); + $this->assertInstanceOf(DeprecationInfo::class, $serverType->deprecation); + $this->assertEquals('2023-06-01T00:00:00Z', $serverType->deprecation->announced); + $this->assertEquals('2023-09-01T00:00:00Z', $serverType->deprecation->unavailableAfter); + } }