Passed
Push — master ( f0f514...a1b81d )
by Artem
01:46
created

VPCRepository::jsonToEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
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\VPC\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\VPC\VPC;
17
use Linode\VPC\VPCRepositoryInterface;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class VPCRepository extends AbstractRepository implements VPCRepositoryInterface
23
{
24
    public function createVPC(array $parameters = []): VPC
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new VPC($this->client, $json);
31
    }
32
33
    public function updateVPC(int $vpcId, array $parameters = []): VPC
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $vpcId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new VPC($this->client, $json);
40
    }
41
42
    public function deleteVPC(int $vpcId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $vpcId));
45
    }
46
47
    protected function getBaseUri(): string
48
    {
49
        return '/vpcs';
50
    }
51
52
    protected function getSupportedFields(): array
53
    {
54
        return [
55
            VPC::FIELD_ID,
56
            VPC::FIELD_LABEL,
57
            VPC::FIELD_DESCRIPTION,
58
            VPC::FIELD_REGION,
59
            VPC::FIELD_SUBNETS,
60
            VPC::FIELD_CREATED,
61
            VPC::FIELD_UPDATED,
62
        ];
63
    }
64
65
    protected function jsonToEntity(array $json): Entity
66
    {
67
        return new VPC($this->client, $json);
68
    }
69
}
70