Passed
Push — master ( 756e7a...85d7cc )
by Gombos
02:17
created

Subscriber::getEmail()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Glorand\Drip\Models;
4
5
use Glorand\Drip\Models\Traits\Jsonable;
6
7
class Subscriber
8
{
9
    use Jsonable;
10
11
    /** @var string */
12
    protected $email;
13
    /** @var string */
14
    protected $new_email;
15
    /** @var string */
16
    protected $user_id;
17
    /** @var string */
18
    protected $time_zone;
19
    /** @var string */
20
    protected $ip_address;
21
    /** @var array */
22
    protected $custom_fields;
23
    /** @var array */
24
    protected $tags;
25
    /** @var array */
26
    protected $remove_tags;
27
28
    /**
29
     * @param string $key
30
     * @param string $value
31
     *
32
     * @return Subscriber
33
     */
34 1
    public function addCustomField(string $key, string $value): self
35
    {
36 1
        $this->custom_fields[$key] = $value;
37
38 1
        return $this;
39
    }
40
41
    /**
42
     * @param string $key
43
     *
44
     * @return Subscriber
45
     */
46 1
    public function removeCustomField(string $key): self
47
    {
48 1
        if (!empty($this->custom_fields[$key])) {
49 1
            unset($this->custom_fields[$key]);
50
        }
51
52 1
        return $this;
53
    }
54
55
    /**
56
     * @param string $key
57
     * @param string $value
58
     *
59
     * @return Subscriber
60
     */
61 1
    public function addTag(string $key, string $value): self
62
    {
63 1
        $this->tags[$key] = $value;
64
65 1
        return $this;
66
    }
67
68
    /**
69
     * @param string $key
70
     *
71
     * @return Subscriber
72
     */
73 1
    public function removeTag(string $key): self
74
    {
75 1
        if (!empty($this->tags[$key])) {
76 1
            unset($this->tags[$key]);
77
        }
78
79 1
        return $this;
80
    }
81
82
    /**
83
     * @param string $email
84
     *
85
     * @return Subscriber
86
     */
87 4
    public function setEmail(string $email): self
88
    {
89 4
        $this->email = $email;
90
91 4
        return $this;
92
    }
93
94
    /**
95
     * @return string
96
     */
97 1
    public function getEmail(): string
98
    {
99 1
        return $this->email;
100
    }
101
102
    /**
103
     * @param string $new_email
104
     *
105
     * @return Subscriber
106
     */
107 1
    public function setNewEmail(string $new_email): self
108
    {
109 1
        $this->new_email = $new_email;
110
111 1
        return $this;
112
    }
113
114
    /**
115
     * @param string $user_id
116
     *
117
     * @return Subscriber
118
     */
119 1
    public function setUserId(string $user_id): self
120
    {
121 1
        $this->user_id = $user_id;
122
123 1
        return $this;
124
    }
125
126
    /**
127
     * @param string $time_zone
128
     *
129
     * @return Subscriber
130
     */
131 2
    public function setTimeZone(string $time_zone): self
132
    {
133 2
        $this->time_zone = $time_zone;
134
135 2
        return $this;
136
    }
137
138
    /**
139
     * @param string $ip_address
140
     *
141
     * @return Subscriber
142
     */
143 1
    public function setIpAddress(string $ip_address): self
144
    {
145 1
        $this->ip_address = $ip_address;
146
147 1
        return $this;
148
    }
149
150
    /**
151
     * @param array $custom_fields
152
     *
153
     * @return Subscriber
154
     */
155 1
    public function setCustomFields(array $custom_fields): self
156
    {
157 1
        $this->custom_fields = $custom_fields;
158
159 1
        return $this;
160
    }
161
162
    /**
163
     * @param array $tags
164
     *
165
     * @return Subscriber
166
     */
167 1
    public function setTags(array $tags): self
168
    {
169 1
        $this->tags = $tags;
170
171 1
        return $this;
172
    }
173
174
    /**
175
     * @param array $remove_tags
176
     *
177
     * @return Subscriber
178
     */
179 1
    public function setRemoveTags(array $remove_tags): self
180
    {
181 1
        $this->remove_tags = $remove_tags;
182
183 1
        return $this;
184
    }
185
186 2
    public function toDrip(): array
187
    {
188
        return [
189
            "subscribers" => [
190 2
                $this->jsonSerialize(),
191
            ],
192
        ];
193
    }
194
}
195