Completed
Push — master ( 64fdd0...0e1ec5 )
by Jean C.
02:58 queued 21s
created

Account::setCompanyAddress()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
c 0
b 0
f 0
nc 1
nop 8
dl 16
loc 16
rs 9.4285

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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