Passed
Push — master ( 851c5d...3501a4 )
by Artem
01:43
created

LinodeRepository::resizeLinodeInstance()   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
dl 0
loc 3
c 0
b 0
f 0
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\LinodeInstances\Repository;
13
14
use Linode\Account\Transfer;
15
use Linode\Entity;
16
use Linode\Internal\AbstractRepository;
17
use Linode\LinodeInstances\Linode;
18
use Linode\LinodeInstances\LinodeRepositoryInterface;
19
use Linode\LinodeInstances\LinodeStats;
20
use Linode\Volumes\Volume;
21
22
/**
23
 * @codeCoverageIgnore This class was autogenerated.
24
 */
25
class LinodeRepository extends AbstractRepository implements LinodeRepositoryInterface
26
{
27
    public function createLinodeInstance(array $parameters = []): Linode
28
    {
29
        $response = $this->client->post($this->getBaseUri(), $parameters);
30
        $contents = $response->getBody()->getContents();
31
        $json     = json_decode($contents, true);
32
33
        return new Linode($this->client, $json);
34
    }
35
36
    public function updateLinodeInstance(int $linodeId, array $parameters = []): Linode
37
    {
38
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $linodeId), $parameters);
39
        $contents = $response->getBody()->getContents();
40
        $json     = json_decode($contents, true);
41
42
        return new Linode($this->client, $json);
43
    }
44
45
    public function deleteLinodeInstance(int $linodeId): void
46
    {
47
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $linodeId));
48
    }
49
50
    public function bootLinodeInstance(int $linodeId, array $parameters = []): void
51
    {
52
        $this->client->post(sprintf('%s/%s/boot', $this->getBaseUri(), $linodeId), $parameters);
53
    }
54
55
    public function cloneLinodeInstance(int $linodeId, array $parameters = []): Linode
56
    {
57
        $response = $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $linodeId), $parameters);
58
        $contents = $response->getBody()->getContents();
59
        $json     = json_decode($contents, true);
60
61
        return new Linode($this->client, $json);
62
    }
63
64
    public function migrateLinodeInstance(int $linodeId, array $parameters = []): void
65
    {
66
        $this->client->post(sprintf('%s/%s/migrate', $this->getBaseUri(), $linodeId), $parameters);
67
    }
68
69
    public function mutateLinodeInstance(int $linodeId, array $parameters = []): void
70
    {
71
        $this->client->post(sprintf('%s/%s/mutate', $this->getBaseUri(), $linodeId), $parameters);
72
    }
73
74
    public function resetLinodePassword(int $linodeId, array $parameters = []): void
75
    {
76
        $this->client->post(sprintf('%s/%s/password', $this->getBaseUri(), $linodeId), $parameters);
77
    }
78
79
    public function rebootLinodeInstance(int $linodeId, array $parameters = []): void
80
    {
81
        $this->client->post(sprintf('%s/%s/reboot', $this->getBaseUri(), $linodeId), $parameters);
82
    }
83
84
    public function rebuildLinodeInstance(int $linodeId, array $parameters = []): Linode
85
    {
86
        $response = $this->client->post(sprintf('%s/%s/rebuild', $this->getBaseUri(), $linodeId), $parameters);
87
        $contents = $response->getBody()->getContents();
88
        $json     = json_decode($contents, true);
89
90
        return new Linode($this->client, $json);
91
    }
92
93
    public function rescueLinodeInstance(int $linodeId, array $parameters = []): void
94
    {
95
        $this->client->post(sprintf('%s/%s/rescue', $this->getBaseUri(), $linodeId), $parameters);
96
    }
97
98
    public function resizeLinodeInstance(int $linodeId, array $parameters = []): void
99
    {
100
        $this->client->post(sprintf('%s/%s/resize', $this->getBaseUri(), $linodeId), $parameters);
101
    }
102
103
    public function shutdownLinodeInstance(int $linodeId): void
104
    {
105
        $this->client->post(sprintf('%s/%s/shutdown', $this->getBaseUri(), $linodeId));
106
    }
107
108
    public function getLinodeStats(int $linodeId): LinodeStats
109
    {
110
        $response = $this->client->get(sprintf('%s/%s/stats', $this->getBaseUri(), $linodeId));
111
        $contents = $response->getBody()->getContents();
112
        $json     = json_decode($contents, true);
113
114
        return new LinodeStats($this->client, $json);
115
    }
116
117
    public function getLinodeStatsByYearMonth(int $linodeId, int $year, int $month): LinodeStats
118
    {
119
        $response = $this->client->get(sprintf('%s/%s/stats/%s/%s', $this->getBaseUri(), $linodeId, $year, $month));
120
        $contents = $response->getBody()->getContents();
121
        $json     = json_decode($contents, true);
122
123
        return new LinodeStats($this->client, $json);
124
    }
125
126
    public function getLinodeTransfer(int $linodeId): Transfer
127
    {
128
        $response = $this->client->get(sprintf('%s/%s/transfer', $this->getBaseUri(), $linodeId));
129
        $contents = $response->getBody()->getContents();
130
        $json     = json_decode($contents, true);
131
132
        return new Transfer($this->client, $json);
133
    }
134
135
    public function getLinodeTransferByYearMonth(int $linodeId, int $year, int $month): Transfer
136
    {
137
        $response = $this->client->get(sprintf('%s/%s/transfer/%s/%s', $this->getBaseUri(), $linodeId, $year, $month));
138
        $contents = $response->getBody()->getContents();
139
        $json     = json_decode($contents, true);
140
141
        return new Transfer($this->client, $json);
142
    }
143
144
    public function getLinodeVolumes(int $linodeId): array
145
    {
146
        $response = $this->client->get(sprintf('%s/%s/volumes', $this->getBaseUri(), $linodeId));
147
        $contents = $response->getBody()->getContents();
148
        $json     = json_decode($contents, true);
149
150
        return array_map(fn ($data) => new Volume($this->client, $data), $json['data']);
151
    }
152
153
    protected function getBaseUri(): string
154
    {
155
        return '/linode/instances';
156
    }
157
158
    protected function getSupportedFields(): array
159
    {
160
        return [
161
            Linode::FIELD_ID,
162
            Linode::FIELD_LABEL,
163
            Linode::FIELD_GROUP,
164
            Linode::FIELD_TAGS,
165
            Linode::FIELD_REGION,
166
            Linode::FIELD_TYPE,
167
            Linode::FIELD_IMAGE,
168
            Linode::FIELD_STATUS,
169
            Linode::FIELD_HYPERVISOR,
170
            Linode::FIELD_CREATED,
171
            Linode::FIELD_UPDATED,
172
            Linode::FIELD_WATCHDOG_ENABLED,
173
            Linode::FIELD_IPV4,
174
            Linode::FIELD_IPV6,
175
            Linode::FIELD_SPECS,
176
            Linode::FIELD_ALERTS,
177
            Linode::FIELD_BACKUPS,
178
        ];
179
    }
180
181
    protected function jsonToEntity(array $json): Entity
182
    {
183
        return new Linode($this->client, $json);
184
    }
185
}
186