Completed
Pull Request — master (#134)
by
unknown
01:42
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
    /**
113
     * Create a new account.
114
     *
115
     * @return \stdClass
116
     */
117
118
    /**
119
     * @return stdClass
120
     */
121
    public function create()
122
    {
123
        return $this->createResource(sprintf('/%s/%s/', MoipResource::VERSION, self::PATH));
124
    }
125
126
    /**
127
     * Find a account.
128
     *
129
     * @param string $moip_id
130
     *
131
     * @return stdClass
132
     */
133
    public function get($moip_id)
134
    {
135
        return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $moip_id));
136
    }
137
138
    /**
139
     * Get account id.
140
     *
141
     * @return string The buyer id.
142
     */
143
    public function getId()
144
    {
145
        return $this->getIfSet('id');
146
    }
147
148
    /**
149
     * Get account address.
150
     *
151
     * @return \stdClass Account's address.
152
     */
153
    public function getAddress()
154
    {
155
        return $this->getIfSet('address', $this->data->person);
156
    }
157
158
    /**
159
     * Get account fullname.
160
     *
161
     * @return string Account's full name.
162
     */
163
    public function getFullname()
164
    {
165
        return $this->getIfSet('name', $this->data->person).' '.$this->getIfSet('lastName', $this->data->person);
166
    }
167
168
    /**
169
     * Get birth date from account.
170
     *
171
     * @return \DateTime|null Date of birth of the credit card holder.
172
     */
173
    public function getBirthDate()
174
    {
175
        return $this->getIfSetDate('birthDate', $this->data->person);
176
    }
177
178
    /**
179
     * Get phone area code from account.
180
     *
181
     * @return int DDD telephone.
182
     */
183
    public function getPhoneAreaCode()
184
    {
185
        return $this->getIfSet('areaCode', $this->data->person->phone);
186
    }
187
188
    /**
189
     * Get phone country code from account.
190
     *
191
     * @return int Country code.
192
     */
193
    public function getPhoneCountryCode()
194
    {
195
        return $this->getIfSet('countryCode', $this->data->person->phone);
196
    }
197
198
    /**
199
     * Get phone number from account.
200
     *
201
     * @return int Telephone number.
202
     */
203
    public function getPhoneNumber()
204
    {
205
        return $this->getIfSet('number', $this->data->person->phone);
206
    }
207
208
    /**
209
     * Get tax document type from account.
210
     *
211
     * @return string Type of value: CPF and CNPJ
212
     */
213
    public function getTaxDocumentType()
214
    {
215
        return $this->getIfSet('type', $this->data->person->taxDocument);
216
    }
217
    
218
    /**
219
     * Get alternative phones
220
     *
221
     * @return array
222
     */
223
    public function getAlternativePhones()
224
    {
225
        return $this->getIfSet('alternativePhones', $this->data->person);
226
    }
227
    
228
    /**
229
     * Get data company
230
     *
231
     * @return array
232
     */
233
    public function getCompany()
234
    {
235
        return $this->getIfSet('company', $this->data);
236
    }
237
238
    /**
239
     * Get tax document number from account.
240
     *
241
     * @return string Document Number.
242
     */
243
    public function getTaxDocumentNumber()
244
    {
245
        return $this->getIfSet('number', $this->data->person->taxDocument);
246
    }
247
248
    /**
249
     * Get account type.
250
     *
251
     * @return string Document Number.
252
     */
253
    public function getType()
254
    {
255
        return $this->getIfSet('type', $this->data);
256
    }
257
258
    /**
259
     * Mount the seller structure from account.
260
     *
261
     * @param \stdClass $response
262
     *
263
     * @return \Moip\Resource\Account Account data
264
     */
265
    protected function populate(stdClass $response)
266
    {
267
        $account = clone $this;
268
        $account->data->email = new stdClass();
269
270
        $email = $this->getIfSet('email', $response);
271
272
        $account->data->email->address = $this->getIfSet('address', $email);
273
        $account->data->person = new stdClass();
274
275
        $person = $this->getIfSet('person', $response);
276
277
        $account->data->person->name = $this->getIfSet('name', $person);
278
        $account->data->person->lastName = $this->getIfSet('lastName', $person);
279
        $account->data->person->taxDocument = new stdClass();
280
281
        $taxDocument = $this->getIfSet('taxDocument', $person);
282
283
        $account->data->person->taxDocument->type = $this->getIfSet('type', $taxDocument);
284
        $account->data->person->taxDocument->number = $this->getIfSet('number', $taxDocument);
285
        $account->data->person->phone = new stdClass();
286
287
        $phone = $this->getIfSet('phone', $person);
288
289
        $account->data->person->phone->countryCode = $this->getIfSet('countryCode', $phone);
290
        $account->data->person->phone->areaCode = $this->getIfSet('areaCode', $phone);
291
        $account->data->person->phone->number = $this->getIfSet('number', $phone);
292
        $account->data->person->identityDocument = new stdClass();
293
294
        $identityDocument = $this->getIfSet('identityDocument', $person);
295
296
        $account->data->person->identityDocument->type = $this->getIfSet('type', $identityDocument);
297
        $account->data->person->identityDocument->number = $this->getIfSet('number', $identityDocument);
298
        $account->data->person->identityDocument->issuer = $this->getIfSet('issuer', $identityDocument);
299
        $account->data->person->identityDocument->issueDate = $this->getIfSet('issueDate', $identityDocument);
300
301
        $account->data->person->birthDate = $this->getIfSet('birthDate', $person);
302
        $account->data->person->address = $this->getIfSet('address', $person);
303
        
304
        $account->data->person->alternativePhones = $this->getIfSet('alternativePhones', $person);
305
        
306
        $account->data->company = $this->getIfSet('company', $response);
307
        $account->data->_links = $this->getIfSet('_links', $response);
308
        $account->data->type = $this->getIfSet('type', $response);
309
        $account->data->id = $this->getIfSet('id', $response);
310
311
        return $account;
312
    }
