Completed
Pull Request — master (#247)
by
unknown
14:42
created

Holder::getBirthDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
rs 10
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->addresses = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
177
        $holder->data->billingAddress = $this->getIfSet('billingAddress', $response);
178
179
        return $holder;
180
    }
181
182
    /**
183
     * Set fullname from holder.
184
     *
185
     * @param string $fullname Holder's full name.
186
     *
187
     * @return $this
188
     */
189
    public function setFullname($fullname)
190
    {
191
        $this->data->fullname = $fullname;
192
193
        return $this;
194
    }
195
196
    /**
197
     * Set birth date from holder.
198
     *
199
     * @param \DateTime|string $birthDate Date of birth of the credit card holder.
200
     *
201
     * @return $this
202
     */
203
    public function setBirthDate($birthDate)
204
    {
205
        if ($birthDate instanceof \DateTime) {
206
            $birthDate = $birthDate->format('Y-m-d');
207
        }
208
209
        $this->data->birthDate = $birthDate;
210
211
        return $this;
212
    }
213
214
    /**
215
     * Set tax document from holder.
216
     *
217
     * @param string $number Document number.
218
     * @param string $type   Document type.
219
     *
220
     * @return $this
221
     */
222 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...
223
    {
224
        $this->data->taxDocument = new stdClass();
225
        $this->data->taxDocument->type = $type;
226
        $this->data->taxDocument->number = $number;
227
228
        return $this;
229
    }
230
231
    /**
232
     * Set phone from holder.
233
     *
234
     * @param int $areaCode    DDD telephone.
235
     * @param int $number      Telephone number.
236
     * @param int $countryCode Country code.
237
     *
238
     * @return $this
239
     */
240 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...
241
    {
242
        $this->data->phone = new stdClass();
243
        $this->data->phone->countryCode = $countryCode;
244
        $this->data->phone->areaCode = $areaCode;
245
        $this->data->phone->number = $number;
246
247
        return $this;
248
    }
249
}
250