Completed
Push — master ( 47ade2...461ffe )
by João Felipe Magro
04:47
created

Order   B

Complexity

Total Complexity 34

Size/Duplication

Total Lines 302
Duplicated Lines 3.31 %

Coupling/Cohesion

Components 7
Dependencies 7

Importance

Changes 0
Metric Value
wmc 34
lcom 7
cbo 7
dl 10
loc 302
rs 7.6666
c 0
b 0
f 0

24 Methods

Rating   Name   Duplication   Size   Complexity  
A getOrderId() 0 4 1
A getOperation() 0 4 1
A getCallbackUrl() 0 4 1
A getAmount() 0 4 1
A getInstallments() 0 4 1
A setOrderId() 0 6 1
A setOperation() 0 6 1
A setCallbackUrl() 0 6 1
A setAmount() 0 6 1
A setInstallments() 0 6 1
A getExpiry() 0 4 1
A setExpiry() 0 11 2
A getFingerprint() 0 4 1
A setFingerprint() 0 6 1
A checkIfInstallmentsIsValidAndReturn() 0 12 4
A isValidExpiryFormatDate() 10 10 3
A getPayment() 0 8 2
A setPayment() 0 6 1
A getCart() 0 8 2
A setCart() 0 6 1
A getCustomer() 0 8 2
A setCustomer() 0 6 1
A getSubscription() 0 8 2
A setSubscription() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Ipag\Classes;
4
5
use Ipag\Classes\Contracts\Emptiable;
6
use Ipag\Classes\Traits\EmptiableTrait;
7
8
final class Order extends BaseResource implements Emptiable
9
{
10
    use EmptiableTrait;
11
12
    /**
13
     * @var string
14
     */
15
    private $orderId;
16
17
    /**
18
     * @var string
19
     */
20
    private $operation;
21
22
    /**
23
     * @var string
24
     */
25
    private $callbackUrl;
26
27
    /**
28
     * @var float
29
     */
30
    private $amount;
31
32
    /**
33
     * @var int
34
     */
35
    private $installments;
36
37
    /**
38
     * @var string
39
     */
40
    private $expiry;
41
42
    /**
43
     * @var string
44
     */
45
    private $fingerprint;
46
47
    /**
48
     * @var Payment
49
     */
50
    private $payment;
51
52
    /**
53
     * @var Cart
54
     */
55
    private $cart;
56
57
    /**
58
     * @var Customer
59
     */
60
    private $customer;
61
62
    /**
63
     * @var Subscription
64
     */
65
    private $subscription;
66
67
    /**
68
     * @return string
69
     */
70
    public function getOrderId()
71
    {
72
        return $this->orderId;
73
    }
74
75
    /**
76
     * @return string
77
     */
78
    public function getOperation()
79
    {
80
        return $this->operation;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getCallbackUrl()
87
    {
88
        return $this->callbackUrl;
89
    }
90
91
    /**
92
     * @return float
93
     */
94
    public function getAmount()
95
    {
96
        return $this->amount;
97
    }
98
99
    /**
100
     * @return int
101
     */
102
    public function getInstallments()
103
    {
104
        return $this->installments;
105
    }
106
107
    /**
108
     * @param string $orderId
109
     */
110
    public function setOrderId($orderId)
111
    {
112
        $this->orderId = substr((string) $orderId, 0, 20);
113
114
        return $this;
115
    }
116
117
    /**
118
     * @param string $operation
119
     */
120
    public function setOperation($operation)
121
    {
122
        $this->operation = $operation;
123
124
        return $this;
125
    }
126
127
    /**
128
     * @param string $callbackUrl
129
     */
130
    public function setCallbackUrl($callbackUrl)
131
    {
132
        $this->callbackUrl = substr((string) $callbackUrl, 0, 255);
133
134
        return $this;
135
    }
136
137
    /**
138
     * @param float $amount
139
     */
140
    public function setAmount($amount)
141
    {
142
        $this->amount = $this->getNumberUtil()->convertToDouble($amount);
143
144
        return $this;
145
    }
146
147
    /**
148
     * @param int $installments
149
     */
150
    public function setInstallments($installments)
151
    {
152
        $this->installments = $this->checkIfInstallmentsIsValidAndReturn($installments);
153
154
        return $this;
155
    }
156
157
    /**
158
     * @return string
159
     */
160
    public function getExpiry()
161
    {
162
        return $this->expiry;
163
    }
164
165
    /**
166
     * @param string $expiry
167
     */
168
    public function setExpiry($expiry)
169
    {
170
        if (!$this->isValidExpiryFormatDate($expiry)) {
171
            throw new \UnexpectedValueException(
172
                'A data de vencimento não é valida ou está em formato incorreto, deve ser informada utilizando o formato dd/mm/aaaa'
173
            );
174
        }
175
        $this->expiry = $expiry;
176
177
        return $this;
178
    }
179
180
    /**
181
     * @return string
182
     */
183
    public function getFingerprint()
184
    {
185
        return $this->fingerprint;
186
    }
187
188
    /**
189
     * @param string $fingerprint
190
     */
191
    public function setFingerprint($fingerprint)
192
    {
193
        $this->fingerprint = substr((string) $fingerprint, 0, 120);
194
195
        return $this;
196
    }
197
198
    private function checkIfInstallmentsIsValidAndReturn($installments)
199
    {
200
        if (empty($installments) || $installments < 1) {
201
            $installments = 1;
202
        } elseif ($installments > 12) {
203
            throw new \UnexpectedValueException(
204
                'O parcelamento não pode ser maior que 12 (doze)'
205
            );
206
        }
207
208
        return (int) $installments;
209
    }
210
211 View Code Duplication
    private function isValidExpiryFormatDate($date)
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...
212
    {
213
        if (preg_match("/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/", $date, $matches)) {
214
            if (checkdate($matches[2], $matches[1], $matches[3])) {
215
                return true;
216
            }
217
        }
218
219
        return false;
220
    }
221
222
    /**
223
     * @return Payment
224
     */
225
    public function getPayment()
226
    {
227
        if (is_null($this->payment)) {
228
            $this->payment = new Payment();
229
        }
230
231
        return $this->payment;
232
    }
233
234
    /**
235
     * @param Payment $payment
236
     */
237
    public function setPayment(Payment $payment)
238
    {
239
        $this->payment = $payment;
240
241
        return $this;
242
    }
243
244
    /**
245
     * @return Cart
246
     */
247
    public function getCart()
248
    {
249
        if (is_null($this->cart)) {
250
            $this->cart = new Cart();
251
        }
252
253
        return $this->cart;
254
    }
255
256
    /**
257
     * @param Cart $cart
258
     */
259
    public function setCart(Cart $cart)
260
    {
261
        $this->cart = $cart;
262
263
        return $this;
264
    }
265
266
    /**
267
     * @return Customer
268
     */
269
    public function getCustomer()
270
    {
271
        if (is_null($this->customer)) {
272
            $this->customer = new Customer();
273
        }
274
275
        return $this->customer;
276
    }
277
278
    /**
279
     * @param Customer $customer
280
     */
281
    public function setCustomer(Customer $customer)
282
    {
283
        $this->customer = $customer;
284
285
        return $this;
286
    }
287
288
    /**
289
     * @return Subscription
290
     */
291
    public function getSubscription()
292
    {
293
        if (is_null($this->subscription)) {
294
            $this->subscription = new Subscription();
295
        }
296
297
        return $this->subscription;
298
    }
299
300
    /**
301
     * @param Subscription $subscription
302
     */
303
    public function setSubscription(Subscription $subscription)
304
    {
305
        $this->subscription = $subscription;
306
307
        return $this;
308
    }
309
}
310