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
Push — master ( ddf1bf...dacac4 )
by Jelte
11:46 queued 09:25
created

AbstractPaymentRequest::setStaticTemplate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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