Completed
Push — master ( 1129fe...06220a )
by Mauro
02:58
created

LeadData::setCity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Zephia\PilotApiClient\Model;
4
5
use Zephia\PilotApiClient\Exception\InvalidArgumentException;
6
7
class LeadData
8
{
9
    private $firstname;
10
    private $lastname;
11
    private $phone;
12
    private $cellphone;
13
    private $email;
14
    private $contact_type_id;
15
    private $business_type_id;
16
    private $notes;
17
    private $origin_id;
18
    private $suborigin_id;
19
    private $assigned_user;
20
    private $car_brand;
21
    private $car_modelo;
22
    private $city;
23
    private $province;
24
    private $country;
25
    private $vendor_name;
26
    private $vendor_email;
27
    private $vendor_phone;
28
    private $provider_service;
29
    private $provider_url;
30
31
    /**
32
     * LeadData constructor.
33
     *
34
     * @param array $data
35
     */
36 27
    public function __construct($data = [])
37
    {
38 27
        if (count($data) > 0) {
39 26
            foreach ($data as $key => $value) {
40 26
                $this->set($key, $value);
41 26
            }
42 26
            $this->validate();
43 4
        }
44 5
    }
45
46
    /**
47
     * Object to array
48
     *
49
     * @return array
50
     */
51 25
    public function toArray()
52
    {
53 25
        $this->validate();
54
        return [
55 4
            'pilot_firstname' => $this->getFirstname(),
56 4
            'pilot_lastname' => $this->getLastname(),
57 4
            'pilot_phone' => $this->getPhone(),
58 4
            'pilot_cellphone' => $this->getCellphone(),
59 4
            'pilot_email' => $this->getEmail(),
60 4
            'pilot_contact_type_id' => $this->getContactTypeId(),
61 4
            'pilot_business_type_id' => $this->getBusinessTypeId(),
62 4
            'pilot_notes' => $this->getNotes(),
63 4
            'pilot_origin_id' => $this->getOriginId(),
64 4
            'pilot_suborigin_id' => $this->getSuboriginId(),
65 4
            'pilot_assigned_user' => $this->getAssignedUser(),
66 4
            'pilot_car_brand' => $this->getCarBrand(),
67 4
            'pilot_car_modelo' => $this->getCarModelo(),
68 4
            'pilot_city' => $this->getCity(),
69 4
            'pilot_province' => $this->getProvince(),
70 4
            'pilot_country' => $this->getCountry(),
71 4
            'pilot_vendor_name' => $this->getVendorName(),
72 4
            'pilot_vendor_email' => $this->getVendorEmail(),
73 4
            'pilot_vendor_phone' => $this->getVendorPhone(),
74 4
            'pilot_provider_service' => $this->getProviderService(),
75 4
            'pilot_provider_url' => $this->getProviderUrl()
76 4
        ];
77
    }
78
79
    /**
80
     * Validate
81
     *
82
     * @throws InvalidArgumentException
83
     */
84 47
    private function validate()
85
    {
86 47
        $required = '';
87
88 47
        if (empty($this->getFirstname()) && empty($this->getLastname())) {
89 1
            $required = "firstname or lastname";
90 1
        }
91 47
        if (empty($this->getPhone())
92 47
            && empty($this->getCellphone())
93 47
            && empty($this->getEmail())
94 47
            && empty($required)) {
95 6
            $required = "phone, cellphone or email";
96 6
        }
97 47
        if (empty($this->getContactTypeId()) && empty($required)) {
98 12
            $required = "contact_type_id";
99 12
        }
100 47
        if (empty($this->getBusinessTypeId()) && empty($required)) {
101 12
            $required = "business_type_id";
102 12
        }
103 47
        if (empty($this->getSuboriginId()) && empty($required)) {
104 12
            $required = "suborigin_id";
105 12
        }
106
107 47
        if (!empty($required)) {
108 43
            throw new InvalidArgumentException(
109 43
                sprintf('Missing required value: %s.', $required)
110 43
            );
111
        }
112 4
    }
113
114
    /**
115
     * Set
116
     *
117
     * @param $key
118
     * @param string $value
119
     */
120 26
    private function set($key, $value = "")
121
    {
122 26
        if (property_exists($this, $key)) {
123 26
            $key = implode('', array_map('ucfirst', explode('_', $key)));
124 26
            $this->{'set' . $key}($value);
125 26
        }
126 26
    }
127
128
    /**
129
     * @return mixed
130
     */
131 48
    public function getFirstname()
132
    {
133 48
        return $this->firstname;
134
    }
135
136
    /**
137
     * @param $firstname
138
     *
139
     * @return $this
140
     */
141 17
    public function setFirstname($firstname)
142
    {
143 17
        $this->firstname = $firstname;
144 17
        return $this;
145
    }
146
147
    /**
148
     * @return mixed
149
     */
150 26
    public function getLastname()
151
    {
152 26
        return $this->lastname;
153
    }
154
155
    /**
156
     * @param $lastname
157
     *
158
     * @return $this
159
     */
160 13
    public function setLastname($lastname)
161
    {
162 13
        $this->lastname = $lastname;
163 13
        return $this;
164
    }
165
166
    /**
167
     * @return mixed
168
     */
169 48
    public function getPhone()
170
    {
171 48
        return $this->phone;
172
    }
173
174
    /**
175
     * @param $phone
176
     *
177
     * @return $this
178
     */
179 11
    public function setPhone($phone)
180
    {
181 11
        $this->phone = $phone;
182 11
        return $this;
183
    }
184
185
    /**
186
     * @return mixed
187
     */
188 36
    public function getCellphone()
189
    {
190 36
        return $this->cellphone;
191
    }
192
193
    /**
194
     * @param $cellphone
195
     *
196
     * @return $this
197
     */
198 7
    public function setCellphone($cellphone)
199
    {
200 7
        $this->cellphone = $cellphone;
201 7
        return $this;
202
    }
203
204
    /**
205
     * @return mixed
206
     */
207 24
    public function getEmail()
208
    {
209 24
        return $this->email;
210
    }
211
212
    /**
213
     * @param $email
214
     *
215
     * @return $this
216
     */
217 7
    public function setEmail($email)
218
    {
219 7
        $this->email = $email;
220 7
        return $this;
221
    }
222
223
    /**
224
     * @return mixed
225
     */
226 48
    public function getContactTypeId()
227
    {
228 48
        return $this->contact_type_id;
229
    }
230
231
    /**
232
     * @param $contact_type_id
233
     *
234
     * @return $this
235
     */
236 19
    public function setContactTypeId($contact_type_id)
237
    {
238 19
        $this->contact_type_id = $contact_type_id;
239 19
        return $this;
240
    }
241
242
    /**
243
     * @return mixed
244
     */
245 48
    public function getBusinessTypeId()
246
    {
247 48
        return $this->business_type_id;
248
    }
249
250
    /**
251
     * @param $business_type_id
252
     *
253
     * @return $this
254
     */
255 13
    public function setBusinessTypeId($business_type_id)
256
    {
257 13
        $this->business_type_id = $business_type_id;
258 13
        return $this;
259
    }
260
261
    /**
262
     * @return mixed
263
     */
264 5
    public function getNotes()
265
    {
266 5
        return $this->notes;
267
    }
268
269
    /**
270
     * @param $notes
271
     *
272
     * @return $this
273
     */
274 1
    public function setNotes($notes)
275
    {
276 1
        $this->notes = $notes;
277 1
        return $this;
278
    }
279
280
    /**
281
     * @return mixed
282
     */
283 5
    public function getOriginId()
284
    {
285 5
        return $this->origin_id;
286
    }
287
288
    /**
289
     * @param $origin_id
290
     *
291
     * @return $this
292
     */
293 1
    public function setOriginId($origin_id)
294
    {
295 1
        $this->origin_id = $origin_id;
296 1
        return $this;
297
    }
298
299
    /**
300
     * @return mixed
301
     */
302 48
    public function getSuboriginId()
303
    {
304 48
        return $this->suborigin_id;
305
    }
306
307
    /**
308
     * @param $suborigin_id
309
     *
310
     * @return $this
311
     */
312 7
    public function setSuboriginId($suborigin_id)
313
    {
314 7
        $this->suborigin_id = $suborigin_id;
315 7
        return $this;
316
    }
317
318
    /**
319
     * @return mixed
320
     */
321 5
    public function getAssignedUser()
322
    {
323 5
        return $this->assigned_user;
324
    }
325
326
    /**
327
     * @param $assigned_user
328
     *
329
     * @return $this
330
     */
331 1
    public function setAssignedUser($assigned_user)
332
    {
333 1
        $this->assigned_user = $assigned_user;
334 1
        return $this;
335
    }
336
337
    /**
338
     * @return mixed
339
     */
340 5
    public function getCarBrand()
341
    {
342 5
        return $this->car_brand;
343
    }
344
345
    /**
346
     * @param $car_brand
347
     *
348
     * @return $this
349
     */
350 1
    public function setCarBrand($car_brand)
351
    {
352 1
        $this->car_brand = $car_brand;
353 1
        return $this;
354
    }
355
356
    /**
357
     * @return mixed
358
     */
359 5
    public function getCarModelo()
360
    {
361 5
        return $this->car_modelo;
362
    }
363
364
    /**
365
     * @param $car_modelo
366
     *
367
     * @return $this
368
     */
369 1
    public function setCarModelo($car_modelo)
370
    {
371 1
        $this->car_modelo = $car_modelo;
372 1
        return $this;
373
    }
374
375
    /**
376
     * @return mixed
377
     */
378 5
    public function getCity()
379
    {
380 5
        return $this->city;
381
    }
382
383
    /**
384
     * @param $city
385
     *
386
     * @return $this
387
     */
388 1
    public function setCity($city)
389
    {
390 1
        $this->city = $city;
391 1
        return $this;
392
    }
393
394
    /**
395
     * @return mixed
396
     */
397 5
    public function getProvince()
398
    {
399 5
        return $this->province;
400
    }
401
402
    /**
403
     * @param $province
404
     *
405
     * @return $this
406
     */
407 1
    public function setProvince($province)
408
    {
409 1
        $this->province = $province;
410 1
        return $this;
411
    }
412
413
    /**
414
     * @return mixed
415
     */
416 5
    public function getCountry()
417
    {
418 5
        return $this->country;
419
    }
420
421
    /**
422
     * @param $country
423
     *
424
     * @return $this
425
     */
426 1
    public function setCountry($country)
427
    {
428 1
        $this->country = $country;
429 1
        return $this;
430
    }
431
432
    /**
433
     * @return mixed
434
     */
435 5
    public function getVendorName()
436
    {
437 5
        return $this->vendor_name;
438
    }
439
440
    /**
441
     * @param $vendor_name
442
     *
443
     * @return $this
444
     */
445 1
    public function setVendorName($vendor_name)
446
    {
447 1
        $this->vendor_name = $vendor_name;
448 1
        return $this;
449
    }
450
451
    /**
452
     * @return mixed
453
     */
454 5
    public function getVendorEmail()
455
    {
456 5
        return $this->vendor_email;
457
    }
458
459
    /**
460
     * @param $vendor_email
461
     *
462
     * @return $this
463
     */
464 1
    public function setVendorEmail($vendor_email)
465
    {
466 1
        $this->vendor_email = $vendor_email;
467 1
        return $this;
468
    }
469
470
    /**
471
     * @return mixed
472
     */
473 5
    public function getVendorPhone()
474
    {
475 5
        return $this->vendor_phone;
476
    }
477
478
    /**
479
     * @param $vendor_phone
480
     *
481
     * @return $this
482
     */
483 1
    public function setVendorPhone($vendor_phone)
484
    {
485 1
        $this->vendor_phone = $vendor_phone;
486 1
        return $this;
487
    }
488
489
    /**
490
     * @return mixed
491
     */
492 5
    public function getProviderService()
493
    {
494 5
        return $this->provider_service;
495
    }
496
497
    /**
498
     * @param $provider_service
499
     *
500
     * @return $this
501
     */
502 1
    public function setProviderService($provider_service)
503
    {
504 1
        $this->provider_service = $provider_service;
505 1
        return $this;
506
    }
507
508
    /**
509
     * @return mixed
510
     */
511 5
    public function getProviderUrl()
512
    {
513 5
        return $this->provider_url;
514
    }
515
516
    /**
517
     * @param $provider_url
518
     *
519
     * @return $this
520
     */
521 1
    public function setProviderUrl($provider_url)
522
    {
523 1
        $this->provider_url = $provider_url;
524 1
        return $this;
525
    }
526
}
527