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

NodeBalancerRepository::getSupportedFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 14
c 0
b 0
f 0
rs 9.8666
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\NodeBalancers\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\NodeBalancers\NodeBalancer;
17
use Linode\NodeBalancers\NodeBalancerRepositoryInterface;
18
use Linode\NodeBalancers\NodeBalancerStats;
19
20
/**
21
 * @codeCoverageIgnore This class was autogenerated.
22
 */
23
class NodeBalancerRepository extends AbstractRepository implements NodeBalancerRepositoryInterface
24
{
25
    public function createNodeBalancer(array $parameters = []): NodeBalancer
26
    {
27
        $response = $this->client->post($this->getBaseUri(), $parameters);
28
        $contents = $response->getBody()->getContents();
29
        $json     = json_decode($contents, true);
30
31
        return new NodeBalancer($this->client, $json);
32
    }
33
34
    public function updateNodeBalancer(int $nodeBalancerId, array $parameters = []): NodeBalancer
35
    {
36
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $nodeBalancerId), $parameters);
37
        $contents = $response->getBody()->getContents();
38
        $json     = json_decode($contents, true);
39
40
        return new NodeBalancer($this->client, $json);
41
    }
42
43
    public function deleteNodeBalancer(int $nodeBalancerId): void
44
    {
45
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $nodeBalancerId));
46
    }
47
48
    public function getNodeBalancerStats(int $nodeBalancerId): NodeBalancerStats
49
    {
50
        $response = $this->client->get(sprintf('%s/%s/stats', $this->getBaseUri(), $nodeBalancerId));
51
        $contents = $response->getBody()->getContents();
52
        $json     = json_decode($contents, true);
53
54
        return new NodeBalancerStats($this->client, $json);
55
    }
56
57
    protected function getBaseUri(): string
58
    {
59
        return '/nodebalancers';
60
    }
61
62
    protected function getSupportedFields(): array
63
    {
64
        return [
65
            NodeBalancer::FIELD_ID,
66
            NodeBalancer::FIELD_LABEL,
67
            NodeBalancer::FIELD_REGION,
68
            NodeBalancer::FIELD_HOSTNAME,
69
            NodeBalancer::FIELD_IPV4,
70
            NodeBalancer::FIELD_IPV6,
71
            NodeBalancer::FIELD_CLIENT_CONN_THROTTLE,
72
            NodeBalancer::FIELD_CREATED,
73
            NodeBalancer::FIELD_UPDATED,
74
            NodeBalancer::FIELD_TAGS,
75
            NodeBalancer::FIELD_TRANSFER,
76
        ];
77
    }
78
79
    protected function jsonToEntity(array $json): Entity
80
    {
81
        return new NodeBalancer($this->client, $json);
82
    }
83
}
84