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

ShowResponse::create()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 24
Code Lines 13

Duplication

Lines 10
Ratio 41.67 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 10
loc 24
ccs 0
cts 18
cp 0
rs 8.5125
c 0
b 0
f 0
cc 6
eloc 13
nc 8
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
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'])) {
0 ignored issues
show
Duplication introduced by
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...
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'])) {
0 ignored issues
show
Duplication introduced by
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...
56
            foreach ($data['sending_dns_records'] as $item) {
57
                $tx[] = DnsRecord::create($item);
58
            }
59
        }
60
61
        return new self($domain, $rx, $tx);
0 ignored issues
show
Bug introduced by
It seems like $domain defined by null on line 43 can be null; however, Mailgun\Model\Domain\ShowResponse::__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...
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