EvidenceRequest::getBody()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
ccs 2
cts 2
cp 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatEET;
4
5
use DateTimeImmutable;
6
use SlevomatEET\Cryptography\CryptographyService;
7
8
class EvidenceRequest
9
{
10
11
	/** @var DateTimeImmutable */
12
	private $sendDate;
13
14
	/** @var mixed[] */
15
	private $header;
16
17
	/** @var mixed[] */
18
	private $body;
19
20
	/** @var string */
21
	private $pkpCode;
22
23
	/** @var string */
24
	private $bkpCode;
25
26 4
	public function __construct(Receipt $receipt, Configuration $configuration, CryptographyService $cryptographyService)
27
	{
28 4
		$this->sendDate = new DateTimeImmutable();
29 4
		$this->header = [
0 ignored issues
show
Documentation Bug introduced by
It seems like array('uuid_zpravy' => $...->isVerificationMode()) of type array<string,string|bool...","overeni":"boolean"}> is incompatible with the declared type array<integer,*> of property $header.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30 4
			'uuid_zpravy' => $receipt->getUuid()->toString(),
31 4
			'dat_odesl' => Formatter::formatDateTime($this->sendDate),
32 4
			'prvni_zaslani' => $receipt->isFirstSend(),
33 4
			'overeni' => $configuration->isVerificationMode(),
34
		];
35
36
		$body = [
37 4
			'dic_popl' => $configuration->getVatId(),
38 4
			'dic_poverujiciho' => $receipt->getDelegatedVatId(),
39 4
			'id_provoz' => $configuration->getPremiseId(),
40 4
			'id_pokl' => $configuration->getCashRegisterId(),
41 4
			'porad_cis' => $receipt->getReceiptNumber(),
42 4
			'dat_trzby' => Formatter::formatDateTime($receipt->getReceiptTime()),
43 4
			'celk_trzba' => Formatter::formatAmount($receipt->getTotalPrice()),
44 4
			'zakl_nepodl_dph' => Formatter::formatAmount($receipt->getPriceZeroVat()),
45 4
			'zakl_dan1' => Formatter::formatAmount($receipt->getPriceStandardVat()),
46 4
			'dan1' => Formatter::formatAmount($receipt->getVatStandard()),
47 4
			'zakl_dan2' => Formatter::formatAmount($receipt->getPriceFirstReducedVat()),
48 4
			'dan2' => Formatter::formatAmount($receipt->getVatFirstReduced()),
49 4
			'zakl_dan3' => Formatter::formatAmount($receipt->getPriceSecondReducedVat()),
50 4
			'dan3' => Formatter::formatAmount($receipt->getVatSecondReduced()),
51 4
			'cest_sluz' => Formatter::formatAmount($receipt->getPriceTravelService()),
52 4
			'pouzit_zboz1' => Formatter::formatAmount($receipt->getPriceUsedGoodsStandardVat()),
53 4
			'pouzit_zboz2' => Formatter::formatAmount($receipt->getPriceUsedGoodsFirstReducedVat()),
54 4
			'pouzit_zboz3' => Formatter::formatAmount($receipt->getPriceUsedGoodsSecondReducedVat()),
55 4
			'urceno_cerp_zuct' => Formatter::formatAmount($receipt->getPriceForSubsequentSettlement()),
56 4
			'cerp_zuct' => Formatter::formatAmount($receipt->getPriceUsedSubsequentSettlement()),
57 4
			'rezim' => $configuration->getEvidenceMode()->getValue(),
58
		];
59
		$this->body = array_filter($body, static function ($value): bool {
60 4
			return $value !== null;
61 4
		});
62
63 4
		$this->pkpCode = $cryptographyService->getPkpCode($this->body);
64 4
		$this->bkpCode = $cryptographyService->getBkpCode($this->pkpCode);
65 4
	}
66
67
	/**
68
	 * @return mixed[]
69
	 */
70 4
	public function getRequestData(): array
71
	{
72
		return [
73 4
			'Hlavicka' => $this->header,
74 4
			'Data' => $this->body,
75
			'KontrolniKody' => [
76
				'pkp' => [
77 4
					'_' => $this->pkpCode,
78 4
					'digest' => 'SHA256',
79 4
					'cipher' => 'RSA2048',
80 4
					'encoding' => 'base64',
81
				],
82
				'bkp' => [
83 4
					'_' => $this->bkpCode,
84 4
					'digest' => 'SHA1',
85 4
					'encoding' => 'base16',
86
				],
87
			],
88
		];
89
	}
90
91 1
	public function getSendDate(): DateTimeImmutable
92
	{
93 1
		return $this->sendDate;
94
	}
95
96
	/**
97
	 * @return mixed[]
98
	 */
99 1
	public function getHeader(): array
100
	{
101 1
		return $this->header;
102
	}
103
104
	/**
105
	 * @return mixed[]
106
	 */
107 1
	public function getBody(): array
108
	{
109 1
		return $this->body;
110
	}
111
112 1
	public function getPkpCode(): string
113
	{
114 1
		return $this->pkpCode;
115
	}
116
117 2
	public function getBkpCode(): string
118
	{
119 2
		return $this->bkpCode;
120
	}
121
122
}
123