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 ( 965474...3c01fc )
by Jelte
06:00 queued 03:33
created

AbstractRequest::setHomeurl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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
        'operation',
45
    );
46
47
    /** @return string */
48 4
    public function getShaSign()
49
    {
50 4
        return $this->shaComposer->compose($this->toArray());
51
    }
52
53
    /** @return string */
54 4
    public function getOgoneUri()
55
    {
56 4
        return $this->ogoneUri;
57
    }
58
59
    /** Ogone uri to send the customer to. Usually PaymentRequest::TEST or PaymentRequest::PRODUCTION */
60 15
    public function setOgoneUri($ogoneUri)
61
    {
62 15
        $this->validateOgoneUri($ogoneUri);
63 10
        $this->ogoneUri = $ogoneUri;
64 10
    }
65
66 25
    public function setPspid($pspid)
67
    {
68 25
        if (strlen($pspid) > 30) {
69 1
            throw new InvalidArgumentException("PSPId is too long");
70
        }
71 24
        $this->parameters['pspid'] = $pspid;
72 24
    }
73
74
    /**
75
     * ISO code eg nl_BE
76
     */
77 2
    public function setLanguage($language)
78
    {
79 2
        if (!array_key_exists($language, $this->allowedlanguages)) {
80 1
            throw new InvalidArgumentException("Invalid language ISO code");
81
        }
82 1
        $this->parameters['language'] = $language;
83 1
    }
84
85
    /** Alias for setCn */
86 6
    public function setCustomername($customername)
87
    {
88 6
        $this->setCn($customername);
89 6
    }
90
91 6
    public function setCn($cn)
92
    {
93 6
        $this->parameters['cn'] = str_replace(array("'", '"'), '', $cn); // replace quotes
94 6
    }
95
96
    public function setHomeurl($homeurl)
97
    {
98
        if (!empty($homeurl)) {
99
            $this->validateUri($homeurl);
100
        }
101
        $this->parameters['homeurl'] = $homeurl;
102
    }
103
104 6
    public function setAccepturl($accepturl)
105
    {
106 6
        $this->validateUri($accepturl);
107 5
        $this->parameters['accepturl'] = $accepturl;
108 5
    }
109
110 2
    public function setDeclineurl($declineurl)
111
    {
112 2
        $this->validateUri($declineurl);
113 1
        $this->parameters['declineurl'] = $declineurl;
114 1
    }
115
116 6
    public function setExceptionurl($exceptionurl)
117
    {
118 6
        $this->validateUri($exceptionurl);
119 5
        $this->parameters['exceptionurl'] = $exceptionurl;
120 5
    }
121
122 3
    public function setCancelurl($cancelurl)
123
    {
124 3
        $this->validateUri($cancelurl);
125 1
        $this->parameters['cancelurl'] = $cancelurl;
126 1
    }
127
128 1
    public function setBackurl($backurl)
129
    {
130 1
        $this->validateUri($backurl);
131 1
        $this->parameters['backurl'] = $backurl;
132 1
    }
133
134
    /** Alias for setParamplus */
135 1
    public function setFeedbackParams(array $feedbackParams)
136
    {
137 1
        $this->setParamplus($feedbackParams);
138 1
    }
139
140 1
    public function setParamplus(array $paramplus)
141
    {
142 1
        $this->parameters['paramplus'] = http_build_query($paramplus);
143 1
    }
144
145 25
    public function validate()
146
    {
147 25
        foreach ($this->getRequiredFields() as $field) {
148 25
            if (empty($this->parameters[$field])) {
149 6
                throw new RuntimeException("$field can not be empty");
150
            }
151 20
        }
152 19
    }
153
154 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...
155
    {
156 23
        if (!filter_var($uri, FILTER_VALIDATE_URL)) {
157 6
            throw new InvalidArgumentException("Uri is not valid");
158
        }
159 17
        if (strlen($uri) > 200) {
160 1
            throw new InvalidArgumentException("Uri is too long");
161
        }
162 16
    }
163
164 15
    protected function validateOgoneUri($uri)
165
    {
166 15
        $this->validateUri($uri);
167
168 14
        if (!in_array($uri, $this->getValidOgoneUris())) {
169 4
            throw new InvalidArgumentException('No valid Ogone url');
170
        }
171 10
    }
172
173
    /**
174
     * Allows setting ogone parameters that don't have a setter -- usually only
175
     * the unimportant ones like bgcolor, which you'd call with setBgcolor()
176
     *
177
     * @param $method
178
     * @param $args
179
     */
180 3
    public function __call($method, $args)
181
    {
182 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...
183 1
            $field = strtolower(substr($method, 3));
184 1
            if (in_array($field, $this->ogoneFields)) {
185 1
                $this->parameters[$field] = $args[0];
186 1
                return;
187
            }
188
        }
189
190 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...
191 3
            $field = strtolower(substr($method, 3));
192 3
            if (array_key_exists($field, $this->parameters)) {
193 2
                return $this->parameters[$field];
194
            }
195 1
        }
196
197 1
        throw new BadMethodCallException("Unknown method $method");
198
    }
199
200 4
    public function toArray()
201
    {
202 4
        $this->validate();
203 4
        return array_change_key_case($this->parameters, CASE_UPPER);
204
    }
205
}
206