Completed
Pull Request — master (#4)
by Gombos
02:36
created

Subscriber::setCustomFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
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 2
    public function setEmail(string $email): self
88
    {
89 2
        $this->email = $email;
90
91 2
        return $this;
92
    }
93
94
    /**
95
     * @param string $new_email
96
     *
97
     * @return Subscriber
98
     */
99 1
    public function setNewEmail(string $new_email): self
100
    {
101 1
        $this->new_email = $new_email;
102
103 1
        return $this;
104
    }
105
106
    /**
107
     * @param string $user_id
108
     *
109
     * @return Subscriber
110
     */
111 1
    public function setUserId(string $user_id): self
112
    {
113 1
        $this->user_id = $user_id;
114
115 1
        return $this;
116
    }
117
118
    /**
119
     * @param string $time_zone
120
     *
121
     * @return Subscriber
122
     */
123 1
    public function setTimeZone(string $time_zone): self
124
    {
125 1
        $this->time_zone = $time_zone;
126
127 1
        return $this;
128
    }
129
130
    /**
131
     * @param string $ip_address
132
     *
133
     * @return Subscriber
134
     */
135 1
    public function setIpAddress(string $ip_address): self
136
    {
137 1
        $this->ip_address = $ip_address;
138
139 1
        return $this;
140
    }
141
142
    /**
143
     * @param array $custom_fields
144
     *
145
     * @return Subscriber
146
     */
147 1
    public function setCustomFields(array $custom_fields): self
148
    {
149 1
        $this->custom_fields = $custom_fields;
150
151 1
        return $this;
152
    }
153
154
    /**
155
     * @param array $tags
156
     *
157
     * @return Subscriber
158
     */
159 1
    public function setTags(array $tags): self
160
    {
161 1
        $this->tags = $tags;
162
163 1
        return $this;
164
    }
165
166
    /**
167
     * @param array $remove_tags
168
     *
169
     * @return Subscriber
170
     */
171 1
    public function setRemoveTags(array $remove_tags): self
172
    {
173 1
        $this->remove_tags = $remove_tags;
174
175 1
        return $this;
176
    }
177
178 2
    public function toDrip(): array
179
    {
180
        return [
181
            "subscribers" => [
182 2
                $this->jsonSerialize(),
183
            ],
184
        ];
185
    }
186
}
187