313
314
    /**
315
     * Set e-mail from account.
316
     *
317
     * @param string $email Email account.
318
     *
319
     * @return \Moip\Resource\Account
320
     */
321
    public function setEmail($email)
322
    {
323
        $this->data->email->address = $email;
324
325
        return $this;
326
    }
327
328
    /**
329
     * Set name from account.
330
     *
331
     * @param string $name Account's person name.
332
     *
333
     * @return \Moip\Resource\Account
334
     */
335
    public function setName($name)
336
    {
337
        $this->data->person->name = $name;
338
339
        return $this;
340
    }
341
342
    /**
343
     * Set name from account.
344
     *
345
     * @param string $name Account's person name.
0 ignored issues
show
Bug introduced by
There is no parameter named $name. 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...
346
     *
347
     * @return \Moip\Resource\Account
348
     */
349
    public function setLastName($lastname)
350
    {
351
        $this->data->person->lastName = $lastname;
352
353
        return $this;
354
    }
355
356
    /**
357
     * Set birth date from account.
358
     *
359
     * @param \DateTime|string $birthDate Date of birth of the credit card holder.
360
     *
361
     * @return \Moip\Resource\Account
362
     */
363 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...
364
    {
365
        if ($birthDate instanceof \DateTime) {
366
            $birthDate = $birthDate->format('Y-m-d');
367
        }
368
369
        $this->data->person->birthDate = $birthDate;
370
371
        return $this;
372
    }
373
374
    /**
375
     * Set tax document from account.
376
     *
377
     * @param string $number Document number.
378
     * @param string $type   Document type.
379
     *
380
     * @return \Moip\Resource\Account
381
     */
382 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...
383
    {
384
        $this->data->person->taxDocument = new stdClass();
385
        $this->data->person->taxDocument->type = $type;
386
        $this->data->person->taxDocument->number = $number;
387
388
        return $this;
389
    }
390
391
    /**
392
     * Set phone from account.
393
     *
394
     * @param int $areaCode    DDD telephone.
395
     * @param int $number      Telephone number.
396
     * @param int $countryCode Country code.
397
     *
398
     * @return \Moip\Resource\Account
399
     */
400 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...
401
    {
402
        $this->data->person->phone = new stdClass();
403
        $this->data->person->phone->countryCode = $countryCode;
404
        $this->data->person->phone->areaCode = $areaCode;
405
        $this->data->person->phone->number = $number;
406
407
        return $this;
408
    }
409
410
    /**
411
     * Set identity document from account.
412
     *
413
     * @param string $number Número do documento.
414
     * @param string $issuer Emissor do documento.
415
     * @param $issueDate
416
     * @param string $type Tipo do documento. Valores possíveis: RG.
417
     *
418
     * @return Account
419
     */
420
    public function setIdentityDocument($number, $issuer, $issueDate, $type = 'RG')
421
    {
422
        $this->data->person->identityDocument = new stdClass();
423
        $this->data->person->identityDocument->type = $type;
424
        $this->data->person->identityDocument->number = $number;
425
        $this->data->person->identityDocument->issuer = $issuer;
426
        $this->data->person->identityDocument->issueDate = $issueDate;
427
428
        return $this;
429
    }
430
    
431
    /**
432
     * Set person nationality.
433
     *
434
     * @param string $nationality Abbreviation for nationality (3 max length).
435
     *
436
     * @return $this
437
     */
438
    public function setNationality($nationality = self::ADDRESS_COUNTRY)
439
    {
440
        $this->data->person->nationality = $nationality;
441
442
        return $this;
443
    }
444
    
445
    /**
446
     * Set person birth place.
447
     *
448
     * @param string $birthPlace Birth place (city).
449
     *
450
     * @return $this
451
     */
452
    public function setBirthPlace($birthPlace)
453
    {
454
        $this->data->person->birthPlace = $birthPlace;
455
456
        return $this;
457
    }
458
    
