Passed
Push — master ( 0676a7...01ab94 )
by Artem
11:54
created

DomainRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 40
dl 0
loc 80
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseUri() 0 3 1
A createDomain() 0 7 1
A jsonToEntity() 0 3 1
A getSupportedFields() 0 17 1
A importDomain() 0 12 1
A deleteDomain() 0 3 1
A cloneDomain() 0 11 1
A updateDomain() 0 7 1
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 importDomain(string $domain, string $remote_nameserver): Domain
48
    {
49
        $parameters = [
50
            'domain'            => $domain,
51
            'remote_nameserver' => $remote_nameserver,
52
        ];
53
54
        $response = $this->client->post(sprintf('%s/import', $this->getBaseUri()), $parameters);
55
        $contents = $response->getBody()->getContents();
56
        $json     = json_decode($contents, true);
57
58
        return new Domain($this->client, $json);
59
    }
60
61
    public function cloneDomain(int $domainId, string $domain): Domain
62
    {
63
        $parameters = [
64
            'domain' => $domain,
65
        ];
66
67
        $response = $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $domainId), $parameters);
68
        $contents = $response->getBody()->getContents();
69
        $json     = json_decode($contents, true);
70
71
        return new Domain($this->client, $json);
72
    }
73
74
    protected function getBaseUri(): string
75
    {
76
        return '/domains';
77
    }
78
79
    protected function getSupportedFields(): array
80
    {
81
        return [
82
            Domain::FIELD_ID,
83
            Domain::FIELD_DOMAIN,
84
            Domain::FIELD_TYPE,
85
            Domain::FIELD_STATUS,
86
            Domain::FIELD_SOA_EMAIL,
87
            Domain::FIELD_GROUP,
88
            Domain::FIELD_DESCRIPTION,
89
            Domain::FIELD_TTL_SEC,
90
            Domain::FIELD_REFRESH_SEC,
91
            Domain::FIELD_RETRY_SEC,
92
            Domain::FIELD_EXPIRE_SEC,
93
            Domain::FIELD_MASTER_IPS,
94
            Domain::FIELD_AXFR_IPS,
95
            Domain::FIELD_TAGS,
96
        ];
97
    }
98
99
    protected function jsonToEntity(array $json): Entity
100
    {
101
        return new Domain($this->client, $json);
102
    }
103
}
104