Completed
Push — master ( b6d035...da6ee3 )
by Sean
03:40
created

ShowResponse::create()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 9
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 1
crap 12
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\Resource\Api\Suppressions\Unsubscribe;
11
12
use Mailgun\Resource\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 $tag;
28
29
    /**
30
     * @var \DateTime
31
     */
32
    private $createdAt;
33
34
    /**
35
     * @param string $address
36
     */
37
    private function __construct($address)
38
    {
39
        $this->address = $address;
40
        $this->createdAt = new \DateTime();
41
    }
42
43
    /**
44
     * @param array $data
45
     *
46
     * @return ShowResponse
47
     */
48
    public static function create(array $data)
49
    {
50
        $unsubscribe = new self($data['address']);
51
52
        if (isset($data['tag'])) {
53
            $this->setTag($data['tag']);
0 ignored issues
show
Bug introduced by
The variable $this does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
54
        }
55
        if (isset($data['created_at'])) {
56
            $this->setCreatedAt(new \DateTime($data['created_at']));
57
        }
58
59
        return $unsubscribe;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getAddress()
66
    {
67
        return $this->address;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getTag()
74
    {
75
        return $this->tag;
76
    }
77
78
    /**
79
     * @param string $tag
80
     */
81
    private function setTag($tag)
82
    {
83
        $this->tag = $tag;
84
    }
85
86
    /**
87
     * @return \DateTime
88
     */
89
    public function getCreatedAt()
90
    {
91
        return $this->createdAt;
92
    }
93
94
    /**
95
     * @param \DateTime $createdAt
96
     */
97
    private function setCreatedAt(\DateTime $createdAt)
98
    {
99
        $this->createdAt = $createdAt;
100
    }
101
}
102