Result::getRawResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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