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