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
|
|
|
use Mailgun\Model\ApiResponse; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @author Sean Johnson <[email protected]> |
16
|
|
|
*/ |
17
|
|
|
final class ShowResponse implements ApiResponse |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var Domain |
21
|
|
|
*/ |
22
|
|
|
private $domain; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var DnsRecord[] |
26
|
|
|
*/ |
27
|
|
|
private $inboundDnsRecords; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var DnsRecord[] |
31
|
|
|
*/ |
32
|
|
|
private $outboundDnsRecords; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array $data |
36
|
|
|
* |
37
|
|
|
* @return self |
38
|
|
|
*/ |
39
|
|
|
public static function create(array $data) |
40
|
|
|
{ |
41
|
|
|
$rx = []; |
42
|
|
|
$tx = []; |
43
|
|
|
$domain = null; |
44
|
|
|
|
45
|
|
|
if (isset($data['domain'])) { |
46
|
|
|
$domain = Domain::create($data['domain']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
View Code Duplication |
if (isset($data['receiving_dns_records'])) { |
|
|
|
|
50
|
|
|
foreach ($data['receiving_dns_records'] as $item) { |
51
|
|
|
$rx[] = DnsRecord::create($item); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
if (isset($data['sending_dns_records'])) { |
|
|
|
|
56
|
|
|
foreach ($data['sending_dns_records'] as $item) { |
57
|
|
|
$tx[] = DnsRecord::create($item); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return new self($domain, $rx, $tx); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param Domain $domainInfo |
66
|
|
|
* @param DnsRecord[] $rxRecords |
67
|
|
|
* @param DnsRecord[] $txRecords |
68
|
|
|
*/ |
69
|
|
|
private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords) |
70
|
|
|
{ |
71
|
|
|
$this->domain = $domainInfo; |
72
|
|
|
$this->inboundDnsRecords = $rxRecords; |
73
|
|
|
$this->outboundDnsRecords = $txRecords; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @return Domain |
78
|
|
|
*/ |
79
|
|
|
public function getDomain() |
80
|
|
|
{ |
81
|
|
|
return $this->domain; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @return DnsRecord[] |
86
|
|
|
*/ |
87
|
|
|
public function getInboundDNSRecords() |
88
|
|
|
{ |
89
|
|
|
return $this->inboundDnsRecords; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @return DnsRecord[] |
94
|
|
|
*/ |
95
|
|
|
public function getOutboundDNSRecords() |
96
|
|
|
{ |
97
|
|
|
return $this->outboundDnsRecords; |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.