GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#62)
by Jelte
03:21
created

AbstractPaymentRequest   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 303
Duplicated Lines 12.54 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 2
Metric Value
wmc 41
c 6
b 1
f 2
lcom 1
cbo 1
dl 38
loc 303
ccs 104
cts 104
cp 1
rs 8.2769

23 Methods

Rating   Name   Duplication   Size   Complexity  
A setOrderid() 0 10 3
A setOrderDescription() 0 4 1
A setCom() 7 7 2
A setAmount() 13 13 4
A setCurrency() 0 7 2
A setEmail() 10 10 3
A setOwnerAddress() 0 7 2
A setOwnerZip() 0 7 2
A setOwnerTown() 0 7 2
A setOwnerCountry() 0 4 1
A setOwnercty() 0 7 2
A setOwnerPhone() 0 4 1
A setOwnertelno() 0 7 2
A setFeedbackMessage() 0 4 1
A setComplus() 0 4 1
A setBrand() 0 9 2
A setPaymentMethod() 0 4 1
A setPm() 0 7 2
A setParamvar() 0 7 3
A setDynamicTemplateUri() 0 4 1
A setTp() 0 5 1
A setOperation() 8 8 2
getValidOperations() 0 1 ?

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like AbstractPaymentRequest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use AbstractPaymentRequest, and based on these observations, apply Extract Interface, too.

1
<?php
2
/*
3
 * This file is part of the Marlon Ogone package.
4
 *
5
 * (c) Marlon BVBA <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Ogone;
12
13
use InvalidArgumentException;
14
15
abstract class AbstractPaymentRequest extends AbstractRequest
16
{
17
    const OPERATION_REQUEST_AUTHORIZATION = 'RES';
18
    const OPERATION_REQUEST_DIRECT_SALE = 'SAL';
19
    const OPERATION_REFUND = 'RFD';
20
    const OPERATION_REQUEST_PRE_AUTHORIZATION = 'PAU';
21
22
    protected $brandsmap = array(
23
        'Acceptgiro'            => 'Acceptgiro',
24
        'AIRPLUS'               => 'CreditCard',
25
        'American Express'      => 'CreditCard',
26
        'Aurora'                => 'CreditCard',
27
        'Aurore'                => 'CreditCard',
28
        'Bank transfer'         => 'Bank transfer',
29
        'Bank transfer BE'      => 'Bank transfer BE',
30
        'Bank transfer DE'      => 'Bank transfer DE',
31
        'Bank transfer FR'      => 'Bank transfer FR',
32
        'Bank transfer NL'      => 'Bank transfer NL',
33
        'BCMC'                  => 'CreditCard',
34
        'Belfius Direct Net'    => 'Belfius Direct Net',
35
        'Billy'                 => 'CreditCard',
36
        'cashU'                 => 'cashU',
37
        'CB'                    => 'CreditCard',
38
        'CBC Online'            => 'CBC Online',
39
        'CENTEA Online'         => 'CENTEA Online',
40
        'Cofinoga'              => 'CreditCard',
41
        'Dankort'               => 'CreditCard',
42
        'Dexia Direct Net'      => 'Dexia Direct Net',
43
        'Diners Club'           => 'CreditCard',
44
        'Direct Debits AT'      => 'Direct Debits AT',
45
        'Direct Debits DE'      => 'Direct Debits DE',
46
        'Direct Debits NL'      => 'Direct Debits NL',
47
        'DirectEbankingDE'      => 'DirectEbankingDE',
48
        'DirectEbankingAT'      => 'DirectEbankingAT',
49
        'DirectEbankingIT'      => 'DirectEbankingIT',
50
        'DirectEbankingBE'      => 'DirectEbankingBE',
51
        'DirectEbankingFR'      => 'DirectEbankingFR',
52
        'eDankort'              => 'eDankort',
53
        'EPS'                   => 'EPS',
54
        'Fortis Pay Button'     => 'Fortis Pay Button',
55
        'giropay'               => 'giropay',
56
        'iDEAL'                 => 'iDEAL',
57
        'ING HomePay'           => 'ING HomePay',
58
        'InterSolve'            => 'InterSolve',
59
        'JCB'                   => 'CreditCard',
60
        'KBC Online'            => 'KBC Online',
61
        'Maestro'               => 'CreditCard',
62
        'MaestroUK'             => 'CreditCard',
63
        'MasterCard'            => 'CreditCard',
64
        'MiniTix'               => 'MiniTix',
65
        'MPASS'                 => 'MPASS',
66
        'NetReserve'            => 'CreditCard',
67
        'Payment on Delivery'   => 'Payment on Delivery',
68
        'PAYPAL'                => 'PAYPAL',
69
        'paysafecard'           => 'paysafecard',
70
        'PingPing'              => 'PingPing',
71
        'PostFinance + card'    => 'PostFinance Card',
72
        'PostFinance e-finance' => 'PostFinance e-finance',
73
        'PRIVILEGE'             => 'CreditCard',
74
        'Sofort Uberweisung'    => 'DirectEbanking',
75
        'Solo'                  => 'CreditCard',
76
        'TUNZ'                  => 'TUNZ',
77
        'UATP'                  => 'CreditCard',
78
        'UNEUROCOM'             => 'UNEUROCOM',
79
        'VISA'                  => 'CreditCard',
80
        'Wallie'                => 'Wallie',
81
    );
82
83
    /** Note this is public to allow easy modification, if need be. */
