Completed
Pull Request — master (#273)
by
unknown
09:57
created

Transfers::getAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Resource;
4
5
use Moip\Helper\Filters;
6
use Moip\Helper\Pagination;
7
use Requests;
8
use stdClass;
9
10
/**
11
 * Class Transfers.
12
 */
13
class Transfers extends MoipResource
14
{
15
    /**
16
     * @const string
17
     */
18
    const PATH = 'transfers';
19
20
    /**
21
     * @const string
22
     */
23
    const METHOD_BKA = 'BANK_ACCOUNT';
24
25
    /**
26
     * @const string
27
     */
28
    const TYPE = 'CHECKING';
29
30
    /**
31
     * Initializes new instances.
32
     */
33 View Code Duplication
    protected function initialize()
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...
34
    {
35
        $this->data = new stdClass();
36
        $this->data->transferInstrument = new stdClass();
37
        $this->data->transferInstrument->bankAccount = new stdClass();
38
        $this->data->transferInstrument->bankAccount->holder = new stdClass();
39
        $this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass();
40
    }
41
42
    /**
43
     * @param stdClass $response
44
     *
45
     * @return Transfers
46
     */
47
    protected function populate(stdClass $response)
48
    {
49
        $transfers = clone $this;
50
51
        $transfers->data->id = $this->getIfSet('id', $response);
52
        $transfers->data->ownId = $this->getIfSet('ownId', $response);
53
        $transfers->data->amount = $this->getIfSet('amount', $response);
54
55
        $transfer_instrument = $this->getIfSet('transferInstrument', $response);
56
        $transfers->data->transferInstrument = new stdClass();
57
        $transfers->data->transferInstrument->method = $this->getIfSet('method', $transfer_instrument);
58
59
        $bank_account = $this->getIfSet('bankAccount', $transfer_instrument);
60
        $transfers->data->transferInstrument->bankAccount = new stdClass();
61
        $transfers->data->transferInstrument->bankAccount->id = $this->getIfSet('id', $bank_account);
62
        $transfers->data->transferInstrument->bankAccount->type = $this->getIfSet('type', $bank_account);
63
        $transfers->data->transferInstrument->bankAccount->bankNumber = $this->getIfSet('bankNumber', $bank_account);
64
        $transfers->data->transferInstrument->bankAccount->agencyNumber = $this->getIfSet('agencyNumber', $bank_account);
65
        $transfers->data->transferInstrument->bankAccount->agencyCheckNumber = $this->getIfSet('agencyCheckNumber', $bank_account);
66
        $transfers->data->transferInstrument->bankAccount->accountNumber = $this->getIfSet('accountNumber', $bank_account);
67
        $transfers->data->transferInstrument->bankAccount->accountCheckNumber = $this->getIfSet('accountCheckNumber', $bank_account);
68
69
        $holder = $this->getIfSet('holder', $bank_account);
70
        $transfers->data->transferInstrument->bankAccount->holder = new stdClass();
71
        $transfers->data->transferInstrument->bankAccount->holder->fullname = $this->getIfSet('fullname', $holder);
72
73
        $tax_document = $this->getIfSet('taxDocument', $holder);
74
        $this->data->transferInstrument->bankAccount->holder->taxDocument = new stdClass();
75
        $this->data->transferInstrument->bankAccount->holder->taxDocument->type = $this->getIfSet('type', $tax_document);
76
        $this->data->transferInstrument->bankAccount->holder->taxDocument->number = $this->getIfSet('number', $tax_document);
77
78
        return $transfers;
79
    }
80
81
    /**
82
     * Set the amount of transfer.
83
     * 
84
     * @param int   $amount
85
     * 
86
     * @return $this
87
     */
88
    public function setAmount($amount)
89
    {
90
        $this->data->amount = $amount;
91
92
        return $this;
93
    }
94
95
    /**
96
     * Returns amount.
97
     * 
98
     * @return amount
99
     */
100
    public function getAmount()
101
    {
102
        return $this->data->amount;
103
    }
104
105
    /**
106
     * Set the bank accout transfer.
107
     *
108
     * @param string $bankNumber         Bank number. possible values: 001, 237, 341, 041.
109
     * @param int    $agencyNumber
110
     * @param int    $agencyCheckNumber
111
     * @param int    $accountNumber
112
     * @param int    $accountCheckNumber
113
     *
114
     * @return $this
115
     */
116
    public function setTransferToBankAccount(
117
        $bankNumber,
118
        $agencyNumber,
119
        $agencyCheckNumber,
120
        $accountNumber,
121
        $accountCheckNumber
122
    ) {
123
        $this->data->transferInstrument->method = self::METHOD_BKA;
124
        $this->data->transferInstrument->bankAccount->type = self::TYPE;
125
        $this->data->transferInstrument->bankAccount->bankNumber = $bankNumber;
126
        $this->data->transferInstrument->bankAccount->agencyNumber = $agencyNumber;
127
        $this->data->transferInstrument->bankAccount->agencyCheckNumber = $agencyCheckNumber;
128
        $this->data->transferInstrument->bankAccount->accountNumber = $accountNumber;
129
        $this->data->transferInstrument->bankAccount->accountCheckNumber = $accountCheckNumber;
130
131
        return $this;
132
    }
133
134
    /**
135
     * Set info of transfers to a saved bank account.
136
     *
137
     * @param int    $amount        Amount
138
     * @param string $bankAccountId Saved bank account id.
139
     *
140
     * @return $this
141
     */
142
    public function setTransferWithBankAccountId($amount, $bankAccountId)
143
    {
144
        $this->data->amount = $amount;
145
        $this->data->transferInstrument->method = self::METHOD_BKA;
146
        $this->data->transferInstrument->bankAccount->id = $bankAccountId;
147
148
        return $this;
149
    }
150
151
    /**
152
     * Returns transfer.
153
     *
154
     * @return stdClass
155
     */
156
    public function getTransfers()
157
    {
158
        return $this->data;
159
    }
160
161
    /**
162
     * Get own request id. external reference.
163
     *
164
     * @param mixed $ownId id
165
     *
166
     * @return $this
167
     */
168
    public function setOwnId($ownId)
169
    {
170
        $this->data->ownId = $ownId;
171
172
        return $this;
173
    }
174
175
    /**
176
     * Set info of holder.
177
     *
178
     * @param string $fullname
179
     * @param int    $taxDocument
0 ignored issues
show
Documentation introduced by
There is no parameter named $taxDocument. Did you maybe mean $taxDocumentNumber?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

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

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

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

Loading history...
180
     *
181
     * @return $this
182
     */
183
    public function setHolder($fullname, $taxDocumentNumber, $taxDocumentType = 'CPF')
184
    {
185
        $this->data->transferInstrument->bankAccount->holder->fullname = $fullname;
186
        $this->data->transferInstrument->bankAccount->holder->taxDocument->type = $taxDocumentType;
187
        $this->data->transferInstrument->bankAccount->holder->taxDocument->number = $taxDocumentNumber;
188
189
        return $this;
190
    }
191
192
    /**
193
     * Returns transfer holder.
194
     *
195
     * @return stdClass
196
     */
197
    public function getHolder()
198
    {
199
        return $this->data->transferInstrument->bankAccount->holder;
200
    }
201
202
    /**
203
     * Execute Tranfers.
204
     *
205
     * @return Transfers
206
     */
207 View Code Duplication
    public function execute()
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...
208
    {
209
        $path = sprintf('/%s/%s', MoipResource::VERSION, self::PATH);
210
211
        $response = $this->httpRequest($path, Requests::POST, $this);
212
213
        return $this->populate($response);
214
    }
215
216
    /**
217
     * Revert Tranfers.
218
     *
219
     * @param string $id Transfer id.
220
     *
221
     * @return Transfers
222
     */
223 View Code Duplication
    public function revert($id)
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...
224
    {
225
        $path = sprintf('/%s/%s/%s/%s', MoipResource::VERSION, self::PATH, $id, 'reverse');
226
227
        $response = $this->httpRequest($path, Requests::POST, $this);
228
229
        return $this->populate($response);
230
    }
231
232
    /**
233
     * Get a Transfer.
234
     *
235
     * @param string $id Transfer id.
236
     *
237
     * @return stdClass
238
     */
239
    public function get($id)
240
    {
241
        return $this->getByPath(sprintf('/%s/%s/%s', MoipResource::VERSION, self::PATH, $id));
242
    }
243
244
    /**
245
     * Create a new Transfers list instance.
246
     *
247
     * @return \Moip\Resource\TransfersList
248
     */
249
    public function getList(Pagination $pagination = null, Filters $filters = null, $qParam = '')
250
    {
251
        $transfersList = new TransfersList($this->moip);
252
253
        return $transfersList->get($pagination, $filters, $qParam);
254
    }
255
256
    /**
257
     * Get MoIP Transfers id.
258
     *
259
     * @return string
260
     */
261
    public function getId()
262
    {
263
        return $this->getIfSet('id');
264
    }
265
266
    /**
267
     * Get own request id. external reference.
268
     *
269
     * @return mixed
270
     */
271
    public function getOwnId()
272
    {
273
        return $this->getIfSet('ownId');
274
    }
275
}
276