459
    /**
460
     * Set parents name.
461
     *
462
     * @param string $motherName Mother name.
463
     * @param string $fatherName Father name.
464
     *
465
     * @return $this
466
     */
467
    public function setParentsName($motherName, $fatherName)
468
    {
469
        $this->data->person->parentsName = new stdClass();
470
        $this->data->person->parentsName->mother = $motherName;
471
        $this->data->person->parentsName->father = $fatherName;
472
473
        return $this;
474
    }
475
    
476
    /**
477
     * Set site.
478
     *
479
     * @param string $site URL from site.
480
     *
481
     * @return $this
482
     */
483
    public function setSite($site)
484
    {
485
        $this->data->site = $site;
486
487
        return $this;
488
    }
489
    
490
    /**
491
     * Set transparent account.
492
     *
493
     * @param bool $transparentAccount Set true if you want create a transparent account.
494
     *
495
     * @return $this
496
     */
497
    public function setTransparentAccount($transparentAccount)
498
    {
499
        $this->data->transparentAccount = $transparentAccount;
500
501
        return $this;
502
    }
503
    
504
    /**
505
     * Set business segment.
506
     *
507
     * @param int $segmentId business segment id. Possible values available at: https://documentao-moip.readme.io/v2.0/reference#tabela-de-categorias-de-estabelecimento 
508
     *
509
     * @return $this
510
     */
511
    public function setBusinessSegment($segmentId)
512
    {
513
        $this->data->businessSegment->id = $segmentId;
514
515
        return $this;
516
    }
517
    
518
    /**
519
     * Set company name.
520
     *
521
     * @param string $name Trading Name.
522
     * @param string $businessName Company Name.
523
     *
524
     * @return $this
525
     */
526
    public function setCompanyName($name, $businessName)
527
    {
528
        $this->data->company->name = $name;
529
        $this->data->company->businessName = $businessName;        
530
531
        return $this;
532
    }
533
    
534
    /**
535
     * Set company opening date.
536
     *
537
     * @param \DateTime|string $openingDate .
538
     *
539
     * @return $this
540
     */
541
    public function setCompanyOpeningDate($openingDate)
542
    {
543
        if ($openingDate instanceof \DateTime) {
544
            $openingDate = $openingDate->format('Y-m-d');
545
        }
546
        $this->data->company->openingDate = $openingDate;
547
548
        return $this;
549
    }
550
    
551
    /**
552
     * Set company tax document.
553
     *
554
     * @param string $documentNumber .
555
     *
556
     * @return $this
557
     */
558 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...
559
    {
560
        $this->data->company->taxDocument = new stdClass();
561
        $this->data->company->taxDocument->type = self::COMPANY_TAX_DOCUMENT;
562
        $this->data->company->taxDocument->number = $documentNumber;
563
564
        return $this;
565
    }
566
    
567
    /**
568
     * Set company tax document.
569
     *
570
     * @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...
571
     *
572
     * @return $this
573
     */
574
    public function setCompanyMainActivity($cnae, $description)
575
    {
576
        $this->data->company->mainActivity = new stdClass();
577
        $this->data->company->mainActivity->cnae = $cnae;
578
        $this->data->company->mainActivity->description = $description;
579
580
        return $this;
581
    }
582
    
583
    /**
584
     * Set address to company.
585
     *
586
     * @param string $street     Street address.
587
     * @param string $number     Number address.
588
     * @param string $district   Neighborhood address.
589
     * @param string $city       City address.
590
     * @param string $state      State address.
591
     * @param string $zip        The zip code billing address.
592
     * @param string $complement Address complement.
593
     * @param string $country    Country ISO-alpha3 format, BRA example.
594
     *
595
     * @return $this
596
     */
597 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...
598
    {
599
        $address = new stdClass();
600
        $address->street = $street;
601
        $address->streetNumber = $number;
602
        $address->complement = $complement;
603
        $address->district = $district;
604
        $address->city = $city;
605
        $address->state = $state;
606
        $address->country = $country;
607
        $address->zipCode = $zip;
608
609
        $this->data->company->address = $address;
610
611
        return $this;
612
    }
613
    
614
    /**
615
     * Set company phone.
616
     *
617
     * @param int $areaCode    DDD telephone.
618
     * @param int $number      Telephone number.
619
     * @param int $countryCode Country code.
620
     *
621
     * @return \Moip\Resource\Account
622
     */
623
    public function setCompanyPhone($areaCode, $number, $countryCode = 55) 
624
    {
625
        $this->data->company->phone = new stdClass();
626
        $this->data->company->phone->countryCode = $countryCode;
627
        $this->data->company->phone->areaCode = $areaCode;
628
        $this->data->company->phone->number = $number;
629
630
        return $this;
631
    }
632
633
    /**
634
     * Set account type. Possible values: CONSUMER, MERCHANT.
635
     *
636
     * @param string $type
637
     *
638
     * @return \Moip\Resource\Account
639
     */
640
    public function setType($type)
641
    {
642
        $this->data->type = $type;
643
644
        return $this;
645
    }
646
}
647