Type   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A payload() 0 28 5
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\Types;
13
14
use AfriCC\Pdns\Helper;
15
16
abstract class Type implements Typable
17
{
18
    protected $name;
19
20
    protected $content;
21
22
    protected $ttl;
23
24
    public function __construct($name, $content = [], $ttl = 300)
25
    {
26
        $this->name = $name;
27
28
        if (!is_array($content)) {
29
            $this->content = [$content];
30
        } else {
31
            $this->content = $content;
32
        }
33
34
        $this->ttl = (int) $ttl;
35
    }
36
37
    public function payload($changetype = null)
38
    {
39
        $rrset = [
40
            'name'      => Helper::canonical($this->name),
41
            'type'      => Helper::className($this),
42
        ];
43
44
        if ($changetype !== null && $changetype === 'DELETE') {
45
            $rrset['records'] = [];
46
        } else {
47
            $records = [];
48
            foreach ($this->content as $record) {
49
                $records[] = [
50
                    'content'   => $record,
51
                    'disabled'  => false,
52
                ];
53
            }
54
55
            $rrset['ttl'] = $this->ttl;
56
            $rrset['records'] = $records;
57
        }
58
59
        if ($changetype !== null) {
60
            $rrset['changetype'] = $changetype;
61
        }
62
63
        return $rrset;
64
    }
65
}
66