Completed
Pull Request — master (#134)
by
unknown
01:47
created

Account::setParentsName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
7
/**
8
 * Class Account.
9
 */
10
class Account extends MoipResource
11
{
12
    /**
13
     * Path accounts API.
14
     *
15
     * @const string
16
     */
17
    const PATH = 'accounts';
18
19
    /**
20
     * Standard country .
21
     *
22
     * @const string
23
     */
24
    const ADDRESS_COUNTRY = 'BRA';
25
26
    /**
27
     * Standard document type.
28
     *
29
     * @const string
30
     */
31
    const TAX_DOCUMENT = 'CPF';
32
33
    /**
34
     * Standard company document type.
35
     *
36
     * @const string
37
     */
38
    const COMPANY_TAX_DOCUMENT = 'CNPJ';
39
40
    /**
41
     * Default Account Type.
42
     *
43
     * @var string
44
     */
45
    const ACCOUNT_TYPE = 'MERCHANT';
46
47
    /**
48
     * Initialize a new instance.
49
     */
50
    public function initialize()
51
    {
52
        $this->data = new stdClass();
53
        $this->data->email = new stdClass();
54
        $this->data->person = new stdClass();
55
        $this->data->person->alternativePhones = [];
56
        $this->data->company = new stdClass();
57
        $this->data->type = self::ACCOUNT_TYPE;
58
    }
59
60
    /**
61
     * Add a new address to the account.
62
     *
63
     * @param string $street     Street address.
64
     * @param string $number     Number address.
65
     * @param string $district   Neighborhood address.
66
     * @param string $city       City address.
67
     * @param string $state      State address.
68
     * @param string $zip        The zip code billing address.
69
     * @param string $complement Address complement.
70
     * @param string $country    Country ISO-alpha3 format, BRA example.
71
     *
72
     * @return $this
73
     */
74 View Code Duplication
    public function addAddress($street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        $address = new stdClass();
77
        $address->street = $street;
78
        $address->streetNumber = $number;
79
        $address->complement = $complement;
80
        $address->district = $district;
81
        $address->city = $city;
82
        $address->state = $state;
83
        $address->country = $country;
84
        $address->zipCode = $zip;
85
86
        $this->data->person->address = $address;
87
88
        return $this;
89
    }
90
91
    /**
92
     * Add alternative phone to an account.
93
     *
94
     * @param int $areaCode    DDD telephone.
95
     * @param int $number      Telephone number.
96
     * @param int $countryCode Country code.
97
     *
98
     * @return \Moip\Resource\Account
99
     */
100
    public function addAlternativePhone($areaCode, $number, $countryCode = 55)
101
    {
102
        $alternativePhone = new stdClass();
103
        $alternativePhone->countryCode = $countryCode;
104
        $alternativePhone->areaCode = $areaCode;
105
        $alternativePhone->number = $number;
106
107
        $this->data->person->alternativePhones[] = $alternativePhone;
108
109
        return $this;
110
    }
111
    /**
112
     * Create a new account.
113
     *
114
     * @return \stdClass
115
     */
116
117
    /**
118
     * @return stdClass
119
     */
120
    public function create()
121
    {
122
        return $this->createResource(sprintf('/%s/%s/', MoipResource::VERSION, self::PATH));
123
    }
124
125
    /**
126
     * Find a account.
127
     *
128
     * @param string $moip_id
129
     *
130
     * @return stdClass
131
     */
132
    public function get($moip_id)
133
    {
134
        return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $moip_id));
135
    }
136
137
    /**
138
     * Get account id.
139
     *
140
     * @return string The buyer id.
141
     */
142
    public function getId()
143
    {
144
        return $this->getIfSet('id');
145
    }
146
147
    /**
148
     * Get account address.
149
     *
150
     * @return \stdClass Account's address.
151
     */
152
    public function getAddress()
153
    {
154
        return $this->getIfSet('address', $this->data->person);
155
    }
156
157
    /**
158
     * Get account fullname.
159
     *
160
     * @return string Account's full name.
161
     */
162
    public function getFullname()
163
    {
164
        return $this->getIfSet('name', $this->data->person).' '.$this->getIfSet('lastName', $this->data->person);
165
    }
166
167
    /**
168
     * Get birth date from account.
169
     *
170
     * @return \DateTime|null Date of birth of the credit card holder.
171
     */
172
    public function getBirthDate()
173
    {
174
        return $this->getIfSetDate('birthDate', $this->data->person);
175
    }
176
177
    /**
178
     * Get phone area code from account.
179
     *
180
     * @return int DDD telephone.
181
     */
