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

VolumeRepository::jsonToEntity()   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 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 = []): void
57
    {
58
        $this->client->post(sprintf('%s/%s/clone', $this->getBaseUri(), $volumeId), $parameters);
59
    }
60
61
    public function detachVolume(int $volumeId): void
62
    {
63
        $this->client->post(sprintf('%s/%s/detach', $this->getBaseUri(), $volumeId));
64
    }
65
66
    public function resizeVolume(int $volumeId, array $parameters = []): void
67
    {
68
        $this->client->post(sprintf('%s/%s/resize', $this->getBaseUri(), $volumeId), $parameters);
69
    }
70
71
    protected function getBaseUri(): string
72
    {
73
        return '/volumes';
74
    }
75
76
    protected function getSupportedFields(): array
77
    {
78
        return [
79
            Volume::FIELD_ID,
80
            Volume::FIELD_LABEL,
81
            Volume::FIELD_STATUS,
82
            Volume::FIELD_SIZE,
83
            Volume::FIELD_REGION,
84
            Volume::FIELD_LINODE_ID,
85
            Volume::FIELD_FILESYSTEM_PATH,
86
            Volume::FIELD_CREATED,
87
            Volume::FIELD_UPDATED,
88
            Volume::FIELD_TAGS,
89
        ];
90
    }
91
92
    protected function jsonToEntity(array $json): Entity
93
    {
94
        return new Volume($this->client, $json);
95
    }
96
}
97