Completed
Pull Request — master (#11)
by
unknown
10:03
created

EvidenceResponse::getXml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatEET;
4
5
class EvidenceResponse
6
{
7
8
	/** @var SoapClient */
9
	private $soapClient;
10
11
	/** @var \stdClass */
12
	private $rawData;
13
14
	/** @var string|null */
15
	private $uuid;
16
17
	/** @var string|null */
18
	private $bkp;
19
20
	/** @var bool */
21
	private $test;
22
23
	/** @var string|null */
24
	private $fik;
25
26
	/** @var \DateTimeImmutable */
27
	private $responseTime;
28
29 2
	/** @var \SlevomatEET\EvidenceRequest */
30
	private $evidenceRequest;
31 2
32 2
	public function __construct(SoapClient $soapClient, \stdClass $rawData, EvidenceRequest $evidenceRequest)
33 2
	{
34 1
		$this->soapClient = $soapClient;
35
		$this->rawData = $rawData;
36 2
		$this->uuid = $rawData->Hlavicka->uuid_zpravy ?? null;
37 2
		if (isset($rawData->Potvrzeni)) {
38 2
			$this->fik = $rawData->Potvrzeni->fik;
39 2
		}
40 2
		$this->bkp = $rawData->Hlavicka->bkp ?? null;
41
		$this->test = $rawData->Potvrzeni->test ?? $rawData->Chyba->test ?? false;
42 2
		$this->responseTime = \DateTimeImmutable::createFromFormat(\DateTime::ISO8601, $rawData->Hlavicka->dat_prij ?? $rawData->Hlavicka->dat_odmit);
43
		$this->evidenceRequest = $evidenceRequest;
44 2
	}
45 1
46
	public function getFik(): string
47
	{
48 1
		if (!$this->isValid()) {
49
			throw new InvalidResponseWithoutFikException($this);
50
		}
51
52
		return $this->fik;
53
	}
54
55
	public function getRawData(): \stdClass
56
	{
57
		return $this->rawData;
58
	}
59
60
	/**
61
	 * @return string|null
62
	 */
63
	public function getUuid()
64
	{
65
		return $this->uuid;
66
	}
67
68
	/**
69
	 * @return string|null
70
	 */
71
	public function getBkp()
72 2
	{
73
		return $this->bkp;
74 2
	}
75
76
	public function isTest(): bool
77 2
	{
78
		return $this->test;
79 2
	}
80
81
	public function isValid(): bool
82
	{
83
		return $this->fik !== null;
84
	}
85
86
	public function getResponseTime(): \DateTimeImmutable
87
	{
88
		return $this->responseTime;
89
	}
90
91
	public function getRequest(): EvidenceRequest
92
	{
93
		return $this->evidenceRequest;
94
	}
95
96
	public function getXml()
97
	{
98
		return $this->soapClient->__getLastResponse();
99
	}
100
}
101