Skip to content

Commit 3e6d535

Browse files
StyleCIBotLKaemmerling
authored andcommitted
Apply fixes from StyleCI
1 parent 939cbe0 commit 3e6d535

File tree

2 files changed

+60
-54
lines changed

2 files changed

+60
-54
lines changed

src/Models/Zones/Zone.php

Lines changed: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use LKDev\HetznerCloud\Models\Meta;
1212
use LKDev\HetznerCloud\Models\Model;
1313
use LKDev\HetznerCloud\Models\Protection;
14-
use LKDev\HetznerCloud\RequestOpts;
1514

1615
class Zone extends Model implements Resource
1716
{
@@ -75,8 +74,8 @@ class Zone extends Model implements Resource
7574
public AuthoritativeNameservers $authoritative_nameservers;
7675

7776
/**
78-
* @param int $zoneId
79-
* @param GuzzleClient|null $httpClient
77+
* @param int $zoneId
78+
* @param GuzzleClient|null $httpClient
8079
*/
8180
public function __construct(int $zoneId, ?GuzzleClient $httpClient = null)
8281
{
@@ -134,9 +133,9 @@ public function reload()
134133
public function delete(): ?APIResponse
135134
{
136135
$response = $this->httpClient->delete($this->replaceZoneIdInUri('zones/{id}'));
137-
if (!HetznerAPIClient::hasError($response)) {
136+
if (! HetznerAPIClient::hasError($response)) {
138137
return APIResponse::create([
139-
'action' => Action::parse(json_decode((string)$response->getBody())->action),
138+
'action' => Action::parse(json_decode((string) $response->getBody())->action),
140139
], $response->getHeaders());
141140
}
142141

@@ -148,7 +147,7 @@ public function delete(): ?APIResponse
148147
*
149148
* @see https://docs.hetzner.cloud/reference/cloud#zones-update-a-zone
150149
*
151-
* @param array $data
150+
* @param array $data
152151
* @return APIResponse|null
153152
*
154153
* @throws \LKDev\HetznerCloud\APIException
@@ -158,9 +157,9 @@ public function update(array $data)
158157
$response = $this->httpClient->put($this->replaceZoneIdInUri('zones/{id}'), [
159158
'json' => $data,
160159
]);
161-
if (!HetznerAPIClient::hasError($response)) {
160+
if (! HetznerAPIClient::hasError($response)) {
162161
return APIResponse::create([
163-
'zone' => self::parse(json_decode((string)$response->getBody())->zone),
162+
'zone' => self::parse(json_decode((string) $response->getBody())->zone),
164163
], $response->getHeaders());
165164
}
166165

@@ -172,21 +171,21 @@ public function update(array $data)
172171
*
173172
* @see https://docs.hetzner.cloud/#zone-actions-change-zone-protection
174173
*
175-
* @param bool $delete
174+
* @param bool $delete
176175
* @return APIResponse|null
177176
*
178177
* @throws \LKDev\HetznerCloud\APIException
179178
*/
180179
public function changeProtection(bool $delete = true): ?APIResponse
181180
{
182-
$response = $this->httpClient->post('zones/' . $this->id . '/actions/change_protection', [
181+
$response = $this->httpClient->post('zones/'.$this->id.'/actions/change_protection', [
183182
'json' => [
184183
'delete' => $delete,
185184
],
186185
]);
187-
if (!HetznerAPIClient::hasError($response)) {
186+
if (! HetznerAPIClient::hasError($response)) {
188187
return APIResponse::create([
189-
'action' => Action::parse(json_decode((string)$response->getBody())->action),
188+
'action' => Action::parse(json_decode((string) $response->getBody())->action),
190189
], $response->getHeaders());
191190
}
192191

@@ -195,10 +194,10 @@ public function changeProtection(bool $delete = true): ?APIResponse
195194

196195
public function exportZonefile(): ?APIResponse
197196
{
198-
$response = $this->httpClient->get('zones/' . $this->id . '/zonefile');
199-
if (!HetznerAPIClient::hasError($response)) {
197+
$response = $this->httpClient->get('zones/'.$this->id.'/zonefile');
198+
if (! HetznerAPIClient::hasError($response)) {
200199
return APIResponse::create([
201-
'zonefile' => json_decode((string)$response->getBody())->zonefile,
200+
'zonefile' => json_decode((string) $response->getBody())->zonefile,
202201
], $response->getHeaders());
203202
}
204203

@@ -207,14 +206,14 @@ public function exportZonefile(): ?APIResponse
207206

208207
public function changeTTL(int $ttl): ?APIResponse
209208
{
210-
$response = $this->httpClient->post('zones/' . $this->id . '/actions/change_ttl', [
209+
$response = $this->httpClient->post('zones/'.$this->id.'/actions/change_ttl', [
211210
'json' => [
212211
'ttl' => $ttl,
213212
],
214213
]);
215-
if (!HetznerAPIClient::hasError($response)) {
214+
if (! HetznerAPIClient::hasError($response)) {
216215
return APIResponse::create([
217-
'action' => Action::parse(json_decode((string)$response->getBody())->action),
216+
'action' => Action::parse(json_decode((string) $response->getBody())->action),
218217
], $response->getHeaders());
219218
}
220219

@@ -223,22 +222,22 @@ public function changeTTL(int $ttl): ?APIResponse
223222

224223
public function importZonefile(string $zonefile): ?APIResponse
225224
{
226-
$response = $this->httpClient->post('zones/' . $this->id . '/actions/import_zonefile', [
225+
$response = $this->httpClient->post('zones/'.$this->id.'/actions/import_zonefile', [
227226
'json' => [
228227
'zonefile' => $zonefile,
229228
],
230229
]);
231-
if (!HetznerAPIClient::hasError($response)) {
230+
if (! HetznerAPIClient::hasError($response)) {
232231
return APIResponse::create([
233-
'action' => Action::parse(json_decode((string)$response->getBody())->action),
232+
'action' => Action::parse(json_decode((string) $response->getBody())->action),
234233
], $response->getHeaders());
235234
}
236235

237236
return null;
238237
}
239238

240239
/**
241-
* @param string $uri
240+
* @param string $uri
242241
* @return string
243242
*/
244243
protected function replaceZoneIdInUri(string $uri): string
@@ -260,29 +259,31 @@ public static function parse($input)
260259
}
261260

262261
/**
263-
* @param array<PrimaryNameserver> $primary_nameservers
262+
* @param array<PrimaryNameserver> $primary_nameservers
264263
* @return void#
264+
*
265265
* @throws APIException
266266
*/
267267
public function changePrimaryNameservers(array $primary_nameservers)
268268
{
269-
$response = $this->httpClient->post('zones/' . $this->id . '/actions/change_primary_nameservers', [
269+
$response = $this->httpClient->post('zones/'.$this->id.'/actions/change_primary_nameservers', [
270270
'json' => [
271271
'primary_nameservers' => $primary_nameservers,
272272
],
273273
]);
274-
if (!HetznerAPIClient::hasError($response)) {
274+
if (! HetznerAPIClient::hasError($response)) {
275275
return APIResponse::create([
276-
'action' => Action::parse(json_decode((string)$response->getBody())->action),
276+
'action' => Action::parse(json_decode((string) $response->getBody())->action),
277277
], $response->getHeaders());
278278
}
279279

280280
return null;
281281
}
282282

283283
/**
284-
* @param RRSetRequestOpts|null $requestOpts
284+
* @param RRSetRequestOpts|null $requestOpts
285285
* @return array<RRSet>
286+
*
286287
* @throws APIException
287288
*/
288289
public function allRRSets(?RRSetRequestOpts $requestOpts = null): array
@@ -306,22 +307,24 @@ public function allRRSets(?RRSetRequestOpts $requestOpts = null): array
306307
}
307308

308309
/**
309-
* @param RRSetRequestOpts|null $requestOpts
310+
* @param RRSetRequestOpts|null $requestOpts
310311
* @return APIResponse|null
312+
*
311313
* @throws \LKDev\HetznerCloud\APIException
312314
*/
313315
public function listRRSets(?RRSetRequestOpts $requestOpts = null): ?APIResponse
314316
{
315317
if ($requestOpts == null) {
316318
$requestOpts = new RRSetRequestOpts();
317319
}
318-
$response = $this->httpClient->get('zones/' . $this->id . "/rrsets" . $requestOpts->buildQuery());
319-
if (!HetznerAPIClient::hasError($response)) {
320-
$resp = json_decode((string)$response->getBody());
320+
$response = $this->httpClient->get('zones/'.$this->id.'/rrsets'.$requestOpts->buildQuery());
321+
if (! HetznerAPIClient::hasError($response)) {
322+
$resp = json_decode((string) $response->getBody());
321323
$rrsets = [];
322324
foreach ($resp->rrsets as $rrset) {
323325
$rrsets[] = RRSet::fromResponse(get_object_vars($rrset));
324326
}
327+
325328
return APIResponse::create([
326329
'meta' => Meta::parse($resp->meta),
327330
'rrsets' => $rrsets,
@@ -332,12 +335,13 @@ public function listRRSets(?RRSetRequestOpts $requestOpts = null): ?APIResponse
332335
}
333336

334337
/**
335-
* @param string $name
336-
* @param string $type
337-
* @param array<Record> $records
338-
* @param int|null $ttl
339-
* @param array|null $labels
338+
* @param string $name
339+
* @param string $type
340+
* @param array<Record> $records
341+
* @param int|null $ttl
342+
* @param array|null $labels
340343
* @return void
344+
*
341345
* @throws APIException
342346
*/
343347
public function createRRSet(string $name, string $type, array $records, ?int $ttl = null, ?array $labels = [])
@@ -350,16 +354,16 @@ public function createRRSet(string $name, string $type, array $records, ?int $tt
350354
if ($ttl !== null) {
351355
$parameters['ttl'] = $ttl;
352356
}
353-
if (!empty($labels)) {
357+
if (! empty($labels)) {
354358
$parameters['labels'] = $labels;
355359
}
356360

357-
$response = $this->httpClient->post('zones/' . $this->id . '/rrsets', [
361+
$response = $this->httpClient->post('zones/'.$this->id.'/rrsets', [
358362
'json' => $parameters,
359363
]);
360364

361-
if (!HetznerAPIClient::hasError($response)) {
362-
$payload = json_decode((string)$response->getBody());
365+
if (! HetznerAPIClient::hasError($response)) {
366+
$payload = json_decode((string) $response->getBody());
363367

364368
return APIResponse::create([
365369
'action' => Action::parse($payload->action),

tests/Unit/Models/Zones/ZoneTest.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function setUp(): void
2121
parent::setUp();
2222
$tmp = new Zones($this->hetznerApi->getHttpClient());
2323

24-
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/zone.json')));
24+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__.'/fixtures/zone.json')));
2525
$this->zone = $tmp->getById(4711);
2626
}
2727

@@ -38,15 +38,15 @@ public function testDelete()
3838

3939
public function testUpdate()
4040
{
41-
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/zone.json')));
41+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__.'/fixtures/zone.json')));
4242
$this->zone->update(['name' => 'new-name']);
4343
$this->assertLastRequestEquals('PUT', '/zones/4711');
4444
$this->assertLastRequestBodyParametersEqual(['name' => 'new-name']);
4545
}
4646

4747
public function testChangeProtection()
4848
{
49-
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/zone_action_change_protection.json')));
49+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__.'/fixtures/zone_action_change_protection.json')));
5050
$apiResponse = $this->zone->changeProtection(true);
5151
$this->assertEquals('change_protection', $apiResponse->action->command);
5252
$this->assertEquals($this->zone->id, $apiResponse->action->resources[0]->id);
@@ -92,38 +92,40 @@ public function testTestChangePrimaryNameservers()
9292

9393
public function testExportZonefile()
9494
{
95-
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/zone_zonefile.json')));
95+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__.'/fixtures/zone_zonefile.json')));
9696
$apiResponse = $this->zone->exportZonefile();
9797
$this->assertNotEmpty($apiResponse->zonefile);
9898
$this->assertLastRequestEquals('GET', '/zones/4711/zonefile');
9999
}
100+
100101
public function testAllRRSets()
101102
{
102-
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/zone_rrsets.json')));
103+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__.'/fixtures/zone_rrsets.json')));
103104
$rrsets = $this->zone->allRRSets();
104105
$this->assertCount(1, $rrsets);
105106
$rrset = $rrsets[0];
106-
$this->assertEquals($rrset->id, "www/A");
107+
$this->assertEquals($rrset->id, 'www/A');
107108
$this->assertEquals($rrset->name, 'www');
108109

109-
$this->assertLastRequestEquals('GET', '/zones/' . $this->zone->id . '/rrsets');
110+
$this->assertLastRequestEquals('GET', '/zones/'.$this->zone->id.'/rrsets');
110111
}
112+
111113
public function testListRRSets()
112114
{
113-
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__ . '/fixtures/zone_rrsets.json')));
115+
$this->mockHandler->append(new Response(200, [], file_get_contents(__DIR__.'/fixtures/zone_rrsets.json')));
114116
$rrsets = $this->zone->listRRSets()->rrsets;
115117
$this->assertCount(1, $rrsets);
116118
$rrset = $rrsets[0];
117-
$this->assertEquals($rrset->id, "www/A");
119+
$this->assertEquals($rrset->id, 'www/A');
118120
$this->assertEquals($rrset->name, 'www');
119121

120-
$this->assertLastRequestEquals('GET', '/zones/' . $this->zone->id . '/rrsets');
122+
$this->assertLastRequestEquals('GET', '/zones/'.$this->zone->id.'/rrsets');
121123
}
122124

123125
public function testCreateRRSet()
124126
{
125-
$this->mockHandler->append(new Response(201, [], file_get_contents(__DIR__ . '/fixtures/zone_create_rrset.json')));
126-
$apiResponse = $this->zone->createRRSet("www", "A", [new Record("198.51.100.1", "my webserver at Hetzner Cloud")], 3600, ["environment" => "prod"]);
127+
$this->mockHandler->append(new Response(201, [], file_get_contents(__DIR__.'/fixtures/zone_create_rrset.json')));
128+
$apiResponse = $this->zone->createRRSet('www', 'A', [new Record('198.51.100.1', 'my webserver at Hetzner Cloud')], 3600, ['environment' => 'prod']);
127129
$this->assertNotEmpty($apiResponse->rrset);
128130
$this->assertNotEmpty($apiResponse->action);
129131

@@ -133,11 +135,11 @@ public function testCreateRRSet()
133135
'type' => 'A',
134136
'ttl' => 3600,
135137
'labels' => ['environment' => 'prod'],
136-
'records' => [['value' => "198.51.100.1", 'comment' => "my webserver at Hetzner Cloud"]]]);
138+
'records' => [['value' => '198.51.100.1', 'comment' => 'my webserver at Hetzner Cloud']]]);
137139
}
138140

139141
protected function getGenericActionResponse(string $command)
140142
{
141-
return str_replace('$command', $command, file_get_contents(__DIR__ . '/fixtures/zone_action_generic.json'));
143+
return str_replace('$command', $command, file_get_contents(__DIR__.'/fixtures/zone_action_generic.json'));
142144
}
143145
}

0 commit comments

Comments
 (0)