Completed
Push — master ( 154099...4cfbe9 )
by Günter
10s
created

Zones   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 89
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 3 1
A show() 0 4 1
A delete() 0 5 1
A add() 0 13 1
A upsertRecord() 0 6 1
A deleteRecord() 0 6 1
A createNS() 0 20 2
A createSOA() 0 22 1
1
<?php
2
3
/**
4
 * This file is part of the africc/pdns-client library.
5
 *
6
 * (c) Gunter Grodotzki <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE file
9
 * that was distributed with this source code.
10
 */
11
12
namespace AfriCC\Pdns\Endpoints;
13
14
use AfriCC\Pdns\Helper;
15
use AfriCC\Pdns\Types\Typable;
16
17
class Zones extends Endpoint
18
{
19
    public function all()
20
    {
21
    }
22
23
    public function show($name)
24
    {
25
        $this->appendToUri(sprintf('/%s', Helper::canonical($name)));
26
    }
27
28
    public function delete($name)
29
    {
30
        $this->appendToUri(sprintf('/%s', Helper::canonical($name)));
31
        $this->method = 'DELETE';
32
    }
33
34
    public function add($name, array $nameservers, $account = '')
35
    {
36
        $this->method = 'POST';
37
        $this->data = [
38
            'account'       => $account,
39
            'kind'          => 'native',
40
            'soa_edit_api'  => 'INCEPTION-INCREMENT',
41
            'masters'       => [],
42
            'name'          => Helper::canonical($name),
43
            'nameservers'   => [],
44
            'rrsets'        => array_merge($this->createSOA($name, $nameservers[0]), $this->createNS($name, $nameservers)),
45
        ];
46
    }
47
48
    public function upsertRecord($name, Typable $rrset)
49
    {
50
        $this->method = 'PATCH';
51
        $this->data = ['rrsets' => [$rrset->payload('REPLACE')]];
0 ignored issues
show
Unused Code introduced by
The call to Typable::payload() has too many arguments starting with 'REPLACE'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
52
        $this->appendToUri(sprintf('/%s', Helper::canonical($name)));
53
    }
54
55
    public function deleteRecord($name, Typable $rrset)
56
    {
57
        $this->method = 'PATCH';
58
        $this->data = ['rrsets' => [$rrset->payload('DELETE')]];
0 ignored issues
show
Unused Code introduced by
The call to Typable::payload() has too many arguments starting with 'DELETE'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
        $this->appendToUri(sprintf('/%s', Helper::canonical($name)));
60
    }
61
62
    protected function createNS($name, array $nameservers)
63
    {
64
        $rrsets = $records = [];
65
66
        foreach ($nameservers as $nameserver) {
67
            $records[] = [
68
                'content'   => Helper::canonical($nameserver),
69
                'disabled'  => false,
70
            ];
71
        }
72
73
        $rrsets[] = [
74
            'records'   => $records,
75
            'name'      => Helper::canonical($name),
76
            'ttl'       => 86400,
77
            'type'      => 'NS',
78
        ];
79
80
        return $rrsets;
81
    }
82
83
    protected function createSOA($name, $primary)
84
    {
85
        $rrsets = [
86
            'records' => [
87
                [
88
                    'content'   => sprintf(
89
                        // primary | contact | serial | refresh | retry | expire | ttl
90
                        '%s %s %s 3600 1800 604800 600',
91
                        Helper::canonical($primary),
92
                        Helper::canonical('dnsadmin.' . $name),
93
                        date('Ymd') . sprintf('%02d', rand(0, 99))
94
                     ),
95
                    'disabled'  => false,
96
                ],
97
            ],
98
            'name'      => Helper::canonical($name),
99
            'ttl'       => 86400,
100
            'type'      => 'SOA',
101
        ];
102
103
        return [$rrsets];
104
    }
105
}
106