Passed
Push — master ( 3501a4...bfa63a )
by Artem
01:45
created

FirewallRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 20
c 1
b 0
f 0
dl 0
loc 46
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSupportedFields() 0 10 1
A deleteFirewall() 0 3 1
A createFirewalls() 0 7 1
A getBaseUri() 0 3 1
A updateFirewall() 0 7 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\Networking\Repository;
13
14
use Linode\Entity;
15
use Linode\Internal\AbstractRepository;
16
use Linode\Networking\Firewall;
17
use Linode\Networking\FirewallRepositoryInterface;
18
19
/**
20
 * @codeCoverageIgnore This class was autogenerated.
21
 */
22
class FirewallRepository extends AbstractRepository implements FirewallRepositoryInterface
23
{
24
    public function createFirewalls(array $parameters = []): Firewall
25
    {
26
        $response = $this->client->post($this->getBaseUri(), $parameters);
27
        $contents = $response->getBody()->getContents();
28
        $json     = json_decode($contents, true);
29
30
        return new Firewall($this->client, $json);
31
    }
32
33
    public function updateFirewall(int $firewallId, array $parameters = []): Firewall
34
    {
35
        $response = $this->client->put(sprintf('%s/%s', $this->getBaseUri(), $firewallId), $parameters);
36
        $contents = $response->getBody()->getContents();
37
        $json     = json_decode($contents, true);
38
39
        return new Firewall($this->client, $json);
40
    }
41
42
    public function deleteFirewall(int $firewallId): void
43
    {
44
        $this->client->delete(sprintf('%s/%s', $this->getBaseUri(), $firewallId));
45
    }
46
47
    protected function getBaseUri(): string
48
    {
49
        return '/networking/firewalls';
50
    }
51
52
    protected function getSupportedFields(): array
53
    {
54
        return [
55
            Firewall::FIELD_ID,
56
            Firewall::FIELD_LABEL,
57
            Firewall::FIELD_STATUS,
58
            Firewall::FIELD_CREATED,
59
            Firewall::FIELD_UPDATED,
60
            Firewall::FIELD_RULES,
61
            Firewall::FIELD_TAGS,
62
        ];
63
    }
64
65
    protected function jsonToEntity(array $json): Entity
66
    {
67
        return new Firewall($this->client, $json);
68
    }
69
}
70