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

NodeBalancerConfigRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 37
dl 0
loc 75
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A updateNodeBalancerConfig() 0 7 1
A rebuildNodeBalancerConfig() 0 7 1
A createNodeBalancerConfig() 0 7 1
A getSupportedFields() 0 22 1
A deleteNodeBalancerConfig() 0 3 1
A getBaseUri() 0 3 1
A jsonToEntity() 0 3 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\NodeBalancers\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\LinodeClient;
17
use Linode\NodeBalancers\NodeBalancer;
18
use Linode\NodeBalancers\NodeBalancerConfig;
19
use Linode\NodeBalancers\NodeBalancerConfigRepositoryInterface;
20
21
/**
22
 * @codeCoverageIgnore This class was autogenerated.
23
 */
24
class NodeBalancerConfigRepository extends AbstractRepository implements NodeBalancerConfigRepositoryInterface
25
{
26
    /**
27
     * @param int $nodeBalancerId The ID of the NodeBalancer to access.
28
     */
29
    public function __construct(LinodeClient $client, protected int $nodeBalancerId)
30
    {
31
        parent::__construct($client);
32
    }
33
34
    public function createNodeBalancerConfig(array $parameters = []): NodeBalancerConfig
35
    {
36
        $response = $this->client->post($this->getBaseUri(), $parameters);
37
        $contents = $response->getBody()->getContents();
38
        $json     = json_decode($contents, true);
39
40
        return new NodeBalancerConfig($this->client, $json);
41
    }
42
43
    public function updateNodeBalancerConfig(int $configId, array $parameters = []): NodeBalancerConfig
44
    {
45
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $configId), $parameters);
46
        $contents = $response->getBody()->getContents();
47
        $json     = json_decode($contents, true);
48
49
        return new NodeBalancerConfig($this->client, $json);
50
    }
51
52
    public function deleteNodeBalancerConfig(int $configId): void
53
    {
54
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $configId));
55
    }
56
57
    public function rebuildNodeBalancerConfig(int $configId, array $parameters = []): NodeBalancer
58
    {
59
        $response = $this->client->post(sprintf('%s/%s/rebuild', $this->getBaseUri(), $configId), $parameters);
60
        $contents = $response->getBody()->getContents();
61
        $json     = json_decode($contents, true);
62
63
        return new NodeBalancer($this->client, $json);
64
    }
65
66
    protected function getBaseUri(): string
67
    {
68
        return sprintf('/nodebalancers/%s/configs', $this->nodeBalancerId);
69
    }
70
71
    protected function getSupportedFields(): array
72
    {
73
        return [
74
            NodeBalancerConfig::FIELD_ID,
75
            NodeBalancerConfig::FIELD_PORT,
76
            NodeBalancerConfig::FIELD_PROTOCOL,
77
            NodeBalancerConfig::FIELD_ALGORITHM,
78
            NodeBalancerConfig::FIELD_STICKINESS,
79
            NodeBalancerConfig::FIELD_CHECK,
80
            NodeBalancerConfig::FIELD_CHECK_INTERVAL,
81
            NodeBalancerConfig::FIELD_CHECK_TIMEOUT,
82
            NodeBalancerConfig::FIELD_CHECK_ATTEMPTS,
83
            NodeBalancerConfig::FIELD_CHECK_PATH,
84
            NodeBalancerConfig::FIELD_CHECK_BODY,
85
            NodeBalancerConfig::FIELD_CHECK_PASSIVE,
86
            NodeBalancerConfig::FIELD_CIPHER_SUITE,
87
            NodeBalancerConfig::FIELD_SSL_COMMONNAME,
88
            NodeBalancerConfig::FIELD_SSL_FINGERPRINT,
89
            NodeBalancerConfig::FIELD_SSL_CERT,
90
            NodeBalancerConfig::FIELD_SSL_KEY,
91
            NodeBalancerConfig::FIELD_NODES_STATUS,
92
            NodeBalancerConfig::FIELD_NODEBALANCER_ID,
93
        ];
94
    }
95
96
    protected function jsonToEntity(array $json): Entity
97
    {
98
        return new NodeBalancerConfig($this->client, $json);
99
    }
100
}
101