Completed
Push — master ( 8187a4...e80003 )
by Tobias
03:13
created

VerifyResponse::create()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 29
Code Lines 16

Duplication

Lines 29
Ratio 100 %

Code Coverage

Tests 20
CRAP Score 7.0368

Importance

Changes 0
Metric Value
dl 29
loc 29
ccs 20
cts 22
cp 0.9091
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 16
nop 1
crap 7.0368
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 Maxim Zasorin <[email protected]>
16
 */
17 View Code Duplication
final class VerifyResponse implements ApiResponse
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
18
{
19
    /**
20
     * @var Domain
21
     */
22
    private $domain;
23
24
    /**
25
     * @var string
26
     */
27
    private $message;
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 1
    public static function create(array $data)
45
    {
46 1
        $rx = [];
47 1
        $tx = [];
48 1
        $domain = null;
49 1
        $message = null;
50
51 1
        if (isset($data['domain'])) {
52 1
            $domain = Domain::create($data['domain']);
53 1
        }
54
55 1
        if (isset($data['message'])) {
56 1
            $message = $data['message'];
57 1
        }
58
59 1
        if (isset($data['receiving_dns_records'])) {
60 1
            foreach ($data['receiving_dns_records'] as $item) {
61
                $rx[] = DnsRecord::create($item);
62 1
            }
63 1
        }
64
65 1
        if (isset($data['sending_dns_records'])) {
66 1
            foreach ($data['sending_dns_records'] as $item) {
67
                $tx[] = DnsRecord::create($item);
68 1
            }
69 1
        }
70
71 1
        return new self($domain, $rx, $tx, $message);
0 ignored issues
show
Bug introduced by
It seems like $domain defined by null on line 48 can be null; however, Mailgun\Model\Domain\VerifyResponse::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
72
    }
73
74
    /**
75
     * @param Domain      $domainInfo
76
     * @param DnsRecord[] $rxRecords
77
     * @param DnsRecord[] $txRecords
78
     * @param string      $message
79
     */
80 1
    private function __construct(Domain $domainInfo, array $rxRecords, array $txRecords, $message)
81
    {
82 1
        $this->domain = $domainInfo;
83 1
        $this->inboundDnsRecords = $rxRecords;
84 1
        $this->outboundDnsRecords = $txRecords;
85 1
        $this->message = $message;
86 1
    }
87
88
    /**
89
     * @return Domain
90
     */
91
    public function getDomain()
92
    {
93
        return $this->domain;
94
    }
95
96
    /**
97
     * @return DnsRecord[]
98
     */
99
    public function getInboundDNSRecords()
100
    {
101
        return $this->inboundDnsRecords;
102
    }
103
104
    /**
105
     * @return DnsRecord[]
106
     */
107
    public function getOutboundDNSRecords()
108
    {
109
        return $this->outboundDnsRecords;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 1
    public function getMessage()
116
    {
117 1
        return $this->message;
118
    }
119
}
120