Completed
Push — master ( a6e4ea...ae9fdb )
by Florian
14s
created

Payone_Api_Response_Abstract::isPending()   A

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
c 0
b 0
f 0
rs 9.4285
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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 isPending()
130
    {
131
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::PENDING) {
132
            return true;
133
        }
134
135
        return false;
136
    }
137
138
    /**
139
     * @return bool
140
     */
141
    public function isRedirect()
142
    {
143
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::REDIRECT) {
144
            return true;
145
        }
146
147
        return false;
148
    }
149
150
    /**
151
     * @return bool
152
     */
153
    public function isValid()
154
    {
155
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::VALID) {
156
            return true;
157
        }
158
159
        return false;
160
    }
161
162
    /**
163
     * @return bool
164
     */
165
    public function isInvalid()
166
    {
167
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::INVALID) {
168
            return true;
169
        }
170
171
        return false;
172
    }
173
174
    /**
175
     * @return bool
176
     */
177
    public function isBlocked()
178
    {
179
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::BLOCKED) {
180
            return true;
181
        }
182
183
        return false;
184
    }
185
186
    /**
187
     * @return bool
188
     */
189
    public function isEnrolled()
190
    {
191
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::ENROLLED) {
192
            return true;
193
        }
194
195
        return false;
196
    }
197
198
    /**
199
     * @return bool
200
     */
201
    public function isError()
202
    {
203
        if ($this->getStatus() === Payone_Api_Enum_ResponseType::ERROR) {
204
            return true;
205
        }
206
207
        return false;
208
    }
209
210
    /**
211
     * @param string $status
212
     */
213
    public function setStatus($status)
214
    {
215
        $this->status = $status;
216
    }
217
218
    /**
219
     * @return string
220
     */
221
    public function getStatus()
222
    {
223
        return $this->status;
224
    }
225
226
    /**
227
     * @param string $key
228
     * @return null|mixed
229
     */
230
    public function getValue($key)
231
    {
232
        return $this->get($key);
233
    }
234
235
    /**
236
     * @param string $key
237
     * @param string $name
238
     * @return boolean|null
239
     */
240
    public function setValue($key, $name)
241
    {
242
        return $this->set($key, $name);
243
    }
244
245
    /**
246
     * @param $name
247
     * @return null|mixed
248
     */
249
    protected function get($name)
250
    {
251
        if (property_exists($this, $name)) {
252
            return $this->$name;
253
        }
254
255
        return null;
256
    }
257
258
    /**
259
     * @param string $name
260
     * @param mixed $value
261
     * @return boolean|null
262
     */
263
    protected function set($name, $value)
264
    {
265
        if (property_exists($this, $name)) {
266
            $this->$name = $value;
267
            return true;
268
        }
269
270
        return null;
271
    }
272
273
    /**
274
     * @param $rawResponse
275
     */
276
    public function setRawResponse($rawResponse)
277
    {
278
        $this->rawResponse = $rawResponse;
279
    }
280
    /**
281
     * @return null
282
     */
283
    public function getRawResponse()
284
    {
285
        return $this->rawResponse;
286
    }
287
288
    /**
289
     * @param Payone_Protocol_Service_ApplyFilters $applyFilters
290
     */
291
    public function setApplyFilters(Payone_Protocol_Service_ApplyFilters $applyFilters)
292
    {
293
        $this->applyFilters = $applyFilters;
294
    }
295
}
296