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

LinodeConfigRepository::deleteLinodeConfig()   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\LinodeInstances\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\LinodeClient;
17
use Linode\LinodeInstances\LinodeConfig;
18
use Linode\LinodeInstances\LinodeConfigRepositoryInterface;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class LinodeConfigRepository extends AbstractRepository implements LinodeConfigRepositoryInterface
24
{
25
    /**
26
     * @param int $linodeId ID of the Linode to look up Configuration profiles for.
27
     */
28
    public function __construct(LinodeClient $client, protected int $linodeId)
29
    {
30
        parent::__construct($client);
31
    }
32
33
    public function addLinodeConfig(array $parameters = []): LinodeConfig
34
    {
35
        $response = $this->client->post($this->getBaseUri(), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new LinodeConfig($this->client, $json);
40
    }
41
42
    public function updateLinodeConfig(int $configId, array $parameters = []): LinodeConfig
43
    {
44
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $configId), $parameters);
45
        $contents = $response->getBody()->getContents();
46
        $json     = json_decode($contents, true);
47
48
        return new LinodeConfig($this->client, $json);
49
    }
50
51
    public function deleteLinodeConfig(int $configId): void
52
    {
53
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $configId));
54
    }
55
56
    protected function getBaseUri(): string
57
    {
58
        return sprintf('/linode/instances/%s/configs', $this->linodeId);
59
    }
60
61
    protected function getSupportedFields(): array
62
    {
63
        return [
64
            LinodeConfig::FIELD_ID,
65
            LinodeConfig::FIELD_LABEL,
66
            LinodeConfig::FIELD_KERNEL,
67
            LinodeConfig::FIELD_COMMENTS,
68
            LinodeConfig::FIELD_MEMORY_LIMIT,
69
            LinodeConfig::FIELD_RUN_LEVEL,
70
            LinodeConfig::FIELD_VIRT_MODE,
71
            LinodeConfig::FIELD_HELPERS,
72
            LinodeConfig::FIELD_DEVICES,
73
            LinodeConfig::FIELD_ROOT_DEVICE,
74
        ];
75
    }
76
77
    protected function jsonToEntity(array $json): Entity
78
    {
79
        return new LinodeConfig($this->client, $json);
80
    }
81
}
82