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
04:52
created

AbstractRequest::__call()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 19
Code Lines 11

Duplication

Lines 13
Ratio 68.42 %

Importance

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