Passed
Push — master ( f04d85...f0f514 )
by Artem
01:45
created

deleteDatabaseMySQLInstanceBackup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
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\Databases\Repository;
13
14
use Linode\Databases\DatabaseBackup;
15
use Linode\Databases\DatabaseCredentials;
16
use Linode\Databases\DatabaseMySQL;
17
use Linode\Databases\DatabaseMySQLRepositoryInterface;
18
use Linode\Databases\DatabaseSSL;
19
use Linode\Entity;
20
use Linode\Internal\AbstractRepository;
21
22
/**
23
 * @codeCoverageIgnore This class was autogenerated.
24
 */
25
class DatabaseMySQLRepository extends AbstractRepository implements DatabaseMySQLRepositoryInterface
26
{
27
    public function postDatabasesMySQLInstances(array $parameters = []): DatabaseMySQL
28
    {
29
        $response = $this->client->post($this->getBaseUri(), $parameters);
30
        $contents = $response->getBody()->getContents();
31
        $json     = json_decode($contents, true);
32
33
        return new DatabaseMySQL($this->client, $json);
34
    }
35
36
    public function putDatabasesMySQLInstance(int $instanceId, array $parameters = []): DatabaseMySQL
37
    {
38
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $instanceId), $parameters);
39
        $contents = $response->getBody()->getContents();
40
        $json     = json_decode($contents, true);
41
42
        return new DatabaseMySQL($this->client, $json);
43
    }
44
45
    public function deleteDatabasesMySQLInstance(int $instanceId): void
46
    {
47
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $instanceId));
48
    }
49
50
    public function getDatabasesMySQLInstanceBackups(int $instanceId): array
51
    {
52
        $response = $this->client->get(sprintf('%s/%s/backups', $this->getBaseUri(), $instanceId));
53
        $contents = $response->getBody()->getContents();
54
        $json     = json_decode($contents, true);
55
56
        return array_map(fn ($data) => new DatabaseBackup($this->client, $data), $json['data']);
57
    }
58
59
    public function postDatabasesMySQLInstanceBackup(int $instanceId, array $parameters = []): void
60
    {
61
        $this->client->post(sprintf('%s/%s/backups', $this->getBaseUri(), $instanceId), $parameters);
62
    }
63
64
    public function getDatabasesMySQLInstanceBackup(int $instanceId, int $backupId): DatabaseBackup
65
    {
66
        $response = $this->client->get(sprintf('%s/%s/backups/%s', $this->getBaseUri(), $instanceId, $backupId));
67
        $contents = $response->getBody()->getContents();
68
        $json     = json_decode($contents, true);
69
70
        return new DatabaseBackup($this->client, $json);
71
    }
72
73
    public function deleteDatabaseMySQLInstanceBackup(int $instanceId, int $backupId): void
74
    {
75
        $this->client->delete(sprintf('%s/%s/backups/%s', $this->getBaseUri(), $instanceId, $backupId));
76
    }
77
78
    public function postDatabasesMySQLInstanceBackupRestore(int $instanceId, int $backupId): void
79
    {
80
        $this->client->post(sprintf('%s/%s/backups/%s/restore', $this->getBaseUri(), $instanceId, $backupId));
81
    }
82
83
    public function getDatabasesMySQLInstanceCredentials(int $instanceId): DatabaseCredentials
84
    {
85
        $response = $this->client->get(sprintf('%s/%s/credentials', $this->getBaseUri(), $instanceId));
86
        $contents = $response->getBody()->getContents();
87
        $json     = json_decode($contents, true);
88
89
        return new DatabaseCredentials($this->client, $json);
90
    }
91
92
    public function postDatabasesMySQLInstanceCredentialsReset(int $instanceId): void
93
    {
94
        $this->client->post(sprintf('%s/%s/credentials/reset', $this->getBaseUri(), $instanceId));
95
    }
96
97
    public function getDatabasesMySQLInstanceSSL(int $instanceId): DatabaseSSL
98
    {
99
        $response = $this->client->get(sprintf('%s/%s/ssl', $this->getBaseUri(), $instanceId));
100
        $contents = $response->getBody()->getContents();
101
        $json     = json_decode($contents, true);
102
103
        return new DatabaseSSL($this->client, $json);
104
    }
105
106
    public function postDatabasesMySQLInstancePatch(int $instanceId): void
107
    {
108
        $this->client->post(sprintf('%s/%s/patch', $this->getBaseUri(), $instanceId));
109
    }
110
111
    protected function getBaseUri(): string
112
    {
113
        return 'beta/databases/mysql/instances';
114
    }
115
116
    protected function getSupportedFields(): array
117
    {
118
        return [
119
            DatabaseMySQL::FIELD_ID,
120
            DatabaseMySQL::FIELD_LABEL,
121
            DatabaseMySQL::FIELD_REGION,
122
            DatabaseMySQL::FIELD_TYPE,
123
            DatabaseMySQL::FIELD_CLUSTER_SIZE,
124
            DatabaseMySQL::FIELD_ENGINE,
125
            DatabaseMySQL::FIELD_VERSION,
126
            DatabaseMySQL::FIELD_PORT,
127
            DatabaseMySQL::FIELD_REPLICATION_TYPE,
128
            DatabaseMySQL::FIELD_STATUS,
129
            DatabaseMySQL::FIELD_ENCRYPTED,
130
            DatabaseMySQL::FIELD_ALLOW_LIST,
131
            DatabaseMySQL::FIELD_HOSTS,
132
            DatabaseMySQL::FIELD_SSL_CONNECTION,
133
            DatabaseMySQL::FIELD_CREATED,
134
            DatabaseMySQL::FIELD_UPDATED,
135
            DatabaseMySQL::FIELD_UPDATES,
136
        ];
137
    }
138
139
    protected function jsonToEntity(array $json): Entity
140
    {
141
        return new DatabaseMySQL($this->client, $json);
142
    }
143
}
144