Result   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 60
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
getErrorMessageByErrorCode() 0 1 ?
processResponse() 0 1 ?
A __construct() 0 5 1
A isSuccess() 0 3 1
A getErrorCode() 0 6 2
A getErrorMessage() 0 3 1
A getRawResponse() 0 3 1
1
<?php
2
/**
3
 * @author Threema GmbH
4
 * @copyright Copyright (c) 2015-2016 Threema GmbH
5
 */
6
7
8
namespace Threema\MsgApi\Commands\Results;
9
10
abstract class Result {
11
	/**
12
	 * @var int
13
	 */
14
	private $httpCode;
15
16
	/**
17
	 * @var string
18
	 */
19
	private $response;
20
21
	/**
22
	 * @param int $httpCode
23
	 * @param $response
24
	 */
25
	public function __construct($httpCode, $response) {
26
		$this->httpCode = $httpCode;
27
		$this->processResponse($response);
28
		$this->response = $response;
29
	}
30
31
	final public function isSuccess() {
32
		return $this->httpCode == 200;
33
	}
34
35
	/**
36
	 * @return null|int
37
	 */
38
	final public function getErrorCode() {
39
		if(false === $this->isSuccess()) {
40
			return $this->httpCode;
41
		}
42
		return null;
43
	}
44
45
	/**
46
	 * @return string
47
	 */
48
	final public function getErrorMessage() {
49
		return $this->getErrorMessageByErrorCode($this->getErrorCode());
50
	}
51
52
	/**
53
	 * @return string
54
	 */
55
	final public function getRawResponse() {
56
		return $this->response;
57
	}
58
59
	/**
60
	 * @param int $httpCode
61
	 * @return string
62
	 */
63
	abstract protected function getErrorMessageByErrorCode($httpCode);
64
65
	/**
66
	 * @param string $response
67
	 */
68
	abstract protected function processResponse($response);
69
}
70