182
    public function getPhoneAreaCode()
183
    {
184
        return $this->getIfSet('areaCode', $this->data->person->phone);
185
    }
186
187
    /**
188
     * Get phone country code from account.
189
     *
190
     * @return int Country code.
191
     */
192
    public function getPhoneCountryCode()
193
    {
194
        return $this->getIfSet('countryCode', $this->data->person->phone);
195
    }
196
197
    /**
198
     * Get phone number from account.
199
     *
200
     * @return int Telephone number.
201
     */
202
    public function getPhoneNumber()
203
    {
204
        return $this->getIfSet('number', $this->data->person->phone);
205
    }
206
207
    /**
208
     * Get tax document type from account.
209
     *
210
     * @return string Type of value: CPF and CNPJ
211
     */
212
    public function getTaxDocumentType()
213
    {
214
        return $this->getIfSet('type', $this->data->person->taxDocument);
215
    }
216
217
    /**
218
     * Get alternative phones.
219
     *
220
     * @return array
221
     */
222
    public function getAlternativePhones()
223
    {
224
        return $this->getIfSet('alternativePhones', $this->data->person);
225
    }
226
227
    /**
228
     * Get company data.
229
     *
230
     * @return array
231
     */
232
    public function getCompany()
233
    {
234
        return $this->getIfSet('company', $this->data);
235
    }
236
237
    /**
238
     * Get tax document number from account.
239
     *
240
     * @return string Document Number.
241
     */
242
    public function getTaxDocumentNumber()
243
    {
244
        return $this->getIfSet('number', $this->data->person->taxDocument);
245
    }
246
247
    /**
248
     * Get account type.
249
     *
250
     * @return string Document Number.
251
     */
252
    public function getType()
253
    {
254
        return $this->getIfSet('type', $this->data);
255
    }
256
257
    /**
258
     * Mount the seller structure from account.
259
     *
260
     * @param \stdClass $response
261
     *
262
     * @return \Moip\Resource\Account Account data
263
     */
264
    protected function populate(stdClass $response)
265
    {
266
        $account = clone $this;
267
        $account->data->email = new stdClass();
268
269
        $email = $this->getIfSet('email', $response);
270
271
        $account->data->email->address = $this->getIfSet('address', $email);
272
        $account->data->person = new stdClass();
273
274
        $person = $this->getIfSet('person', $response);
275
276
        $account->data->person->name = $this->getIfSet('name', $person);
277
        $account->data->person->lastName = $this->getIfSet('lastName', $person);
278
        $account->data->person->taxDocument = new stdClass();
279
280
        $taxDocument = $this->getIfSet('taxDocument', $person);
281
282
        $account->data->person->taxDocument->type = $this->getIfSet('type', $taxDocument);
283
        $account->data->person->taxDocument->number = $this->getIfSet('number', $taxDocument);
284
        $account->data->person->phone = new stdClass();
285
286
        $phone = $this->getIfSet('phone', $person);
287
288
        $account->data->person->phone->countryCode = $this->getIfSet('countryCode', $phone);
289
        $account->data->person->phone->areaCode = $this->getIfSet('areaCode', $phone);
290
        $account->data->person->phone->number = $this->getIfSet('number', $phone);
291
        $account->data->person->identityDocument = new stdClass();
292
293
        $identityDocument = $this->getIfSet('identityDocument', $person);
294
295
        $account->data->person->identityDocument->type = $this->getIfSet('type', $identityDocument);
296
        $account->data->person->identityDocument->number = $this->getIfSet('number', $identityDocument);
297
        $account->data->person->identityDocument->issuer = $this->getIfSet('issuer', $identityDocument);
298
        $account->data->person->identityDocument->issueDate = $this->getIfSet('issueDate', $identityDocument);
299
300
        $account->data->person->birthDate = $this->getIfSet('birthDate', $person);
301
        $account->data->person->address = $this->getIfSet('address', $person);
302
303
        $account->data->person->alternativePhones = $this->getIfSet('alternativePhones', $person);
304
305
        $account->data->company = $this->getIfSet('company', $response);
306
        $account->data->_links = $this->getIfSet('_links', $response);
307
        $account->data->type = $this->getIfSet('type', $response);
308
        $account->data->id = $this->getIfSet('id', $response);
309
310
        return $account;
311
    }
312
313
    /**
314
     * Set e-mail from account.
315
     *
316
     * @param string $email Email account.
317
     *
318
     * @return \Moip\Resource\Account
319
     */
320
    public function setEmail($email)
