GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 4531c4...f1c5f1 )
by
unknown
02:06
created

Lead::getFunnelId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace LPTracker\models;
4
5
use LPTracker\exceptions\LPTrackerSDKException;
6
7
/**
8
 * Class Lead
9
 * @package LPTracker\models
10
 */
11
class Lead extends Model
12
{
13
14
    /**
15
     * @var integer
16
     */
17
    protected $id;
18
19
    /**
20
     * @var integer
21
     */
22
    protected $contactId;
23
24
    /**
25
     * @var string
26
     */
27
    protected $name;
28
29
    /**
30
     * @var integer
31
     */
32
    protected $funnelId;
33
34
    /**
35
     * @var View
36
     */
37
    protected $view;
38
39
    /**
40
     * @var integer
41
     */
42
    protected $ownerId;
43
44
    /**
45
     * @var \DateTime
46
     */
47
    protected $createdAt;
48
49
    /**
50
     * @var Payment[]
51
     */
52
    protected $payments = [];
53
54
    /**
55
     * @var Custom[]
56
     */
57
    protected $customs = [];
58
59
    /**
60
     * @var array
61
     */
62
    protected $options = [];
63
64
65
    /**
66
     * Lead constructor.
67
     *
68
     * @param array $leadData
69
     */
70
    public function __construct(array $leadData = [])
71
    {
72
        if ( ! empty($leadData['id'])) {
73
            $this->id = intval($leadData['id']);
74
        }
75
        if ( ! empty($leadData['contact_id'])) {
76
            $this->contactId = intval($leadData['contact_id']);
77
        }
78
        if ( ! empty($leadData['name'])) {
79
            $this->name = $leadData['name'];
80
        }
81
        if ( ! empty($leadData['funnel'])) {
82
            $this->funnelId = intval($leadData['funnel']);
83
        }
84
        if ( ! empty($leadData['view'])) {
85
            $this->view = new View($leadData['view']);
86
        }
87
        if ( ! empty($leadData['owner'])) {
88
            $this->ownerId = intval($leadData['owner']);
89
        }
90
        if ( ! empty($leadData['payments']) && is_array($leadData['payments'])) {
91
            foreach ($leadData['payments'] as $paymentData) {
92
                $paymentModel = new Payment($paymentData);
93
                $this->addPayment($paymentModel);
94
            }
95
        }
96
        if ( ! empty($leadData['custom']) && is_array($leadData['custom'])) {
97
            foreach ($leadData['custom'] as $customData) {
98
                $customModel = new Custom($customData, $this->id);
99
                $this->addCustom($customModel);
100
            }
101
        }
102
        if ( ! empty($leadData['lead_date'])) {
103
            $date = \DateTime::createFromFormat('d.m.Y H:i', $leadData['lead_date']);
104
            $this->setCreatedAt($date);
105
        }
106
        if ( ! empty($leadData['deal_date'])) {
107
            $this->options['deal_date'] = $leadData['deal_date'];
108
        }
109
        if ( ! empty($leadData['params']) && is_array($leadData['params'])) {
110
            $this->options['params'] = $leadData['params'];
111
        }
112
    }
113
114
115
    /**
116
     * @param bool $toSave
117
     *
118
     * @return array
119
     */
120
    public function toArray($toSave = false)
121
    {
122
        $result = [
123
            'contact_id' => $this->contactId,
124
        ];
125
        if ( ! empty($this->id)) {
126
            $result['id'] = $this->getId();
127
        }
128
        if ( ! empty($this->name)) {
129
            $result['name'] = $this->getName();
130
        }
131
        if ( ! empty($this->funnelId)) {
132
            $result['funnel'] = $this->getFunnelId();
133
        }
134
        if ( ! empty($this->ownerId)) {
135
            $result['owner'] = $this->getOwnerId();
136
        }
137
        if ( ! empty($this->createdAt)) {
138
            $result['lead_date'] = $this->getCreatedAt()->format('d.m.Y H:i');
139
        }
140
        if ( ! empty($this->view)) {
141
            $result['view'] = $this->view->toArray();
142
        }
143
        foreach ($this->getPayments() as $payment) {
144
            $result['payments'][] = $payment->toArray();
145
        }
146
        foreach ($this->getCustoms() as $custom) {
147
            if ($toSave) {
148
                $result['custom'][$custom->getId()] = $custom->getValue();
149
            } else {
150
                $result['custom'][] = $custom->toArray();
151
            }
152
        }
153
        foreach ($this->options as $key => $value) {
154
            $result[$key] = $value;
155
        }
156
157
        return $result;
158
    }
159
160
161
    /**
162
     * @return bool
163
     * @throws LPTrackerSDKException
164
     */
165
    public function validate()
166
    {
167
        if (empty($this->contactId)) {
168
            throw new LPTrackerSDKException('Contact ID is required');
169
        }
170
        if (intval($this->contactId) <= 0) {
171
            throw new LPTrackerSDKException('Invalid contact id');
172
        }
173
        if ( ! empty($this->funnelId) && intval($this->funnelId) <= 0) {
174
            throw new LPTrackerSDKException('Invalid funnel ID');
175
        }
176
        if ( ! empty($this->ownerId) && intval($this->ownerId) < 0) {
177
            throw new LPTrackerSDKException('Invalid owner ID');
178
        }
179
        foreach ($this->getPayments() as $payment) {
180
            $payment->validate();
181
        }
182
183
        return true;
184
    }
185
186
187
    /**
188
     * @return int
189
     */
190
    public function getId()
191
    {
192
        return intval($this->id);
193
    }
194
195
196
    /**
197
     * @return int
198
     */
199
    public function getContactId()
200
    {
201
        return intval($this->contactId);
202
    }
203
204
205
    /**
206
     * @return string
207
     */
208
    public function getName()
209
    {
210
        return $this->name;
211
    }
212
213
214
    /**
215
     * @param string $name
216
     *
217
     * @return $this
218
     */
219
    public function setName($name)
220
    {
221
        $this->name = $name;
222
223
        return $this;
224
    }
225
226
227
    /**
228
     * @return int
229
     */
230
    public function getFunnelId()
231
    {
232
        return $this->funnelId;
233
    }
234
235
236
    /**
237
     * @param int $funnelId
238
     *
239
     * @return $this
240
     */
241
    public function setFunnelId($funnelId)
242
    {
243
        $this->funnelId = intval($funnelId);
244
245
        return $this;
246
    }
247
248
249
    /**
250
     * @return View
251
     */
252
    public function getView()
253
    {
254
        return $this->view;
255
    }
256
257
258
    /**
259
     * @return Payment[]
260
     */
261
    public function getPayments()
262
    {
263
        return $this->payments;
264
    }
265
266
267
    /**
268
     * @param array $payments
269
     *
270
     * @return $this
271
     */
272
    public function setPayments(array $payments)
273
    {
274
        $this->payments = $payments;
275
276
        return $this;
277
    }
278
279
280
    /**
281
     * @param Payment $payment
282
     *
283
     * @return $this
284
     */
285
    public function addPayment(Payment $payment)
286
    {
287
        $this->payments[] = $payment;
288
289
        return $this;
290
    }
291
292
293
    /**
294
     * @return int
295
     */
296
    public function getOwnerId()
297
    {
298
        return $this->ownerId;
299
    }
300
301
302
    /**
303
     * @param int $ownerId
304
     *
305
     * @return $this
306
     */
307
    public function setOwnerId($ownerId)
308
    {
309
        $this->ownerId = intval($ownerId);
310
311
        return $this;
312
    }
313
314
315
    /**
316
     * @return Custom[]
317
     */
318
    public function getCustoms()
319
    {
320
        return $this->customs;
321
    }
322
323
324
    /**
325
     * @param Custom[] $customs
326
     *
327
     * @return $this
328
     */
329
    public function setCustoms(array $customs)
330
    {
331
        $this->customs = $customs;
332
333
        return $this;
334
    }
335
336
337
    /**
338
     * @param Custom $custom
339
     *
340
     * @return $this
341
     */
342
    public function addCustom(Custom $custom)
343
    {
344
        $this->customs[] = $custom;
345
346
        return $this;
347
    }
348
349
350
    /**
351
     * @return \DateTime
352
     */
353
    public function getCreatedAt()
354
    {
355
        return $this->createdAt;
356
    }
357
358
359
    /**
360
     * @param \DateTime $createdAt
361
     *
362
     * @return $this
363
     */
364
    public function setCreatedAt($createdAt)
365
    {
366
        $this->createdAt = $createdAt;
367
368
        return $this;
369
    }
370
}