DomainRepository::getSupportedFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 17
c 0
b 0
f 0
rs 9.7666
cc 1
nc 1
nop 0
1
<?php
2
3
// ---------------------------------------------------------------------
4
//
5
//  Copyright (C) 2018-2024 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <https://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Domains\Repository;
13
14
use Linode\Domains\Domain;
15
use Linode\Domains\DomainRepositoryInterface;
16
use Linode\Entity;
17
use Linode\Internal\AbstractRepository;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class DomainRepository extends AbstractRepository implements DomainRepositoryInterface
23
{
24
    public function createDomain(array $parameters = []): Domain
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new Domain($this->client, $json);
31
    }
32
33
    public function updateDomain(int $domainId, array $parameters = []): Domain
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $domainId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new Domain($this->client, $json);
40
    }
41
42
    public function deleteDomain(int $domainId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $domainId));
45
    }
46
47
    public function getDomainZone(string $domainId): array
48
    {
49
        $response = $this->client->get(sprintf('%s/%s/zone-file', $this->getBaseUri(), $domainId));
50
        $contents = $response->getBody()->getContents();
51
        $json     = json_decode($contents, true);
52
53
        return $json['zone_file'];
54
    }
55
56
    public function importDomain(string $domain, string $remote_nameserver): Domain
57
    {
58
        $parameters = [
59
            'domain'            => $domain,
60
            'remote_nameserver' => $remote_nameserver,
61
        ];
62
63
        $response = $this->client->post(sprintf('%s/import', $this->getBaseUri()), $parameters);
64
        $contents = $response->getBody()->getContents();
65
        $json     = json_decode($contents, true);
66
67
        return new Domain($this->client, $json);
68
    }
69
70
    public function cloneDomain(int $domainId, string $domain): Domain
71
    {
72
        $parameters = [
73
            'domain' => $domain,
74
        ];
75
76
        $response = $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $domainId), $parameters);
77
        $contents = $response->getBody()->getContents();
78
        $json     = json_decode($contents, true);
79
80
        return new Domain($this->client, $json);
81
    }
82
83
    protected function getBaseUri(): string
84
    {
85
        return '/domains';
86
    }
87
88
    protected function getSupportedFields(): array
89
    {
90
        return [
91
            Domain::FIELD_ID,
92
            Domain::FIELD_DOMAIN,
93
            Domain::FIELD_TYPE,
94
            Domain::FIELD_STATUS,
95
            Domain::FIELD_SOA_EMAIL,
96
            Domain::FIELD_GROUP,
97
            Domain::FIELD_DESCRIPTION,
98
            Domain::FIELD_TTL_SEC,
99
            Domain::FIELD_REFRESH_SEC,
100
            Domain::FIELD_RETRY_SEC,
101
            Domain::FIELD_EXPIRE_SEC,
102
            Domain::FIELD_MASTER_IPS,
103
            Domain::FIELD_AXFR_IPS,
104
            Domain::FIELD_TAGS,
105
        ];
106
    }
107
108
    protected function jsonToEntity(array $json): Entity
109
    {
110
        return new Domain($this->client, $json);
111
    }
112
}
113