321
    {
322
        $this->data->email->address = $email;
323
324
        return $this;
325
    }
326
327
    /**
328
     * Set name from account.
329
     *
330
     * @param string $name Account's person name.
331
     *
332
     * @return \Moip\Resource\Account
333
     */
334
    public function setName($name)
335
    {
336
        $this->data->person->name = $name;
337
338
        return $this;
339
    }
340
341
    /**
342
     * Set name from account.
343
     *
344
     * @param string $lastname Account's person name.
345
     *
346
     * @return \Moip\Resource\Account
347
     */
348
    public function setLastName($lastname)
349
    {
350
        $this->data->person->lastName = $lastname;
351
352
        return $this;
353
    }
354
355
    /**
356
     * Set birth date from account.
357
     *
358
     * @param \DateTime|string $birthDate Date of birth of the credit card holder.
359
     *
360
     * @return \Moip\Resource\Account
361
     */
362 View Code Duplication
    public function setBirthDate($birthDate)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
363
    {
364
        if ($birthDate instanceof \DateTime) {
365
            $birthDate = $birthDate->format('Y-m-d');
366
        }
367
368
        $this->data->person->birthDate = $birthDate;
369
370
        return $this;
371
    }
372
373
    /**
374
     * Set tax document from account.
375
     *
376
     * @param string $number Document number.
377
     * @param string $type   Document type.
378
     *
379
     * @return \Moip\Resource\Account
380
     */
381 View Code Duplication
    public function setTaxDocument($number, $type = self::TAX_DOCUMENT)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
382
    {
383
        $this->data->person->taxDocument = new stdClass();
384
        $this->data->person->taxDocument->type = $type;
385
        $this->data->person->taxDocument->number = $number;
386
387
        return $this;
388
    }
389
390
    /**
391
     * Set phone from account.
392
     *
393
     * @param int $areaCode    DDD telephone.
394
     * @param int $number      Telephone number.
395
     * @param int $countryCode Country code.
396
     *
397
     * @return \Moip\Resource\Account
398
     */
399 View Code Duplication
    public function setPhone($areaCode, $number, $countryCode = 55)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
400
    {
401
        $this->data->person->phone = new stdClass();
402
        $this->data->person->phone->countryCode = $countryCode;
403
        $this->data->person->phone->areaCode = $areaCode;
404
        $this->data->person->phone->number = $number;
405
406
        return $this;
407
    }
408
409
    /**
410
     * Set identity document from account.
411
     *
412
     * @param string $number Número do documento.
413
     * @param string $issuer Emissor do documento.
414
     * @param $issueDate
415
     * @param string $type Tipo do documento. Valores possíveis: RG.
416
     *
417
     * @return Account
418
     */
419
    public function setIdentityDocument($number, $issuer, $issueDate, $type = 'RG')
420
    {
421
        $this->data->person->identityDocument = new stdClass();
422
        $this->data->person->identityDocument->type = $type;
423
        $this->data->person->identityDocument->number = $number;
424
        $this->data->person->identityDocument->issuer = $issuer;
425
        $this->data->person->identityDocument->issueDate = $issueDate;
426
427
        return $this;
428
    }
429
430
    /**
431
     * Set person nationality.
432
     *
433
     * @param string $nationality Abbreviation for nationality (3 max length).
434
     *
435
     * @return $this
436
     */
437
    public function setNationality($nationality = self::ADDRESS_COUNTRY)
438
    {
439
        $this->data->person->nationality = $nationality;
440
441
        return $this;
442
    }
443
444
    /**
445
     * Set person birth place.
446
     *
447
     * @param string $birthPlace Birth place (city).
448
     *
449
     * @return $this
450
     */
451
    public function setBirthPlace($birthPlace)
452
    {
453
        $this->data->person->birthPlace = $birthPlace;
454
455
        return $this;
456
    }
457
458
    /**
459
     * Set parents name.
460
     *
461
     * @param string $motherName Mother name.
462
     * @param string $fatherName Father name.
463
     *
464
     * @return $this
465
     */
466
    public function setParentsName($motherName, $fatherName)
467
    {
468
        $this->data->person->parentsName = new stdClass();
469
        $this->data->person->parentsName->mother = $motherName;
470
        $this->data->person->parentsName->father = $fatherName;
471
472
        return $this;
473
    }
474
475
    /**
476
     * Set site.
477
     *
478
     * @param string $site URL from site.
479
     *
480
     * @return $this
481
     */
482
    public function setSite($site)
483
    {
484
        $this->data->site = $site;
485
486
        return $this;
487
    }
