StackScriptRepository::getSupportedFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 18
rs 9.7333
cc 1
nc 1
nop 0
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\StackScripts\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\StackScripts\StackScript;
17
use Linode\StackScripts\StackScriptRepositoryInterface;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class StackScriptRepository extends AbstractRepository implements StackScriptRepositoryInterface
23
{
24
    public function addStackScript(array $parameters = []): StackScript
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new StackScript($this->client, $json);
31
    }
32
33
    public function updateStackScript(int $stackscriptId, array $parameters = []): StackScript
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $stackscriptId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new StackScript($this->client, $json);
40
    }
41
42
    public function deleteStackScript(int $stackscriptId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $stackscriptId));
45
    }
46
47
    protected function getBaseUri(): string
48
    {
49
        return '/linode/stackscripts';
50
    }
51
52
    protected function getSupportedFields(): array
53
    {
54
        return [
55
            StackScript::FIELD_ID,
56
            StackScript::FIELD_USERNAME,
57
            StackScript::FIELD_LABEL,
58
            StackScript::FIELD_IMAGES,
59
            StackScript::FIELD_IS_PUBLIC,
60
            StackScript::FIELD_CREATED,
61
            StackScript::FIELD_UPDATED,
62
            StackScript::FIELD_USER_GRAVATAR_ID,
63
            StackScript::FIELD_DESCRIPTION,
64
            StackScript::FIELD_DEPLOYMENTS_TOTAL,
65
            StackScript::FIELD_DEPLOYMENTS_ACTIVE,
66
            StackScript::FIELD_REV_NOTE,
67
            StackScript::FIELD_SCRIPT,
68
            StackScript::FIELD_USER_DEFINED_FIELDS,
69
            StackScript::FIELD_MINE,
70
        ];
71
    }
72
73
    protected function jsonToEntity(array $json): Entity
74
    {
75
        return new StackScript($this->client, $json);
76
    }
77
}
78