Completed
Push — master ( ef3dc6...e28065 )
by David
03:47
created

Mailgun/Model/Domain/AbstractDomainResponse.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * Copyright (C) 2013 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 Tobias Nyholm <[email protected]>
16
 */
17
abstract class AbstractDomainResponse implements ApiResponse
18
{
19
    /**
20
     * @var string
21
     */
22
    private $message;
23
24
    /**
25
     * @var Domain
26
     */
27
    private $domain;
28
29
    /**
30
     * @var DnsRecord[]
31
     */
32
    private $inboundDnsRecords;
33
34
    /**
35
     * @var DnsRecord[]
36
     */
37
    private $outboundDnsRecords;
38
39
    /**
40
     * @param array $data
41
     *
42
     * @return self
43
     */
44 2
    public static function create(array $data)
45
    {
46 2
        $rx = [];
47 2
        $tx = [];
48 2
        $domain = null;
49 2
        $message = null;
50
51 2
        if (isset($data['domain'])) {
52 2
            $domain = Domain::create($data['domain']);
53 2
        }
54
55 2
        if (isset($data['message'])) {
56 2
            $message = $data['message'];
57 2
        }
58
59 2 View Code Duplication
        if (isset($data['receiving_dns_records'])) {
60 2
            foreach ($data['receiving_dns_records'] as $item) {
61 1
                $rx[] = DnsRecord::create($item);
62 2
            }
63 2
        }
64
65 2 View Code Duplication
        if (isset($data['sending_dns_records'])) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
66 2
            foreach ($data['sending_dns_records'] as $item) {
67 1
                $tx[] = DnsRecord::create($item);
68 2
            }
69 2
        }
70
71 2
        return new static($domain, $rx, $tx, $message);
72
    }
73
74
    /**
75
     * @param Domain      $domainInfo
76
     * @param DnsRecord[] $rxRecords
77
     * @param DnsRecord[] $txRecords
78
     * @param string      $message
79
     */
80 2
    private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords, $message)
81
    {
82 2
        $this->domain = $domainInfo;
83 2
        $this->inboundDnsRecords = $rxRecords;
84 2
        $this->outboundDnsRecords = $txRecords;
85 2
        $this->message = $message;
86 2
    }
87
88
    /**
89
     * @return Domain
90
     */
91 1
    public function getDomain()
92
    {
93 1
        return $this->domain;
94
    }
95
96
    /**
97
     * @return DnsRecord[]
98
     */
99 1
    public function getInboundDNSRecords()
100
    {
101 1
        return $this->inboundDnsRecords;
102
    }
103
104
    /**
105
     * @return DnsRecord[]
106
     */
107 1
    public function getOutboundDNSRecords()
108
    {
109 1
        return $this->outboundDnsRecords;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 1
    public function getMessage()
116
    {
117 1
        return $this->message;
118
    }
119
}
120