84
    public $allowedcurrencies = array(
85
        'AED',
86
        'ANG',
87
        'ARS',
88
        'AUD',
89
        'AWG',
90
        'BGN',
91
        'BRL',
92
        'BYR',
93
        'CAD',
94
        'CHF',
95
        'CNY',
96
        'CZK',
97
        'DKK',
98
        'EEK',
99
        'EGP',
100
        'EUR',
101
        'GBP',
102
        'GEL',
103
        'HKD',
104
        'HRK',
105
        'HUF',
106
        'ILS',
107
        'ISK',
108
        'JPY',
109
        'KRW',
110
        'LTL',
111
        'LVL',
112
        'MAD',
113
        'MXN',
114
        'MYR',
115
        'NOK',
116
        'NZD',
117
        'PLN',
118
        'RON',
119
        'RUB',
120
        'SEK',
121
        'SGD',
122
        'SKK',
123
        'THB',
124
        'TRY',
125
        'UAH',
126
        'USD',
127
        'XAF',
128
        'XOF',
129
        'XPF',
130
        'ZAR'
131
    );
132
133 15
    public function setOrderid($orderid)
134
    {
135 15
        if (strlen($orderid) > 30) {
136 1
            throw new InvalidArgumentException("Orderid cannot be longer than 30 characters");
137
        }
138 14
        if (preg_match('/[^a-zA-Z0-9_-]/', $orderid)) {
139 1
            throw new InvalidArgumentException("Order id cannot contain special characters");
140
        }
141 13
        $this->parameters['orderid'] = $orderid;
142 13
    }
143
144
    /** Friend alias for setCom() */
145 2
    public function setOrderDescription($orderDescription)
146
    {
147 2
        $this->setCom($orderDescription);
148 1
    }
149
150 2 View Code Duplication
    public function setCom($com)
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...
151
    {
152 2
        if (strlen($com) > 100) {
153 1
            throw new InvalidArgumentException("Order description cannot be longer than 100 characters");
154
        }
155 1
        $this->parameters['com'] = $com;
156 1
    }
157
158
    /**
159
     * Set amount in cents, eg EUR 12.34 is written as 1234
160
     */
161 14 View Code Duplication
    public function setAmount($amount)
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...
162
    {
163 14
        if (!is_int($amount)) {
164 1
            throw new InvalidArgumentException("Integer expected. Amount is always in cents");
165
        }
166 13
        if ($amount <= 0) {
167 1
            throw new InvalidArgumentException("Amount must be a positive number");
168
        }
169 12
        if ($amount >= 1.0E+15) {
170 1
            throw new InvalidArgumentException("Amount is too high");
171
        }
172 11
        $this->parameters['amount'] = $amount;
173 11
    }
174
175 14
    public function setCurrency($currency)
176
    {
177 14
        if (!in_array(strtoupper($currency), $this->allowedcurrencies)) {
178 1
            throw new InvalidArgumentException("Unknown currency");
179
        }
180 13
        $this->parameters['currency'] = $currency;
181 13
    }
182
183 8 View Code Duplication
    public function setEmail($email)
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...
184
    {
185 8
        if (strlen($email) > 50) {
186 1
            throw new InvalidArgumentException("Email is too long");
187
        }
188 7
        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
189 1
            throw new InvalidArgumentException("Email is invalid");
190
        }
