Completed
Push — master ( b3f24e...84a5c5 )
by Tobias
03:15
created

ShowResponse::create()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 12
cp 0
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 8
nop 1
crap 20
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\Suppression\Bounce;
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 string
21
     */
22
    private $address;
23
24
    /**
25
     * @var string
26
     */
27
    private $code;
28
29
    /**
30
     * @var string
31
     */
32
    private $error;
33
34
    /**
35
     * @var \DateTime
36
     */
37
    private $createdAt;
38
39
    /**
40
     * @param string $address
41
     */
42
    private function __construct($address)
43
    {
44
        $this->address = $address;
45
        $this->createdAt = new \DateTime();
46
    }
47
48
    /**
49
     * @param array $data
50
     *
51
     * @return ShowResponse
52
     */
53
    public static function create(array $data)
54
    {
55
        $bounce = new self($data['address']);
56
57
        if (isset($data['code'])) {
58
            $bounce->setCode($data['code']);
59
        }
60
        if (isset($data['error'])) {
61
            $bounce->setError($data['error']);
62
        }
63
        if (isset($data['created_at'])) {
64
            $bounce->setCreatedAt(new \DateTime($data['created_at']));
65
        }
66
67
        return $bounce;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getAddress()
74
    {
75
        return $this->address;
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getCode()
82
    {
83
        return $this->code;
84
    }
85
86
    /**
87
     * @param string $code
88
     */
89
    private function setCode($code)
90
    {
91
        $this->code = $code;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getError()
98
    {
99
        return $this->error;
100
    }
101
102
    /**
103
     * @param string $error
104
     */
105
    private function setError($error)
106
    {
107
        $this->error = $error;
108
    }
109
110
    /**
111
     * @return \DateTime
112
     */
113
    public function getCreatedAt()
114
    {
115
        return $this->createdAt;
116
    }
117
118
    /**
119
     * @param \DateTime $createdAt
120
     */
121
    private function setCreatedAt(\DateTime $createdAt)
122
    {
123
        $this->createdAt = $createdAt;
124
    }
125
}
126