Payone_Api_Response_Abstract::isEnrolled()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
/**
3
 *
4
 * NOTICE OF LICENSE
5
 *
6
 * This source file is subject to the GNU General Public License (GPL 3)
7
 * that is bundled with this package in the file LICENSE.txt
8
 *
9
 * DISCLAIMER
10
 *
11
 * Do not edit or add to this file if you wish to upgrade Payone to newer
12
 * versions in the future. If you wish to customize Payone for your
13
 * needs please refer to http://www.payone.de for more information.
14
 *
15
 * @category        Payone
16
 * @package         Payone_Api
17
 * @subpackage      Response
18
 * @copyright       Copyright (c) 2012 <[email protected]> - www.noovias.com
19
 * @author          Matthias Walter <[email protected]>
20
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
21
 * @link            http://www.noovias.com
22
 */
23
24
/**
25
 *
26
 * @category        Payone
27
 * @package         Payone_Api
28
 * @subpackage      Response
29
 * @copyright       Copyright (c) 2012 <[email protected]> - www.noovias.com
30
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
31
 * @link            http://www.noovias.com
32
 */
33
abstract class Payone_Api_Response_Abstract implements Payone_Api_Response_Interface
34
{
35
    protected $status = NULL;
36
37
    protected $rawResponse = NULL;
38
39
    /**
40
     * @var Payone_Protocol_Service_ApplyFilters
41
     */
42
    private $applyFilters = NULL;
43
44
    /**
45
     * @param array $params
46
     */
47
    function __construct(array $params = array())
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
    {
49
        $this->setRawResponse($params);
0 ignored issues
show
Documentation introduced by
$params is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
        if (count($params) > 0) {
51
            $this->init($params);
52
        }
53
    }
54
55
    /**
56
     * @param array $data
57
     */
58
    public function init(array $data = array())
59
    {
60
        foreach ($data as $key => $value) {
61
            $key = ucwords(str_replace(array('_', '[', ']'), ' ', $key));
62
            $method = 'set' . str_replace(' ', '', $key);
63
            if (method_exists($this, $method)) {
64
                $this->{$method}($value);
65
            }
66
        }
67
    }
68
69
    /**
70
     * @return array
71
     */
72
    public function toArray()
73
    {
74
        $result = array();
75
        foreach ($this as $key => $data) {
0 ignored issues
show
Bug introduced by
The expression $this of type this<Payone_Api_Response_Abstract> is not traversable.
Loading history...
76
            if ($data === null) {
77
                continue;
78
            }
79
            elseif ($data instanceof Payone_Protocol_Service_ApplyFilters == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
80
                $result[$key] = $data;
81
            }
82
        }
83
84
        return $result;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function __toString()
91
    {
92
        return $this->_toString($this->toArray());
93
    }
94
    
95
    public function getRawResponseToString()
96
    {
97
        return $this->_toString($this->getRawResponse());
98
    }
99
    
100
    protected function _toString($aValue)
101
    {
102
        if($this->applyFilters) {
103
            $result = $this->applyFilters->apply($aValue);
104
        } else {
105
            $protocolFactory     = new Payone_Protocol_Factory();
106
            $defaultApplyFilters = $protocolFactory->buildServiceApplyFilters();
107
            $result = $defaultApplyFilters->apply($aValue);
108
        }
109
110
        return $result;        
111
    }
112
113
114
    /**
115
     * @return bool
116
     */
117
    public function isApproved()
118
    {
119
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::APPROVED) {
120
            return true;
121
        }
122
123
        return false;
124
    }
125
126
    /**
127
     * @return bool
128
     */
129
    public function isRedirect()
130
    {
131
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::REDIRECT) {
132
            return true;
133
        }
134
135
        return false;
136
    }
137
138
    /**
139
     * @return bool
140
     */
141
    public function isValid()
142
    {
143
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::VALID) {
144
            return true;
145
        }
146
147
        return false;
148
    }
149
150
    /**
151
     * @return bool
152
     */
153
    public function isInvalid()
154
    {
155
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::INVALID) {
156
            return true;
157
        }
158
159
        return false;
160
    }
161
162
    /**
163
     * @return bool
164
     */
165
    public function isBlocked()
166
    {
167
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::BLOCKED) {
168
            return true;
169
        }
170
171
        return false;
172
    }
173
174
    /**
175
     * @return bool
176
     */
177
    public function isEnrolled()
178
    {
179
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::ENROLLED) {
180
            return true;
181
        }
182
183
        return false;
184
    }
185
186
    /**
187
     * @return bool
188
     */
189
    public function isError()
190
    {
191
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::ERROR) {
192
            return true;
193
        }
194
195
        return false;
196
    }
197
198
    /**
199
     * @param string $status
200
     */
201
    public function setStatus($status)
202
    {
203
        $this->status = $status;
204
    }
205
206
    /**
207
     * @return string
208
     */
209
    public function getStatus()
210
    {
211
        return $this->status;
212
    }
213
214
    /**
215
     * @param string $key
216
     * @return null|mixed
217
     */
218
    public function getValue($key)
219
    {
220
        return $this->get($key);
221
    }
222
223
    /**
224
     * @param string $key
225
     * @param string $name
226
     * @return boolean|null
227
     */
228
    public function setValue($key, $name)
229
    {
230
        return $this->set($key, $name);
231
    }
232
233
    /**
234
     * @param $name
235
     * @return null|mixed
236
     */
237
    protected function get($name)
238
    {
239
        if (property_exists($this, $name)) {
240
            return $this->$name;
241
        }
242
243
        return null;
244
    }
245
246
    /**
247
     * @param string $name
248
     * @param mixed $value
249
     * @return boolean|null
250
     */
251
    protected function set($name, $value)
252
    {
253
        if (property_exists($this, $name)) {
254
            $this->$name = $value;
255
            return true;
256
        }
257
258
        return null;
259
    }
260
261
    /**
262
     * @param $rawResponse
263
     */
264
    public function setRawResponse($rawResponse)
265
    {
266
        $this->rawResponse = $rawResponse;
267
    }
268
    /**
269
     * @return null
270
     */
271
    public function getRawResponse()
272
    {
273
        return $this->rawResponse;
274
    }
275
276
    /**
277
     * @param Payone_Protocol_Service_ApplyFilters $applyFilters
278
     */
279
    public function setApplyFilters(Payone_Protocol_Service_ApplyFilters $applyFilters)
280
    {
281
        $this->applyFilters = $applyFilters;
282
    }
283
}
284