191 6
        $this->parameters['email'] = $email;
192 6
    }
193
194 7
    public function setOwnerAddress($owneraddress)
195
    {
196 7
        if (strlen($owneraddress) > 35) {
197 1
            throw new InvalidArgumentException("Owner address is too long");
198
        }
199 6
        $this->parameters['owneraddress'] = $owneraddress;
200 6
    }
201
202 7
    public function setOwnerZip($ownerzip)
203
    {
204 7
        if (strlen($ownerzip) > 10) {
205 1
            throw new InvalidArgumentException("Owner Zip is too long");
206
        }
207 6
        $this->parameters['ownerzip'] = $ownerzip;
208 6
    }
209
210 7
    public function setOwnerTown($ownertown)
211
    {
212 7
        if (strlen($ownertown) > 40) {
213 1
            throw new InvalidArgumentException("Owner town is too long");
214
        }
215 6
        $this->parameters['ownertown'] = $ownertown;
216 6
    }
217
218
    /**
219
     * Alias for setOwnercty
220
     *
221
     * @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
222
     */
223 7
    public function setOwnerCountry($ownercountry)
224
    {
225 7
        $this->setOwnercty($ownercountry);
226 6
    }
227
228
    /**
229
     * @see http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
230
     */
231 7
    public function setOwnercty($ownercty)
232
    {
233 7
        if (!preg_match('/^[A-Z]{2}$/', strtoupper($ownercty))) {
234 1
            throw new InvalidArgumentException("Illegal country code");
235
        }
236 6
        $this->parameters['ownercty'] = strtoupper($ownercty);
237 6
    }
238
239
    /** Alias for setOwnertelno() */
240 2
    public function setOwnerPhone($ownerphone)
241
    {
242 2
        $this->setOwnertelno($ownerphone);
243 1
    }
244
245 2
    public function setOwnertelno($ownertelno)
246
    {
247 2
        if (strlen($ownertelno) > 30) {
248 1
            throw new InvalidArgumentException("Owner phone is too long");
249
        }
250 1
        $this->parameters['ownertelno'] = $ownertelno;
251 1
    }
252
253
    /** Alias for setComplus() */
254 1
    public function setFeedbackMessage($feedbackMessage)
255
    {
256 1
        $this->setComplus($feedbackMessage);
257 1
    }
258
259 1
    public function setComplus($complus)
260
    {
261 1
        $this->parameters['complus'] = $complus;
262 1
    }
263
264 2
    public function setBrand($brand)
265
    {
266 2
        if (!array_key_exists($brand, $this->brandsmap)) {
267 1
            throw new InvalidArgumentException("Unknown Brand [$brand].");
268
        }
269
270 1
        $this->setPaymentMethod($this->brandsmap[$brand]);
271 1
        $this->parameters['brand'] = $brand;
272 1
    }
273
274 2
    public function setPaymentMethod($paymentMethod)
275
    {
276 2
        $this->setPm($paymentMethod);
277 1
    }
278
279 2
    public function setPm($pm)
280
    {
281 2
        if (!in_array($pm, $this->brandsmap)) {
282 1
            throw new InvalidArgumentException("Unknown Payment method [$pm].");
283
        }
284 1
        $this->parameters['pm'] = $pm;
285 1
    }
286
287 2
    public function setParamvar($paramvar)
288
    {
289 2
        if (strlen($paramvar) < 2 || strlen($paramvar) > 50) {
290 1
            throw new InvalidArgumentException("Paramvar must be between 2 and 50 characters in length");
291
        }
292 1
        $this->parameters['paramvar'] = $paramvar;
293 1
    }
294
295
    /** Alias for setTp */
296 2
    public function setDynamicTemplateUri($uri)
297
    {
298 2
        $this->setTp($uri);
299 1
    }
300
301 2
    public function setTp($tp)
302
    {
303 2
        $this->validateUri($tp);
304 1
        $this->parameters['tp'] = $tp;
305 1
    }
306
307 6 View Code Duplication
    public function setOperation($operation)
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...
308
    {
309 6
        if (!in_array($operation, $this->getValidOperations())) {
310 3
            throw new InvalidArgumentException("Invalid operation [$operation].");
311
        }
312
313 3
        $this->parameters['operation'] = $operation;
314 3
    }
315
316
    abstract protected function getValidOperations();
317
}
318