Completed
Push — master ( 3fbd33...51cff9 )
by David
02:08
created

DnsRecord::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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