Completed
Push — master ( bc3f33...99b627 )
by Josef
03:38
created

ClosePaymentRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 96%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 74
loc 74
ccs 24
cts 25
cp 0.96
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
B send() 41 41 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 SlevomatCsobGateway\Validator;
9
10 View Code Duplication
class ClosePaymentRequest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
{
12
13
	/**
14
	 * @var string
15
	 */
16
	private $merchantId;
17
18
	/**
19
	 * @var string
20
	 */
21
	private $payId;
22
23
	/**
24
	 * @var int|null
25
	 */
26
	private $totalAmount;
27
28 2
	public function __construct(
29
		string $merchantId,
30
		string $payId,
31
		int $totalAmount = null
32
	)
33
	{
34 2
		Validator::checkPayId($payId);
35
36 2
		$this->merchantId = $merchantId;
37 2
		$this->payId = $payId;
38 2
		$this->totalAmount = $totalAmount;
39 2
	}
40
41 1
	public function send(ApiClient $apiClient): PaymentResponse
42
	{
43
		$data = [
44 1
			'merchantId' => $this->merchantId,
45 1
			'payId' => $this->payId,
46
		];
47
48 1
		if ($this->totalAmount !== null) {
49
			$data['totalAmount'] = $this->totalAmount;
50
		}
51
52 1
		$response = $apiClient->put(
53 1
			'payment/close',
54
			$data,
55 1
			new SignatureDataFormatter([
56 1
				'merchantId' => null,
57
				'payId' => null,
58
				'dttm' => null,
59
				'totalAmount' => null,
60
			]),
61 1
			new SignatureDataFormatter([
62 1
				'payId' => null,
63
				'dttm' => null,
64
				'resultCode' => null,
65
				'resultMessage' => null,
66
				'paymentStatus' => null,
67
				'authCode' => null,
68
			])
69
		);
70
71 1
		$data = $response->getData();
72
73 1
		return new PaymentResponse(
74 1
			$data['payId'],
75 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
76 1
			new ResultCode($data['resultCode']),
77 1
			$data['resultMessage'],
78 1
			isset($data['paymentStatus']) ? new PaymentStatus($data['paymentStatus']) : null,
79 1
			$data['authCode'] ?? null
80
		);
81
	}
82
83
}
84