ErrorResponse::getException()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace HelePartnerSyncApi\Response;
4
5
use Exception;
6
use HelePartnerSyncApi\Exception as HeleException;
7
use Throwable;
8
9
class ErrorResponse extends Response
10
{
11
12
	/**
13
	 * @var Exception|Throwable
14
	 */
15
	private $exception;
16
17
	/**
18
	 * @param string $secret
19
	 * @param Exception|Throwable $exception
20
	 */
21
	public function __construct($secret, $exception)
22
	{
23
		parent::__construct($secret);
24
		$this->exception = $exception;
25
	}
26
27
	/**
28
	 * @return null
29
	 */
30
	public function getData()
31
	{
32
		return null;
33
	}
34
35
	/**
36
	 * @return bool
37
	 */
38
	public function isSuccessful()
39
	{
40
		return false;
41
	}
42
43
	/**
44
	 * @return int
45
	 */
46
	public function getHttpCode()
47
	{
48
		return $this->exception instanceof HeleException ? 422 : 500;
49
	}
50
51
	/**
52
	 * @return string
53
	 */
54
	public function getMessage()
55
	{
56
		if ($this->exception instanceof HeleException) {
57
			return $this->exception->getMessage();
58
		}
59
60
		return 'Internal server error';
61
	}
62
63
	/**
64
	 * @return Exception|Throwable
65
	 */
66
	public function getException()
67
	{
68
		return $this->exception;
69
	}
70
71
}
72