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 ( e176a0...0ea391 )
by Jelte
02:11
created

AbstractRequest::setSecure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 RuntimeException;
15
use BadMethodCallException;
16
use Ogone\ShaComposer\ShaComposer;
17
18
abstract class AbstractRequest implements Request
19
{
20
    /** @var ShaComposer */
21
    protected $shaComposer;
22
23
    protected $ogoneUri;
24
25
    protected $parameters = array();
26
27
    /** Note this is public to allow easy modification, if need be. */
28
    public $allowedlanguages = array(
29
        'en_US' => 'English', 'cs_CZ' => 'Czech', 'de_DE' => 'German',
30
        'dk_DK' => 'Danish', 'el_GR' => 'Greek', 'es_ES' => 'Spanish',
31
        'fr_FR' => 'French', 'it_IT' => 'Italian', 'ja_JP' => 'Japanese',
32
        'nl_BE' => 'Flemish', 'nl_NL' => 'Dutch', 'no_NO' => 'Norwegian',
33
        'pl_PL' => 'Polish', 'pt_PT' => 'Portugese', 'ru_RU' => 'Russian',
34
        'se_SE' => 'Swedish', 'sk_SK' => 'Slovak', 'tr_TR' => 'Turkish'
35
    );
36
37
    protected $ogoneFields = array(
38
        'pspid', 'orderid', 'com', 'amount', 'currency', 'language', 'cn', 'email',
39
        'cardno', 'cvc', 'ed', 'ownerzip', 'owneraddress', 'ownercty', 'ownertown',
40
        'ownertelno', 'homeurl', 'accepturl', 'declineurl', 'exceptionurl', 'cancelurl', 'backurl',
41
        'complus', 'paramplus', 'pm', 'brand', 'title', 'bgcolor', 'txtcolor', 'tblbgcolor',
42
        'tbltxtcolor', 'buttonbgcolor', 'buttontxtcolor', 'logo', 'fonttype', 'tp', 'paramvar',
43
        'alias', 'aliasoperation', 'aliasusage', 'aliaspersistedafteruse', 'device', 'pmlisttype',
44
        'ecom_payment_card_verification', 'operation', 'withroot', 'remote_addr', 'rtimeout',
45
        'flag3d', 'http_accept', 'http_user_agent', 'win3ds',
46
    );
47
48
    /** @return string */
49 4
    public function getShaSign()
50
    {
51 4
        return $this->shaComposer->compose($this->toArray());
52
    }
53
54
    /** @return string */
55 4
    public function getOgoneUri()
56
    {
57 4
        return $this->ogoneUri;
58
    }
59
60
    /** Ogone uri to send the customer to. Usually PaymentRequest::TEST or PaymentRequest::PRODUCTION */
61 15
    public function setOgoneUri($ogoneUri)
62
    {
63 15
        $this->validateOgoneUri($ogoneUri);
64 10
        $this->ogoneUri = $ogoneUri;
65 10
    }
66
67 25
    public function setPspid($pspid)
68
    {
69 25
        if (strlen($pspid) > 30) {
70 1
            throw new InvalidArgumentException("PSPId is too long");
71
        }
72 24
        $this->parameters['pspid'] = $pspid;
73 24
    }
74
75 6
    public function setSecure()
76
    {
77 6
      $this->parameters['win3ds'] = 'MAINW';
78 6
    }
79
80
    /**
81
     * ISO code eg nl_BE
82
     */
83 2
    public function setLanguage($language)
84
    {
85 2
        if (!array_key_exists($language, $this->allowedlanguages)) {
86 1
            throw new InvalidArgumentException("Invalid language ISO code");
87
        }
88 1
        $this->parameters['language'] = $language;
89 1
    }
90
91
    /** Alias for setCn */
92 6
    public function setCustomername($customername)
93
    {
94 6
        $this->setCn($customername);
95 6
    }
96
97 6
    public function setCn($cn)
98
    {
99 6
        $this->parameters['cn'] = str_replace(array("'", '"'), '', $cn); // replace quotes
100 6
    }
101
102
    public function setHomeurl($homeurl)
103
    {
104
        if (!empty($homeurl)) {
105
            $this->validateUri($homeurl);
106
        }
107
        $this->parameters['homeurl'] = $homeurl;
108
    }
109
110 6
    public function setAccepturl($accepturl)
111
    {
112 6
        $this->validateUri($accepturl);
113 5
        $this->parameters['accepturl'] = $accepturl;
114 5
    }
115
116 2
    public function setDeclineurl($declineurl)
117
    {
118 2
        $this->validateUri($declineurl);
119 1
        $this->parameters['declineurl'] = $declineurl;
120 1
    }
121
122 6
    public function setExceptionurl($exceptionurl)
123
    {
124 6
        $this->validateUri($exceptionurl);
125 5
        $this->parameters['exceptionurl'] = $exceptionurl;
126 5
    }
127
128 3
    public function setCancelurl($cancelurl)
129
    {
130 3
        $this->validateUri($cancelurl);
131 1
        $this->parameters['cancelurl'] = $cancelurl;
132 1
    }
133
134 1
    public function setBackurl($backurl)
135
    {
136 1
        $this->validateUri($backurl);
137 1
        $this->parameters['backurl'] = $backurl;
138 1
    }
139
140
    /** Alias for setParamplus */
141 1
    public function setFeedbackParams(array $feedbackParams)
142
    {
143 1
        $this->setParamplus($feedbackParams);
144 1
    }
145
146 1
    public function setParamplus(array $paramplus)
147
    {
148 1
        $this->parameters['paramplus'] = http_build_query($paramplus);
149 1
    }
150
151 25
    public function validate()
152
    {
153 25
        foreach ($this->getRequiredFields() as $field) {
154 25
            if (empty($this->parameters[$field])) {
155 6
                throw new RuntimeException("$field can not be empty");
156
            }
157 20
        }
158 19
    }
159
160 23 View Code Duplication
    protected function validateUri($uri)
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...
161
    {
162 23
        if (!filter_var($uri, FILTER_VALIDATE_URL)) {
163 6
            throw new InvalidArgumentException("Uri is not valid");
164
        }
165 17
        if (strlen($uri) > 200) {
166 1
            throw new InvalidArgumentException("Uri is too long");
167
        }
168 16
    }
169
170 15
    protected function validateOgoneUri($uri)
171
    {
172 15
        $this->validateUri($uri);
173
174 14
        if (!in_array($uri, $this->getValidOgoneUris())) {
175 4
            throw new InvalidArgumentException('No valid Ogone url');
176
        }
177 10
    }
178
179
    /**
180
     * Allows setting ogone parameters that don't have a setter -- usually only
181
     * the unimportant ones like bgcolor, which you'd call with setBgcolor()
182
     *
183
     * @param $method
184
     * @param $args
185
     */
186 3
    public function __call($method, $args)
187
    {
188 3 View Code Duplication
        if (substr($method, 0, 3) == 'set') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
189 1
            $field = strtolower(substr($method, 3));
190 1
            if (in_array($field, $this->ogoneFields)) {
191 1
                $this->parameters[$field] = $args[0];
192 1
                return;
193
            }
194
        }
195
196 3 View Code Duplication
        if (substr($method, 0, 3) == 'get') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
197 3
            $field = strtolower(substr($method, 3));
198 3
            if (array_key_exists($field, $this->parameters)) {
199 2
                return $this->parameters[$field];
200
            }
201 1
        }
202
203 1
        throw new BadMethodCallException("Unknown method $method");
204
    }
205
206 4
    public function toArray()
207
    {
208 4
        $this->validate();
209 4
        return array_change_key_case($this->parameters, CASE_UPPER);
210
    }
211
}
212