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.

ParameterResolver::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Lexik\Bundle\PayboxBundle\Paybox\DirectPlus;
4
5
use Lexik\Bundle\PayboxBundle\Paybox\AbstractParameterResolver;
6
7
/**
8
 * Class ParameterResolver
9
 * Based on PAYBOX DIRECT PLUS VERSION 6.2 documentation.
10
 *
11
 * @package Lexik\Bundle\PayboxBundle\Paybox\DirectPlus
12
 *
13
 * @author Lexik <[email protected]>
14
 * @author Olivier Maisonneuve <[email protected]>
15
 */
16
class ParameterResolver extends AbstractParameterResolver
17
{
18
    /**
19
     * @var array All availables parameters DirectPlus calls.
20
     */
21
    private $knownParameters = array(
22
        'VERSION'             => '%05d',
23
        'TYPE'                => '%05d',
24
        'SITE'                => '%07d',
25
        'RANG'                => '%03d',
26
        'CLE'                 => '%s',
27
        'NUMQUESTION'         => '%010d',
28
        'DATEQ'               => '%014s',
29
        'ACQUEREUR'           => null,
30
        'ACTIVITE'            => '%03d',
31
        'ARCHIVAGE'           => null,
32
        'AUTORISATION'        => null,
33
        'CODEREPONSE'         => null,
34
        'COMMENTAIRE'         => null,
35
        'CVV'                 => null,
36
        'DATENAISS'           => '%08d',
37
        'DATEVAL'             => null,
38
        'DEVISE'              => null,
39
        'DIFFERE'             => '%03d',
40
        'ERRORCODETEST'       => '%05d',
41
        'ID3D'                => null,
42
        'MONTANT'             => '%010d',
43
        'NUMAPPEL'            => '%010d',
44
        'NUMTRANS'            => '%010d',
45
        'PAYS'                => null,
46
        'PORTEUR'             => null,
47
        'PRIV_CODETRAITEMENT' => '%03d',
48
        'REFABONNE'           => null,
49
        'REFERENCE'           => null,
50
        'REMISE'              => null,
51
        'SHA-1'               => null,
52
        'STATUS'              => null,
53
        'TYPECARTE'           => null,
54
    );
55
56
    /**
57
     * @var array Requireds parameters for any DirectPlus call.
58
     */
59
    private $requiredParameters = array(
60
        'VERSION',
61
        'TYPE',
62
        'SITE',
63
        'RANG',
64
        'CLE',
65
        'NUMQUESTION',
66
        'DATEQ',
67
    );
68
69
    /**
70
     * @var array
71
     */
72
    private $currencies;
73
74
    /**
75
     * Constructor initialize all available parameters.
76
     *
77
     * @param array $currencies
78
     */
79
    public function __construct(array $currencies)
80
    {
81
        parent::__construct();
82
83
        $this->currencies = $currencies;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function resolve(array $parameters)
90
    {
91
        $this->initResolver();
92
93
        $result = $this->resolver->resolve($parameters);
94
        $result = $this->normalize($result);
95
96
        return $result;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102 View Code Duplication
    protected function initResolver()
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...
103
    {
104
        $this->resolver->setRequired($this->requiredParameters);
105
106
        $this->resolver->setDefined(array_diff(array_keys($this->knownParameters), $this->requiredParameters));
107
108
        $this->initAllowed();
109
    }
110
111
    /**
112
     * Initialize allowed values.
113
     */
114
    protected function initAllowed()
115
    {
116
        $this->resolver
117
            ->setAllowedValues('ACTIVITE', array(
118
                '020',
119
                '021',
120
                '022',
121
                '023',
122
                '024',
123
                '027',
124
                20,
125
                21,
126
                22,
127
                23,
128
                24,
129
                27,
130
            ))
131
            ->setAllowedValues('DEVISE', $this->currencies)
132
            ->setAllowedValues('TYPE', array(
133
                '00001',
134
                '00002',
135
                '00003',
136
                '00004',
137
                '00005',
138
                '00011',
139
                '00012',
140
                '00013',
141
                '00014',
142
                '00017',
143
                '00051',
144
                '00052',
145
                '00053',
146
                '00054',
147
                '00055',
148
                '00056',
149
                '00057',
150
                '00058',
151
                '00061',
152
                1,
153
                2,
154
                3,
155
                4,
156
                5,
157
                11,
158
                12,
159
                13,
160
                14,
161
                17,
162
                51,
163
                52,
164
                53,
165
                54,
166
                55,
167
                56,
168
                57,
169
                58,
170
                61,
171
            ))
172
            ->setAllowedValues('VERSION', array(
173
                '00103',
174
                '00104',
175
                103,
176
                104,
177
            ))
178
        ;
179
    }
180
181
    /**
182
     * Normalizes parameters depending on Paybox's 6.2 parameters specifications.
183
     *
184
     * @param array $parameters
185
     *
186
     * @return array
187
     */
188
    protected function normalize(array $parameters)
189
    {
190
        foreach ($parameters as $parameter => $value) {
191
            if (null !== $this->knownParameters[$parameter]) {
192
                $parameters[$parameter] = sprintf($this->knownParameters[$parameter], $value);
193
            }
194
        }
195
196
        return $parameters;
197
    }
198
}
199