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.

AbstractResponse   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 100
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A filterRequestParameters() 0 5 1
A extractShaSign() 0 7 3
A getParam() 0 15 3
A toArray() 0 4 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
15
abstract class AbstractResponse implements Response
16
{
17
18
    /**
19
     * Available Ogone parameters
20
     * @var array
21
     */
22
    protected $ogoneFields = array(
23
        'AAVADDRESS', 'AAVCHECK', 'AAVMAIL', 'AAVNAME', 'AAVPHONE', 'AAVZIP', 'ACCEPTANCE', 'ALIAS',
24
        'AMOUNT', 'BIC', 'BIN', 'BRAND', 'CARDNO', 'CCCTY', 'CN', 'COLLECTOR_BIC', 'COLLECTOR_IBAN',
25
        'COMPLUS', 'CREATION_STATUS', 'CREDITDEBIT', 'CURRENCY', 'CVC', 'CVCCHECK', 'DCC_COMMPERCENTAGE',
26
        'DCC_CONVAMOUNT', 'DCC_CONVCCY', 'DCC_EXCHRATE', 'DCC_EXCHRATESOURCE', 'DCC_EXCHRATETS',
27
        'DCC_INDICATOR', 'DCC_MARGINPERCENTAGE', 'DCC_VALIDHOURS', 'DEVICEID', 'DIGESTCARDNO', 'ECI',
28
        'ED', 'EMAIL', 'ENCCARDNO', 'FXAMOUNT', 'FXCURRENCY', 'IP', 'IPCTY', 'MANDATEID', 'MOBILEMODE',
29
        'NBREMAILUSAGE', 'NBRIPUSAGE', 'NBRIPUSAGE_ALLTX', 'NBRUSAGE', 'NCERROR', 'NCERRORPLUS', 'NCERRORCN',
30
        'NCERRORCARDNO', 'NCERRORCVC', 'NCERRORED', 'NCSTATUS', 'ORDERID', 'PAYID', 'PAYIDSUB',
31
        'PAYMENT_REFERENCE', 'PM', 'SCO_CATEGORY', 'SCORING', 'SEQUENCETYPE', 'SIGNDATE', 'STATUS',
32
        'SUBBRAND', 'SUBSCRIPTION_ID', 'TICKET', 'TRXDATE', 'VC',
33
    );
34
35
    /**
36
     * @var array
37
     */
38
    protected $parameters;
39
40
    /**
41
     * @var string
42
     */
43
    protected $shaSign;
44
45
    /**
46
     * @param array $httpRequest Typically $_REQUEST
47
     * @throws \InvalidArgumentException
48
     */
49 17
    public function __construct(array $httpRequest)
50
    {
51
        // use uppercase internally
52 17
        $httpRequest = array_change_key_case($httpRequest, CASE_UPPER);
53
54
        // set sha sign
55 17
        $this->shaSign = $this->extractShaSign($httpRequest);
56
57
        // filter request for Ogone parameters
58 15
        $this->parameters = $this->filterRequestParameters($httpRequest);
59 15
    }
60
61
    /**
62
     * Filter http request parameters
63
     * @param array $requestParameters
64
     * @return array
65
     */
66 22
    protected function filterRequestParameters(array $requestParameters)
67
    {
68
        // filter request for Ogone parameters
69 22
        return array_intersect_key($requestParameters, array_flip($this->ogoneFields));
70
    }
71
72
    /**
73
     * Set Ogone SHA sign
74
     * @param array $parameters
75
     * @throws \InvalidArgumentException
76
     */
77 17
    protected function extractShaSign(array $parameters)
78
    {
79 17
        if (!array_key_exists(self::SHASIGN_FIELD, $parameters) || $parameters[self::SHASIGN_FIELD] == '') {
80 2
            throw new InvalidArgumentException('SHASIGN parameter not present in parameters.');
81
        }
82 15
        return $parameters[self::SHASIGN_FIELD];
83
    }
84
85
    /**
86
     * Retrieves a response parameter
87
     * @param string $key
88
     * @throws \InvalidArgumentException
89
     */
90 32
    public function getParam($key)
91
    {
92 32
        if (method_exists($this, 'get'.$key)) {
93 18
            return $this->{'get'.$key}();
94
        }
95
96
        // always use uppercase
97 14
        $key = strtoupper($key);
98
99 14
        if (!array_key_exists($key, $this->parameters)) {
100 4
            throw new InvalidArgumentException('Parameter ' . $key . ' does not exist.');
101
        }
102
103 10
        return $this->parameters[$key];
104
    }
105
106
    /**
107
     * Get all parameters + SHASIGN
108
     * @return array
109
     */
110 1
    public function toArray()
111
    {
112 1
        return $this->parameters + array('SHASIGN' => $this->shaSign);
113
    }
114
}
115