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

DomainRecordRepository::getSupportedFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 14
c 0
b 0
f 0
rs 9.8666
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\DomainRecord;
15
use Linode\Domains\DomainRecordRepositoryInterface;
16
use Linode\Entity;
17
use Linode\Internal\AbstractRepository;
18
use Linode\LinodeClient;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class DomainRecordRepository extends AbstractRepository implements DomainRecordRepositoryInterface
24
{
25
    /**
26
     * @param int $domainId The ID of the Domain we are accessing Records for.
27
     */
28
    public function __construct(LinodeClient $client, protected int $domainId)
29
    {
30
        parent::__construct($client);
31
    }
32
33
    public function createDomainRecord(array $parameters = []): DomainRecord
34
    {
35
        $response = $this->client->post($this->getBaseUri(), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new DomainRecord($this->client, $json);
40
    }
41
42
    public function updateDomainRecord(int $recordId, array $parameters = []): DomainRecord
43
    {
44
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $recordId), $parameters);
45
        $contents = $response->getBody()->getContents();
46
        $json     = json_decode($contents, true);
47
48
        return new DomainRecord($this->client, $json);
49
    }
50
51
    public function deleteDomainRecord(int $recordId): void
52
    {
53
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $recordId));
54
    }
55
56
    protected function getBaseUri(): string
57
    {
58
        return sprintf('/domains/%s/records', $this->domainId);
59
    }
60
61
    protected function getSupportedFields(): array
62
    {
63
        return [
64
            DomainRecord::FIELD_ID,
65
            DomainRecord::FIELD_TYPE,
66
            DomainRecord::FIELD_NAME,
67
            DomainRecord::FIELD_TARGET,
68
            DomainRecord::FIELD_TTL_SEC,
69
            DomainRecord::FIELD_PRIORITY,
70
            DomainRecord::FIELD_WEIGHT,
71
            DomainRecord::FIELD_SERVICE,
72
            DomainRecord::FIELD_PROTOCOL,
73
            DomainRecord::FIELD_PORT,
74
            DomainRecord::FIELD_TAG,
75
        ];
76
    }
77
78
    protected function jsonToEntity(array $json): Entity
79
    {
80
        return new DomainRecord($this->client, $json);
81
    }
82
}
83