Passed
Push — master ( 41a424...f04d85 )
by Artem
01:57
created

putDatabasesMySQLInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
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 postDatabasesMySQLInstanceBackupRestore(int $instanceId, int $backupId): void
74
    {
75
        $this->client->post(sprintf('%s/%s/backups/%s/restore', $this->getBaseUri(), $instanceId, $backupId));
76
    }
77
78
    public function getDatabasesMySQLInstanceCredentials(int $instanceId): DatabaseCredentials
79
    {
80
        $response = $this->client->get(sprintf('%s/%s/credentials', $this->getBaseUri(), $instanceId));
81
        $contents = $response->getBody()->getContents();
82
        $json     = json_decode($contents, true);
83
84
        return new DatabaseCredentials($this->client, $json);
85
    }
86
87
    public function postDatabasesMySQLInstanceCredentialsReset(int $instanceId): void
88
    {
89
        $this->client->post(sprintf('%s/%s/credentials/reset', $this->getBaseUri(), $instanceId));
90
    }
91
92
    public function getDatabasesMySQLInstanceSSL(int $instanceId): DatabaseSSL
93
    {
94
        $response = $this->client->get(sprintf('%s/%s/ssl', $this->getBaseUri(), $instanceId));
95
        $contents = $response->getBody()->getContents();
96
        $json     = json_decode($contents, true);
97
98
        return new DatabaseSSL($this->client, $json);
99
    }
100
101
    public function postDatabasesMySQLInstancePatch(int $instanceId): void
102
    {
103
        $this->client->post(sprintf('%s/%s/patch', $this->getBaseUri(), $instanceId));
104
    }
105
106
    protected function getBaseUri(): string
107
    {
108
        return 'beta/databases/mysql/instances';
109
    }
110
111
    protected function getSupportedFields(): array
112
    {
113
        return [
114
            DatabaseMySQL::FIELD_ID,
115
            DatabaseMySQL::FIELD_LABEL,
116
            DatabaseMySQL::FIELD_REGION,
117
            DatabaseMySQL::FIELD_TYPE,
118
            DatabaseMySQL::FIELD_CLUSTER_SIZE,
119
            DatabaseMySQL::FIELD_ENGINE,
120
            DatabaseMySQL::FIELD_VERSION,
121
            DatabaseMySQL::FIELD_PORT,
122
            DatabaseMySQL::FIELD_REPLICATION_TYPE,
123
            DatabaseMySQL::FIELD_STATUS,
124
            DatabaseMySQL::FIELD_ENCRYPTED,
125
            DatabaseMySQL::FIELD_ALLOW_LIST,
126
            DatabaseMySQL::FIELD_HOSTS,
127
            DatabaseMySQL::FIELD_SSL_CONNECTION,
128
            DatabaseMySQL::FIELD_CREATED,
129
            DatabaseMySQL::FIELD_UPDATED,
130
            DatabaseMySQL::FIELD_UPDATES,
131
        ];
132
    }
133
134
    protected function jsonToEntity(array $json): Entity
135
    {
136
        return new DatabaseMySQL($this->client, $json);
137
    }
138
}
139