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

Payone_Api_Mapper_Response_Abstract   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 23
lcom 1
cbo 1
dl 0
loc 153
c 0
b 0
f 0
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A isApproved() 0 9 2
A isPending() 0 9 2
A isRedirect() 0 9 2
A isValid() 0 9 2
A isInvalid() 0 9 2
A isBlocked() 0 9 2
A isEnrolled() 0 9 2
A isError() 0 9 2
A isOk() 0 9 2
A setParams() 0 4 1
A getParams() 0 4 1
A getParam() 0 10 3
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      Mapper
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      Mapper
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_Mapper_Response_Abstract extends Payone_Api_Mapper_Abstract
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
    // @todo hs: Introduce constants for the various status´ , where? Settings?
36
    /**
37
     * @var array
38
     */
39
    protected $params = null;
40
41
    /**
42
     * @return bool
43
     */
44
    protected function isApproved()
45
    {
46
        $status = $this->getParam('status');
47
        if ($status === 'APPROVED') {
48
            return true;
49
        }
50
51
        return false;
52
    }
53
54
    protected function isPending()
55
    {
56
        $status = $this->getParam('status');
57
        if ($status === 'PENDING') {
58
            return true;
59
        }
60
61
        return false;
62
    }
63
64
    /**
65
     * @return bool
66
     */
67
    protected function isRedirect()
68
    {
69
        $status = $this->getParam('status');
70
        if ($status === 'REDIRECT') {
71
            return true;
72
        }
73
74
        return false;
75
    }
76
77
    /**
78
     * @return bool
79
     */
80
    protected function isValid()
81
    {
82
        $status = $this->getParam('status');
83
        if ($status === 'VALID') {
84
            return true;
85
        }
86
87
        return false;
88
    }
89
90
    /**
91
     * @return bool
92
     */
93
    protected function isInvalid()
94
    {
95
        $status = $this->getParam('status');
96
        if ($status === 'INVALID') {
97
            return true;
98
        }
99
100
        return false;
101
    }
102
103
    /**
104
     * @return bool
105
     */
106
    protected function isBlocked()
107
    {
108
        $status = $this->getParam('status');
109
        if ($status === 'BLOCKED') {
110
            return true;
111
        }
112
113
        return false;
114
    }
115
116
    /**
117
     * @return bool
118
     */
119
    protected function isEnrolled()
120
    {
121
        $status = $this->getParam('status');
122
        if ($status === 'ENROLLED') {
123
            return true;
124
        }
125
126
        return false;
127
    }
128
129
    /**
130
     * @return bool
131
     */
132
    protected function isError()
133
    {
134
        $status = $this->getParam('status');
135
        if ($status === 'ERROR') {
136
            return true;
137
        }
138
139
        return false;
140
    }
141
142
    /**
143
     * @return bool
144
     */
145
    protected function isOk()
146
    {
147
        $status = $this->getParam('status');
148
        if ($status === 'OK') {
149
            return true;
150
        }
151
152
        return false;
153
    }
154
155
    /**
156
     * @param array $responseRaw
157
     */
158
    protected function setParams($responseRaw)
159
    {
160
        $this->params = $responseRaw;
161
    }
162
163
    /**
164
     * @return array
165
     */
166
    protected function getParams()
167
    {
168
        return $this->params;
169
    }
170
171
    /**
172
     * @param $key
173
     * @return mixed
174
     */
175
    protected function getParam($key)
176
    {
177
        if (is_array($this->params) and array_key_exists($key, $this->params)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
178
            return $this->params[$key];
179
        }
180
        else
181
        {
182
            return null;
183
        }
184
    }
185
}
186