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

Domain   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 16
lcom 0
cbo 0
dl 0
loc 131
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
B create() 0 12 8
A __construct() 0 10 1
A getName() 0 4 1
A getSmtpUsername() 0 4 1
A getSmtpPassword() 0 4 1
A isWildcard() 0 4 1
A getSpamAction() 0 4 1
A getState() 0 4 1
A getCreatedAt() 0 4 1
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
/**
13
 * Represents domain information in its simplest form.
14
 *
15
 * @author Sean Johnson <[email protected]>
16
 */
17
final class Domain
18
{
19
    /**
20
     * @var \DateTime
21
     */
22
    private $createdAt;
23
24
    /**
25
     * @var string
26
     */
27
    private $smtpLogin;
28
29
    /**
30
     * @var string
31
     */
32
    private $name;
33
34
    /**
35
     * @var string
36
     */
37
    private $smtpPassword;
38
39
    /**
40
     * @var bool
41
     */
42
    private $wildcard;
43
44
    /**
45
     * @var string
46
     */
47
    private $spamAction;
48
49
    /**
50
     * @var string
51
     */
52
    private $state;
53
54
    /**
55
     * @param array $data
56
     *
57
     * @return self
58
     */
59
    public static function create(array $data)
60
    {
61
        return new self(
62
            isset($data['name']) ? $data['name'] : null,
63
            isset($data['smtp_login']) ? $data['smtp_login'] : null,
64
            isset($data['smtp_password']) ? $data['smtp_password'] : null,
65
            isset($data['wildcard']) ? $data['wildcard'] : null,
66
            isset($data['spam_action']) ? $data['spam_action'] : null,
67
            isset($data['state']) ? $data['state'] : null,
68
            isset($data['created_at']) ? new \DateTime($data['created_at']) : null
0 ignored issues
show
Bug introduced by
It seems like isset($data['created_at'...a['created_at']) : null can be null; however, __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...
69
        );
70
    }
71
72
    /**
73
     * @param string    $name
74
     * @param string    $smtpLogin
75
     * @param string    $smtpPassword
76
     * @param bool      $wildcard
77
     * @param string    $spamAction
78
     * @param string    $state
79
     * @param \DateTime $createdAt
80
     */
81
    private function __construct($name, $smtpLogin, $smtpPassword, $wildcard, $spamAction, $state, \DateTime $createdAt)
82
    {
83
        $this->name = $name;
84
        $this->smtpLogin = $smtpLogin;
85
        $this->smtpPassword = $smtpPassword;
86
        $this->wildcard = $wildcard;
87
        $this->spamAction = $spamAction;
88
        $this->state = $state;
89
        $this->createdAt = $createdAt;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getName()
96
    {
97
        return $this->name;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getSmtpUsername()
104
    {
105
        return $this->smtpLogin;
106
    }
107
108
    /**
109
     * @return string
110
     */
111
    public function getSmtpPassword()
112
    {
113
        return $this->smtpPassword;
114
    }
115
116
    /**
117
     * @return bool
118
     */
119
    public function isWildcard()
120
    {
121
        return $this->wildcard;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getSpamAction()
128
    {
129
        return $this->spamAction;
130
    }
131
132
    /**
133
     * @return string
134
     */
135
    public function getState()
136
    {
137
        return $this->state;
138
    }
139
140
    /**
141
     * @return \DateTime
142
     */
143
    public function getCreatedAt()
144
    {
145
        return $this->createdAt;
146
    }
147
}
148