Passed
Pull Request — master (#3)
by Gombos
01:54
created

Subscriber::toDrip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
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 $key
30
     * @param $value
31
     *
32
     * @return Subscriber
33
     */
34
    public function addCustomField($key, $value): self
35
    {
36
        $this->custom_fields[$key] = $value;
37
38
        return $this;
39
    }
40
41
    /**
42
     * @param $key
43
     *
44
     * @return Subscriber
45
     */
46
    public function removeCustomField($key): self
47
    {
48
        if (!empty($this->custom_fields[$key])) {
49
            unset($this->custom_fields[$key]);
50
        }
51
52
        return $this;
53
    }
54
55
    /**
56
     * @param $key
57
     * @param $value
58
     *
59
     * @return Subscriber
60
     */
61
    public function addTag($key, $value): self
62
    {
63
        $this->tags[$key] = $value;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param $key
70
     *
71
     * @return Subscriber
72
     */
73
    public function removeTag($key): self
74
    {
75
        if (!empty($this->tags[$key])) {
76
            unset($this->tags[$key]);
77
        }
78
79
        return $this;
80
    }
81
82
    /**
83
     * @param string $email
84
     *
85
     * @return Subscriber
86
     */
87
    public function setEmail(string $email): self
88
    {
89
        $this->email = $email;
90
91
        return $this;
92
    }
93
94
    /**
95
     * @param string $new_email
96
     *
97
     * @return Subscriber
98
     */
99
    public function setNewEmail(string $new_email): self
100
    {
101
        $this->new_email = $new_email;
102
103
        return $this;
104
    }
105
106
    /**
107
     * @param string $user_id
108
     *
109
     * @return Subscriber
110
     */
111
    public function setUserId(string $user_id): self
112
    {
113
        $this->user_id = $user_id;
114
115
        return $this;
116
    }
117
118
    /**
119
     * @param string $time_zone
120
     *
121
     * @return Subscriber
122
     */
123
    public function setTimeZone(string $time_zone): self
124
    {
125
        $this->time_zone = $time_zone;
126
127
        return $this;
128
    }
129
130
    /**
131
     * @param string $ip_address
132
     *
133
     * @return Subscriber
134
     */
135
    public function setIpAddress(string $ip_address): self
136
    {
137
        $this->ip_address = $ip_address;
138
139
        return $this;
140
    }
141
142
    /**
143
     * @param array $custom_fields
144
     *
145
     * @return Subscriber
146
     */
147
    public function setCustomFields(array $custom_fields): self
148
    {
149
        $this->custom_fields = $custom_fields;
150
151
        return $this;
152
    }
153
154
    /**
155
     * @param array $tags
156
     *
157
     * @return Subscriber
158
     */
159
    public function setTags(array $tags): self
160
    {
161
        $this->tags = $tags;
162
163
        return $this;
164
    }
165
166
    /**
167
     * @param array $remove_tags
168
     *
169
     * @return Subscriber
170
     */
171
    public function setRemoveTags(array $remove_tags): self
172
    {
173
        $this->remove_tags = $remove_tags;
174
175
        return $this;
176
    }
177
178
    public function toDrip(): array
179
    {
180
        return [
181
            "subscribers" => [
182
                $this->jsonSerialize(),
183
            ],
184
        ];
185
    }
186
}
187