VolumeRepository::jsonToEntity()   A
last analyzed

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 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\Volumes\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\Volumes\Volume;
17
use Linode\Volumes\VolumeRepositoryInterface;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class VolumeRepository extends AbstractRepository implements VolumeRepositoryInterface
23
{
24
    public function createVolume(array $parameters = []): Volume
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new Volume($this->client, $json);
31
    }
32
33
    public function updateVolume(int $volumeId, array $parameters = []): Volume
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $volumeId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new Volume($this->client, $json);
40
    }
41
42
    public function deleteVolume(int $volumeId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $volumeId));
45
    }
46
47
    public function attachVolume(int $volumeId, array $parameters = []): Volume
48
    {
49
        $response = $this->client->post(sprintf('%s/%s/attach', $this->getBaseUri(), $volumeId), $parameters);
50
        $contents = $response->getBody()->getContents();
51
        $json     = json_decode($contents, true);
52
53
        return new Volume($this->client, $json);
54
    }
55
56
    public function cloneVolume(int $volumeId, array $parameters = []): Volume
57
    {
58
        $response = $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $volumeId), $parameters);
59
        $contents = $response->getBody()->getContents();
60
        $json     = json_decode($contents, true);
61
62
        return new Volume($this->client, $json);
63
    }
64
65
    public function detachVolume(int $volumeId): void
66
    {
67
        $this->client->post(sprintf('%s/%s/detach', $this->getBaseUri(), $volumeId));
68
    }
69
70
    public function resizeVolume(int $volumeId, array $parameters = []): Volume
71
    {
72
        $response = $this->client->post(sprintf('%s/%s/resize', $this->getBaseUri(), $volumeId), $parameters);
73
        $contents = $response->getBody()->getContents();
74
        $json     = json_decode($contents, true);
75
76
        return new Volume($this->client, $json);
77
    }
78
79
    protected function getBaseUri(): string
80
    {
81
        return '/volumes';
82
    }
83
84
    protected function getSupportedFields(): array
85
    {
86
        return [
87
            Volume::FIELD_ID,
88
            Volume::FIELD_LABEL,
89
            Volume::FIELD_STATUS,
90
            Volume::FIELD_SIZE,
91
            Volume::FIELD_REGION,
92
            Volume::FIELD_LINODE_ID,
93
            Volume::FIELD_LINODE_LABEL,
94
            Volume::FIELD_FILESYSTEM_PATH,
95
            Volume::FIELD_CREATED,
96
            Volume::FIELD_UPDATED,
97
            Volume::FIELD_TAGS,
98
            Volume::FIELD_HARDWARE_TYPE,
99
        ];
100
    }
101
102
    protected function jsonToEntity(array $json): Entity
103
    {
104
        return new Volume($this->client, $json);
105
    }
106
}
107