Completed
Push — master ( da873d...74929b )
by Tobias
03:47
created

DnsRecord::create()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 7
cp 0
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 7
nc 32
nop 1
crap 42
1
<?php
2
3
/*
4
 * Copyright (C) 2013-2016 Mailgun
5
 *
6
 * This software may be modified and distributed under the terms
7
 * of the MIT license. See the LICENSE file for details.
8
 */
9
10
namespace Mailgun\Model\Domain;
11
12
/**
13
 * Represents a single DNS record for a domain.
14
 *
15
 * @author Sean Johnson <[email protected]>
16
 */
17
final class DnsRecord
18
{
19
    /**
20
     * @var string|null
21
     */
22
    private $name;
23
24
    /**
25
     * @var string
26
     */
27
    private $type;
28
29
    /**
30
     * @var string
31
     */
32
    private $value;
33
34
    /**
35
     * @var string|null
36
     */
37
    private $priority;
38
39
    /**
40
     * @var string
41
     */
42
    private $valid;
43
44
    /**
45
     * @param array $data
46
     *
47
     * @return self
48
     */
49
    public static function create(array $data)
50
    {
51
        $name = isset($data['name']) ? $data['name'] : null;
52
        $priority = isset($data['priority']) ? $data['priority'] : null;
53
        $recordType = isset($data['record_type']) ? $data['record_type'] : null;
54
        $value = isset($data['value']) ? $data['value'] : null;
55
        $valid = isset($data['valid']) ? $data['valid'] : null;
56
57
        return new self($name, $recordType, $value, $priority, $valid);
58
    }
59
60
    /**
61
     * @param string|null $name     Name of the record, as used in CNAME, etc.
62
     * @param string      $type     DNS record type
63
     * @param string      $value    DNS record value
64
     * @param string|null $priority Record priority, used for MX
65
     * @param string      $valid    DNS record has been added to domain DNS?
66
     */
67
    private function __construct($name, $type, $value, $priority, $valid)
68
    {
69
        $this->name = $name;
70
        $this->type = $type;
71
        $this->value = $value;
72
        $this->priority = $priority;
73
        $this->valid = $valid;
74
    }
75
76
    /**
77
     * @return string|null
78
     */
79
    public function getName()
80
    {
81
        return $this->name;
82
    }
83
84
    /**
85
     * @return string
86
     */
87
    public function getType()
88
    {
89
        return $this->type;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getValue()
96
    {
97
        return $this->value;
98
    }
99
100
    /**
101
     * @return string|null
102
     */
103
    public function getPriority()
104
    {
105
        return $this->priority;
106
    }
107
108
    /**
109
     * @return bool
110
     */
111
    public function isValid()
112
    {
113
        return 'valid' === $this->value;
114
    }
115
116
    /**
117
     * @return string
118
     */
119
    public function getValidity()
120
    {
121
        return $this->valid;
122
    }
123
}
124