Completed
Push — master ( 7ce793...baf7a0 )
by Sullivan
04:40 queued 02:10
created

AbstractResponse::isSuccessful()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Nexy\PayboxDirect\Response;
4
5
/**
6
 * @author Sullivan Senechal <[email protected]>
7
 */
8
abstract class AbstractResponse implements ResponseInterface
9
{
10
    /**
11
     * @var int
12
     */
13
    private $code;
14
15
    /**
16
     * @var string
17
     */
18
    private $comment;
19
20
    /**
21
     * @var string
22
     */
23
    private $site;
24
25
    /**
26
     * @var string
27
     */
28
    private $rank;
29
30
    /**
31
     * @var int
32
     */
33
    private $callNumber;
34
35
    /**
36
     * @var int
37
     */
38
    private $questionNumber;
39
40
    /**
41
     * @var int
42
     */
43
    private $transactionNumber;
44
45
    /**
46
     * @var string|null|false
47
     */
48
    private $authorization = null;
49
50
    /**
51
     * @var string|null|false
52
     */
53
    private $country = null;
54
55
    /**
56
     * @var string|null|false
57
     */
58
    private $sha1 = null;
59
60
    /**
61
     * @var string|null|false
62
     */
63
    private $cardType = null;
64
65
    /**
66
     * @var mixed[]
67
     */
68
    protected $filteredParameters;
69
70
    /**
71
     * @param string[] $parameters
72
     */
73
    public function __construct(array $parameters)
74
    {
75
        // Cleanup array to set false for empty/invalid values.
76
        $this->filteredParameters = array_map(function ($value) {
77
            if (in_array($value, ['', '???'], true)) {
78
                return false;
79
            }
80
81
            return $value;
82
        }, $parameters);
83
84
        $this->code = intval($this->filteredParameters['CODEREPONSE']);
85
        $this->comment = $this->filteredParameters['COMMENTAIRE'];
86
        $this->site = $this->filteredParameters['SITE'];
87
        $this->rank = $this->filteredParameters['RANG'];
88
        $this->callNumber = intval($this->filteredParameters['NUMAPPEL']);
89
        $this->questionNumber = intval($this->filteredParameters['NUMQUESTION']);
90
        $this->transactionNumber = intval($this->filteredParameters['NUMTRANS']);
91
92
        if (array_key_exists('AUTORISATION', $this->filteredParameters)) {
93
            $this->authorization = $this->filteredParameters['AUTORISATION'];
94
        }
95
        if (array_key_exists('PAYS', $this->filteredParameters)) {
96
            $this->country = $this->filteredParameters['PAYS'];
97
        }
98
        if (array_key_exists('SHA-1', $this->filteredParameters)) {
99
            $this->sha1 = $this->filteredParameters['SHA-1'];
100
        }
101
        if (array_key_exists('TYPECARTE', $this->filteredParameters)) {
102
            $this->cardType = $this->filteredParameters['TYPECARTE'];
103
        }
104
    }
105
106
    /**
107
     * {@inheritdoc}
108
     */
109
    final public function isSuccessful()
110
    {
111
        return 0 === $this->code;
112
    }
113
114
    /**
115
     * {@inheritdoc}
116
     */
117
    final public function getCode()
118
    {
119
        return $this->code;
120
    }
121
122
    /**
123
     * {@inheritdoc}
124
     */
125
    final public function getComment()
126
    {
127
        return $this->comment;
128
    }
129
130
    /**
131
     * {@inheritdoc}
132
     */
133
    final public function getSite()
134
    {
135
        return $this->site;
136
    }
137
138
    /**
139
     * {@inheritdoc}
140
     */
141
    final public function getRank()
142
    {
143
        return $this->rank;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149
    final public function getCallNumber()
150
    {
151
        return $this->callNumber;
152
    }
153
154
    /**
155
     * {@inheritdoc}
156
     */
157
    final public function getQuestionNumber()
158
    {
159
        return $this->questionNumber;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    final public function getTransactionNumber()
166
    {
167
        return $this->transactionNumber;
168
    }
169
170
    /**
171
     * {@inheritdoc}
172
     */
173
    public function getAuthorization()
174
    {
175
        return $this->authorization;
176
    }
177
178
    /**
179
     * {@inheritdoc}
180
     */
181
    public function getCountry()
182
    {
183
        return $this->country;
184
    }
185
186
    /**
187
     * {@inheritdoc}
188
     */
189
    final public function getSha1()
190
    {
191
        return $this->sha1;
192
    }
193
194
    /**
195
     * {@inheritdoc}
196
     */
197
    public function getCardType()
198
    {
199
        return $this->cardType;
200
    }
201
}
202