Passed
Push — master ( 2c24c4...fb6e78 )
by Artem
01:55
created

ObjectStorageKeyRepository::jsonToEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 <http://opensource.org/licenses/MIT>.
9
//
10
// ---------------------------------------------------------------------
11
12
namespace Linode\Internal\ObjectStorage;
13
14
use Linode\Entity\Entity;
15
use Linode\Entity\ObjectStorage\ObjectStorageKey;
16
use Linode\Internal\AbstractRepository;
17
use Linode\Repository\ObjectStorage\ObjectStorageKeyRepositoryInterface;
18
19
class ObjectStorageKeyRepository extends AbstractRepository implements ObjectStorageKeyRepositoryInterface
20
{
21 1
    public function create(array $parameters): ObjectStorageKey
22
    {
23 1
        $this->checkParametersSupport($parameters);
24
25 1
        $response = $this->client->api($this->client::REQUEST_POST, $this->getBaseUri(), $parameters);
26 1
        $contents = $response->getBody()->getContents();
27 1
        $json     = json_decode($contents, true);
28
29 1
        return new ObjectStorageKey($this->client, $json);
30
    }
31
32 1
    public function update(int $id, array $parameters): ObjectStorageKey
33
    {
34 1
        $this->checkParametersSupport($parameters);
35
36 1
        $response = $this->client->api($this->client::REQUEST_PUT, sprintf('%s/%s', $this->getBaseUri(), $id), $parameters);
37 1
        $contents = $response->getBody()->getContents();
38 1
        $json     = json_decode($contents, true);
39
40 1
        return new ObjectStorageKey($this->client, $json);
41
    }
42
43 1
    public function revoke(int $id): void
44
    {
45 1
        $this->client->api($this->client::REQUEST_DELETE, sprintf('%s/%s', $this->getBaseUri(), $id));
46
    }
47
48 4
    protected function getBaseUri(): string
49
    {
50 4
        return 'beta/object-storage/keys';
51
    }
52
53 3
    protected function getSupportedFields(): array
54
    {
55 3
        return [
56 3
            ObjectStorageKey::FIELD_ID,
57 3
            ObjectStorageKey::FIELD_LABEL,
58 3
        ];
59
    }
60
61 1
    protected function jsonToEntity(array $json): Entity
62
    {
63 1
        return new ObjectStorageKey($this->client, $json);
64
    }
65
}
66