ResourceRecord   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
c 1
b 0
f 0
dl 0
loc 101
ccs 19
cts 19
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A __construct() 0 4 1
A getTtl() 0 3 1
A isValidType() 0 14 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Afonso\Dns;
6
7
/**
8
 * This class represents a DNS Resource Record.
9
 */
10
abstract class ResourceRecord implements ResourceRecordInterface
11
{
12
    /**
13
     * @var int
14
     */
15
    const TYPE_A = 0x0001;
16
17
    /**
18
     * @var int
19
     */
20
    const TYPE_NS = 0x0002;
21
22
    /**
23
     * @var int
24
     */
25
    const TYPE_CNAME = 0x0005;
26
27
    /**
28
     * @var int
29
     */
30
    const TYPE_SOA = 0x0006;
31
32
    /**
33
     * @var int
34
     */
35
    const TYPE_PTR = 0x000C;
36
37
    /**
38
     * @var int
39
     */
40
    const TYPE_MX = 0x000F;
41
42
    /**
43
     * @var int
44
     */
45
    const TYPE_SRV = 0x0021;
46
47
    /**
48
     * @var int
49
     */
50
    const TYPE_AAAA = 0x001C;
51
52
    /**
53
     * @var int
54
     */
55
    const TYPE_ANY = 0x00FF;
56
57
    /**
58
     * @var string
59
     */
60
    protected $name;
61
62
    /**
63
     * @var int
64
     */
65
    protected $type;
66
67
    /**
68
     * @var int
69
     */
70
    protected $ttl;
71
72 78
    public function __construct(string $name, int $ttl)
73
    {
74 78
        $this->name = $name;
75 78
        $this->ttl = $ttl;
76 78
    }
77
78
    abstract public function getType(): int;
79
80 9
    public function getName(): string
81
    {
82 9
        return $this->name;
83
    }
84
85 27
    public function getTtl(): int
86
    {
87 27
        return $this->ttl;
88
    }
89
90
    /**
91
     * Return whether the specified value is a supported Resource Record type
92
     * in this library.
93
     *
94
     * @param int $type
95
     * @return bool
96
     */
97 42
    public static function isValidType(int $type): bool
98
    {
99
        $validTypes = [
100 42
            static::TYPE_A,
101 42
            static::TYPE_NS,
102 42
            static::TYPE_CNAME,
103 42
            static::TYPE_SOA,
104 42
            static::TYPE_PTR,
105 42
            static::TYPE_MX,
106 42
            static::TYPE_SRV,
107 42
            static::TYPE_AAAA,
108 42
            static::TYPE_ANY
109
        ];
110 42
        return in_array($type, $validTypes);
111
    }
112
}
113