Completed
Push — master ( a1ca1a...6a943d )
by David
01:56
created

EmailValidation   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 19
lcom 0
cbo 1
dl 0
loc 157
ccs 0
cts 36
cp 0
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 2
B create() 0 13 9
A getAddress() 0 4 1
A getDidYouMean() 0 4 1
A isDisposableAddress() 0 4 1
A isRoleAddress() 0 4 1
A isValid() 0 4 1
A isMailboxVerification() 0 4 1
A getParts() 0 4 1
A getReason() 0 4 1
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\EmailValidation;
11
12
/**
13
 * @author David Garcia <[email protected]>
14
 */
15
final class EmailValidation
16
{
17
    /**
18
     * @var string|null
19
     */
20
    private $address;
21
22
    /**
23
     * @var string|null
24
     */
25
    private $didYouMean;
26
27
    /**
28
     * @var bool
29
     */
30
    private $isDisposableAddress;
31
32
    /**
33
     * @var bool
34
     */
35
    private $isRoleAddress;
36
37
    /**
38
     * @var bool
39
     */
40
    private $isValid;
41
42
    /**
43
     * @var bool
44
     */
45
    private $mailboxVerification;
46
47
    /**
48
     * @var Parts
49
     */
50
    private $parts;
51
52
    /**
53
     * @var string|null
54
     */
55
    private $reason;
56
57
    /**
58
     * EmailValidation constructor.
59
     *
60
     * @param string|null $address
61
     * @param string|null $didYouMean
62
     * @param bool        $isDisposableAddress
63
     * @param bool        $isRoleAddress
64
     * @param bool        $isValid
65
     * @param string|null $mailboxVerification
66
     * @param array       $parts
67
     * @param string|null $reason
68
     */
69
    private function __construct(
70
        $address,
71
        $didYouMean,
72
        $isDisposableAddress,
73
        $isRoleAddress,
74
        $isValid,
75
        $mailboxVerification,
76
        $parts,
77
        $reason
78
    ) {
79
        $this->address = $address;
80
        $this->didYouMean = $didYouMean;
81
        $this->isDisposableAddress = $isDisposableAddress;
82
        $this->isRoleAddress = $isRoleAddress;
83
        $this->isValid = $isValid;
84
        $this->mailboxVerification = 'true' === $mailboxVerification ? true : false;
85
        $this->parts = Parts::create($parts);
86
        $this->reason = $reason;
87
    }
88
89
    /**
90
     * @param array $data
91
     *
92
     * @return EmailValidation
93
     */
94
    public static function create(array $data)
95
    {
96
        return new self(
97
            (isset($data['address']) ? $data['address'] : null),
98
            (isset($data['did_you_mean']) ? $data['did_you_mean'] : null),
99
            (isset($data['is_disposable_address']) ? $data['is_disposable_address'] : false),
100
            (isset($data['is_role_address']) ? $data['is_role_address'] : false),
101
            (isset($data['is_valid']) ? $data['is_valid'] : false),
102
            (isset($data['mailbox_verification']) ? $data['mailbox_verification'] : null),
103
            (isset($data['parts']) ? $data['parts'] : []),
104
            (isset($data['reason']) ? $data['reason'] : null)
105
        );
106
    }
107
108
    /**
109
     * @return null|string
110
     */
111
    public function getAddress()
112
    {
113
        return $this->address;
114
    }
115
116
    /**
117
     * @return null|string
118
     */
119
    public function getDidYouMean()
120
    {
121
        return $this->didYouMean;
122
    }
123
124
    /**
125
     * @return bool
126
     */
127
    public function isDisposableAddress()
128
    {
129
        return $this->isDisposableAddress;
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function isRoleAddress()
136
    {
137
        return $this->isRoleAddress;
138
    }
139
140
    /**
141
     * @return bool
142
     */
143
    public function isValid()
144
    {
145
        return $this->isValid;
146
    }
147
148
    /**
149
     * @return bool
150
     */
151
    public function isMailboxVerification()
152
    {
153
        return $this->mailboxVerification;
154
    }
155
156
    /**
157
     * @return Parts
158
     */
159
    public function getParts()
160
    {
161
        return $this->parts;
162
    }
163
164
    /**
165
     * @return null|string
166
     */
167
    public function getReason()
168
    {
169
        return $this->reason;
170
    }
171
}
172