488
489
    /**
490
     * Set transparent account.
491
     *
492
     * @param bool $transparentAccount Set true if you want create a transparent account.
493
     *
494
     * @return $this
495
     */
496
    public function setTransparentAccount($transparentAccount)
497
    {
498
        $this->data->transparentAccount = $transparentAccount;
499
500
        return $this;
501
    }
502
503
    /**
504
     * Set business segment.
505
     *
506
     * @param int $segmentId business segment id. Possible values available at: https://documentao-moip.readme.io/v2.0/reference#tabela-de-categorias-de-estabelecimento 
507
     *
508
     * @return $this
509
     */
510
    public function setBusinessSegment($segmentId)
511
    {
512
        $this->data->businessSegment->id = $segmentId;
513
514
        return $this;
515
    }
516
517
    /**
518
     * Set company name.
519
     *
520
     * @param string $name         Trading Name.
521
     * @param string $businessName Company Name.
522
     *
523
     * @return $this
524
     */
525
    public function setCompanyName($name, $businessName)
526
    {
527
        $this->data->company->name = $name;
528
        $this->data->company->businessName = $businessName;
529
530
        return $this;
531
    }
532
533
    /**
534
     * Set company opening date.
535
     *
536
     * @param \DateTime|string $openingDate .
537
     *
538
     * @return $this
539
     */
540
    public function setCompanyOpeningDate($openingDate)
541
    {
542
        if ($openingDate instanceof \DateTime) {
543
            $openingDate = $openingDate->format('Y-m-d');
544
        }
545
        $this->data->company->openingDate = $openingDate;
546
547
        return $this;
548
    }
549
550
    /**
551
     * Set company tax document.
552
     *
553
     * @param string $documentNumber .
554
     *
555
     * @return $this
556
     */
557 View Code Duplication
    public function setCompanyTaxDocument($documentNumber)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
558
    {
559
        $this->data->company->taxDocument = new stdClass();
560
        $this->data->company->taxDocument->type = self::COMPANY_TAX_DOCUMENT;
561
        $this->data->company->taxDocument->number = $documentNumber;
562
563
        return $this;
564
    }
565
566
    /**
567
     * Set company tax document.
568
     *
569
     * @param string $documentNumber .
0 ignored issues
show
Bug introduced by
There is no parameter named $documentNumber. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
570
     *
571
     * @return $this
572
     */
573
    public function setCompanyMainActivity($cnae, $description)
574
    {
575
        $this->data->company->mainActivity = new stdClass();
576
        $this->data->company->mainActivity->cnae = $cnae;
577
        $this->data->company->mainActivity->description = $description;
578
579
        return $this;
580
    }
581
582
    /**
583
     * Set address to company.
584
     *
585
     * @param string $street     Street address.
586
     * @param string $number     Number address.
587
     * @param string $district   Neighborhood address.
588
     * @param string $city       City address.
589
     * @param string $state      State address.
590
     * @param string $zip        The zip code billing address.
591
     * @param string $complement Address complement.
592
     * @param string $country    Country ISO-alpha3 format, BRA example.
593
     *
594
     * @return $this
595
     */
596 View Code Duplication
    public function setCompanyAddress($street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
597
    {
598
        $address = new stdClass();
599
        $address->street = $street;
600
        $address->streetNumber = $number;
601
        $address->complement = $complement;
602
        $address->district = $district;
603
        $address->city = $city;
604
        $address->state = $state;
605
        $address->country = $country;
606
        $address->zipCode = $zip;
607
608
        $this->data->company->address = $address;
609
610
        return $this;
611
    }
612
613
    /**
614
     * Set company phone.
615
     *
616
     * @param int $areaCode    DDD telephone.
617
     * @param int $number      Telephone number.
618
     * @param int $countryCode Country code.
619
     *
620
     * @return \Moip\Resource\Account
621
     */
622
    public function setCompanyPhone($areaCode, $number, $countryCode = 55)
623
    {
624
        $this->data->company->phone = new stdClass();
625
        $this->data->company->phone->countryCode = $countryCode;
626
        $this->data->company->phone->areaCode = $areaCode;
627
        $this->data->company->phone->number = $number;
628
629
        return $this;
630
    }
631
632
    /**
633
     * Set account type. Possible values: CONSUMER, MERCHANT.
634
     *
635
     * @param string $type
636
     *
637
     * @return \Moip\Resource\Account
638
     */
639
    public function setType($type)
640
    {
641
        $this->data->type = $type;
642
643
        return $this;
644
    }
645
}
646