ReceivePaymentRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 38
rs 10
ccs 16
cts 16
cp 1
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B send() 0 30 7
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
8
use function array_key_exists;
9
use function base64_decode;
10
use function is_numeric;
11
12
class ReceivePaymentRequest
13
{
14
15
	/**
16
	 * @param ApiClient $apiClient
17
	 * @param mixed[] $data
18
	 * @return PaymentResponse
19
	 */
20 2
	public function send(ApiClient $apiClient, array $data): PaymentResponse
21
	{
22 2
		if (array_key_exists('resultCode', $data) && is_numeric($data['resultCode'])) {
23 2
			$data['resultCode'] = (int) $data['resultCode'];
24
		}
25
26 2
		if (array_key_exists('paymentStatus', $data) && is_numeric($data['paymentStatus'])) {
27 2
			$data['paymentStatus'] = (int) $data['paymentStatus'];
28
		}
29
30 2
		$response = $apiClient->createResponseByData($data, new SignatureDataFormatter([
31 2
			'payId' => null,
32
			'dttm' => null,
33
			'resultCode' => null,
34
			'resultMessage' => null,
35
			'paymentStatus' => null,
36
			'authCode' => null,
37
			'merchantData' => null,
38
		]));
39
40 2
		$data = $response->getData();
41
42 2
		return new PaymentResponse(
43 2
			$data['payId'],
44 2
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
0 ignored issues
show
Bug introduced by
It seems like DateTimeImmutable::creat...YmdHis', $data['dttm']) can also be of type false; however, parameter $responseDateTime of SlevomatCsobGateway\Call...Response::__construct() does only seem to accept DateTimeImmutable, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
45 2
			ResultCode::get($data['resultCode']),
46 2
			$data['resultMessage'],
47 2
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
48 2
			$data['authCode'] ?? null,
49 2
			isset($data['merchantData']) ? (string) base64_decode($data['merchantData'], true) : null
50
		);
51
	}
52
53
}
54