Complex classes like Payone_Api_Response_Abstract often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Payone_Api_Response_Abstract, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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()) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param array $data |
||
| 57 | */ |
||
| 58 | public function init(array $data = array()) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @return array |
||
| 71 | */ |
||
| 72 | public function toArray() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | public function __toString() |
||
| 94 | |||
| 95 | public function getRawResponseToString() |
||
| 99 | |||
| 100 | protected function _toString($aValue) |
||
| 112 | |||
| 113 | |||
| 114 | /** |
||
| 115 | * @return bool |
||
| 116 | */ |
||
| 117 | public function isApproved() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @return bool |
||
| 128 | */ |
||
| 129 | public function isPending() |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @return bool |
||
| 140 | */ |
||
| 141 | public function isRedirect() |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return bool |
||
| 152 | */ |
||
| 153 | public function isValid() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return bool |
||
| 164 | */ |
||
| 165 | public function isInvalid() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @return bool |
||
| 176 | */ |
||
| 177 | public function isBlocked() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return bool |
||
| 188 | */ |
||
| 189 | public function isEnrolled() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return bool |
||
| 200 | */ |
||
| 201 | public function isError() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * @param string $status |
||
| 212 | */ |
||
| 213 | public function setStatus($status) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * @return string |
||
| 220 | */ |
||
| 221 | public function getStatus() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * @param string $key |
||
| 228 | * @return null|mixed |
||
| 229 | */ |
||
| 230 | public function getValue($key) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @param string $key |
||
| 237 | * @param string $name |
||
| 238 | * @return boolean|null |
||
| 239 | */ |
||
| 240 | public function setValue($key, $name) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @param $name |
||
| 247 | * @return null|mixed |
||
| 248 | */ |
||
| 249 | protected function get($name) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @param string $name |
||
| 260 | * @param mixed $value |
||
| 261 | * @return boolean|null |
||
| 262 | */ |
||
| 263 | protected function set($name, $value) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param $rawResponse |
||
| 275 | */ |
||
| 276 | public function setRawResponse($rawResponse) |
||
| 280 | /** |
||
| 281 | * @return null |
||
| 282 | */ |
||
| 283 | public function getRawResponse() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @param Payone_Protocol_Service_ApplyFilters $applyFilters |
||
| 290 | */ |
||
| 291 | public function setApplyFilters(Payone_Protocol_Service_ApplyFilters $applyFilters) |
||
| 295 | } |
||
| 296 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.