TransactionSettlementExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 8
c 1
b 0
f 1
dl 0
loc 31
rs 10
ccs 9
cts 11
cp 0.8182
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSignatureDataFormatter() 0 3 1
A parseSettlementDate() 0 3 1
A createResponse() 0 6 3
A parseAuthDate() 0 3 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\Extension;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Call\ResponseExtensionHandler;
7
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
8
use function array_flip;
9
10
class TransactionSettlementExtension implements ResponseExtensionHandler
11
{
12
13
	public const NAME = 'trxDates';
14
15
	/**
16
	 * @param mixed[] $data
17
	 * @return TransactionSettlementResponse
18
	 */
19 1
	public function createResponse(array $data): TransactionSettlementResponse
20
	{
21 1
		return new TransactionSettlementResponse(
22 1
			new DateTimeImmutable($data['createdDate']),
23 1
			isset($data['authDate']) ? $this->parseAuthDate($data['authDate']) : null,
24 1
			isset($data['settlementDate']) ? $this->parseSettlementDate($data['settlementDate']) : null
25
		);
26
	}
27
28
	public function getSignatureDataFormatter(): SignatureDataFormatter
29
	{
30
		return new SignatureDataFormatter(array_flip(['extension', 'dttm', 'createdDate', 'authDate', 'settlementDate']));
31
	}
32
33 1
	private function parseAuthDate(string $authDate): DateTimeImmutable
34
	{
35 1
		return DateTimeImmutable::createFromFormat('ymdHis', $authDate);
0 ignored issues
show
Bug Best Practice introduced by
The expression return DateTimeImmutable...at('ymdHis', $authDate) could return the type false which is incompatible with the type-hinted return DateTimeImmutable. Consider adding an additional type-check to rule them out.
Loading history...
36
	}
37
38 1
	private function parseSettlementDate(string $settlementDate): DateTimeImmutable
39
	{
40 1
		return DateTimeImmutable::createFromFormat('Ymd', $settlementDate)->setTime(0, 0, 0);
0 ignored issues
show
Bug Best Practice introduced by
The expression return DateTimeImmutable...Date)->setTime(0, 0, 0) could return the type false which is incompatible with the type-hinted return DateTimeImmutable. Consider adding an additional type-check to rule them out.
Loading history...
41
	}
42
43
}
44