Holder::populate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 15
nc 1
nop 1
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use stdClass;
6
7
/**
8
 * Class Holder.
9
 */
10
class Holder extends MoipResource
11
{
12
    /**
13
     * Address Type.
14
     *
15
     * @const string
16
     */
17
    const ADDRESS_BILLING = 'BILLING';
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
     * Initialize a new instance.
35
     */
36
    public function initialize()
37
    {
38
        $this->data = new stdClass();
39
    }
40
41
    /**
42
     * Add a new address to the holder.
43
     *
44
     * @param string $type       Address type: BILLING.
45
     * @param string $street     Street address.
46
     * @param string $number     Number address.
47
     * @param string $district   Neighborhood address.
48
     * @param string $city       City address.
49
     * @param string $state      State address.
50
     * @param string $zip        The zip code billing address.
51
     * @param string $complement Address complement.
52
     * @param string $country    Country ISO-alpha3 format, BRA example.
53
     *
54
     * @return $this
55
     */
56 View Code Duplication
    public function setAddress($type, $street, $number, $district, $city, $state, $zip, $complement = null, $country = self::ADDRESS_COUNTRY)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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...
57
    {
58
        $address = new stdClass();
59
        $address->street = $street;
60
        $address->streetNumber = $number;
61
        $address->complement = $complement;
62
        $address->district = $district;
63
        $address->city = $city;
64
        $address->state = $state;
65
        $address->country = $country;
66
        $address->zipCode = $zip;
67
68
        $this->data->billingAddress = $address;
69
70
        return $this;
71
    }
72
73
    /**
74
     * Get holder address.
75
     *
76
     * @return \stdClass Holder's address.
77
     */
78
    public function getBillingAddress()
79
    {
80
        return $this->getIfSet('billingAddress');
81
    }
82
83
    /**
84
     * Get holser fullname.
85
     *
86
     * @return string Holder's full name.
87
     */
88
    public function getFullname()
89
    {
90
        return $this->getIfSet('fullname');
91
    }
92
93
    /**
94
     * Get birth date from holder.
95
     *
96
     * @return \DateTime|null Date of birth of the credit card holder.
97
     */
98
    public function getBirthDate()
99
    {
100
        return $this->getIfSetDate('birthDate');
101
    }
102
103
    /**
104
     * Get phone area code from holder.
105
     *
106
     * @return int DDD telephone.
107
     */
108
    public function getPhoneAreaCode()
109
    {
110
        return $this->getIfSet('areaCode', $this->data->phone);
111
    }
112
113
    /**
114
     * Get phone country code from holder.
115
     *
116
     * @return int Country code.
117
     */
118
    public function getPhoneCountryCode()
119
    {
120
        return $this->getIfSet('countryCode', $this->data->phone);
121
    }
122
123
    /**
124
     * Get phone number from holder.
125
     *
126
     * @return int Telephone number.
127
     */
128
    public function getPhoneNumber()
129
    {
130
        return $this->getIfSet('number', $this->data->phone);
131
    }
132
133
    /**
134
     * Get tax document type from holder.
135
     *
136
     * @return string Type of value: CPF and CNPJ
137
     */
138
    public function getTaxDocumentType()
139
    {
140
        return $this->getIfSet('type', $this->data->taxDocument);
141
    }
142
143
    /**
144
     * Get tax document number from holder.
145
     *
146
     * @return string Document Number.
147
     */
148
    public function getTaxDocumentNumber()
149
    {
150
        return $this->getIfSet('number', $this->data->taxDocument);
151
    }
152
153
    /**
154
     * Mount the buyer structure from holder.
155
     *
156
     * @param \stdClass $response
157
     *
158
     * @return Holder information.
159
     */
160
    protected function populate(stdClass $response)
161
    {
162
        $holder = clone $this;
163
        $holder->data = new stdClass();
164
        $holder->data->fullname = $this->getIfSet('fullname', $response);
165
        $holder->data->phone = new stdClass();
166
167
        $phone = $this->getIfSet('phone', $response);
168
169
        $holder->data->phone->countryCode = $this->getIfSet('countryCode', $phone);
170
        $holder->data->phone->areaCode = $this->getIfSet('areaCode', $phone);
171
        $holder->data->phone->number = $this->getIfSet('number', $phone);
172
        $holder->data->birthDate = $this->getIfSet('birthDate', $response);
173
        $holder->data->taxDocument = new stdClass();
174
        $holder->data->taxDocument->type = $this->getIfSet('type', $this->getIfSet('taxDocument', $response));
175
        $holder->data->taxDocument->number = $this->getIfSet('number', $this->getIfSet('taxDocument', $response));
176
        $holder->data->billingAddress = $this->getIfSet('billingAddress', $response);
177
178
        return $holder;
179
    }
180
181
    /**
182
     * Set fullname from holder.
183
     *
184
     * @param string $fullname Holder's full name.
185
     *
186
     * @return $this
187
     */
188
    public function setFullname($fullname)
189
    {
190
        $this->data->fullname = $fullname;
191
192
        return $this;
193
    }
194
195
    /**
196
     * Set birth date from holder.
197
     *
198
     * @param \DateTime|string $birthDate Date of birth of the credit card holder.
199
     *
200
     * @return $this
201
     */
202 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...
203
    {
204
        if ($birthDate instanceof \DateTime) {
205
            $birthDate = $birthDate->format('Y-m-d');
206
        }
207
208
        $this->data->birthDate = $birthDate;
209
210
        return $this;
211
    }
212
213
    /**
214
     * Set tax document from holder.
215
     *
216
     * @param string $number Document number.
217
     * @param string $type   Document type.
218
     *
219
     * @return $this
220
     */
221
    public function setTaxDocument($number, $type = self::TAX_DOCUMENT)
222
    {
223
        $this->data->taxDocument = new stdClass();
224
        $this->data->taxDocument->type = $type;
225
        $this->data->taxDocument->number = $number;
226
227
        return $this;
228
    }
229
230
    /**
231
     * Set phone from holder.
232
     *
233
     * @param int $areaCode    DDD telephone.
234
     * @param int $number      Telephone number.
235
     * @param int $countryCode Country code.
236
     *
237
     * @return $this
238
     */
239 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...
240
    {
241
        $this->data->phone = new stdClass();
242
        $this->data->phone->countryCode = $countryCode;
243
        $this->data->phone->areaCode = $areaCode;
244
        $this->data->phone->number = $number;
245
246
        return $this;
247
    }
248
}
249