Completed
Push — master ( 955097...f4414e )
by Jan
08:34
created

OneClickEchoRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
eloc 27
dl 0
loc 46
ccs 20
cts 20
cp 1
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 31 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway\Call\OneClick;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Call\PaymentResponse;
8
use SlevomatCsobGateway\Call\ResultCode;
9
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
10
11
class OneClickEchoRequest
12
{
13
14
	/** @var string */
15
	private $merchantId;
16
17
	/** @var string */
18
	private $origPayId;
19
20 2
	public function __construct(string $merchantId, string $origPayId)
21
	{
22 2
		$this->merchantId = $merchantId;
23 2
		$this->origPayId = $origPayId;
24 2
	}
25
26 1
	public function send(ApiClient $apiClient): PaymentResponse
27
	{
28
		$requestData = [
29 1
			'merchantId' => $this->merchantId,
30 1
			'origPayId' => $this->origPayId,
31
		];
32
33 1
		$response = $apiClient->post(
34 1
			'oneclick/echo',
35
			$requestData,
36 1
			new SignatureDataFormatter([
37 1
				'merchantId' => null,
38
				'origPayId' => null,
39
				'dttm' => null,
40
			]),
41 1
			new SignatureDataFormatter([
42 1
				'origPayId' => null,
43
				'dttm' => null,
44
				'resultCode' => null,
45
				'resultMessage' => null,
46
			])
47
		);
48
49 1
		$data = $response->getData();
50
51 1
		return new PaymentResponse(
52 1
			$data['origPayId'],
53 1
			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

53
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
54 1
			ResultCode::get($data['resultCode']),
55 1
			$data['resultMessage'],
56 1
			null
57
		);
58
	}
59
60
}
61