Completed
Pull Request — master (#32)
by Jan
03:24
created

BasicFinishRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 71
Duplicated Lines 49.3 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 35
loc 71
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
B send() 35 35 2

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\Masterpass;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\ApiClient;
7
use SlevomatCsobGateway\Call\PaymentResponse;
8
use SlevomatCsobGateway\Call\PaymentStatus;
9
use SlevomatCsobGateway\Call\ResultCode;
10
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
11
use SlevomatCsobGateway\Validator;
12
13
class BasicFinishRequest
14
{
15
16
	/**
17
	 * @var string
18
	 */
19
	private $merchantId;
20
21
	/**
22
	 * @var string
23
	 */
24
	private $payId;
25
26
	/** @var mixed[] */
27
	private $callbackParams;
28
29
	/**
30
	 * @param string $merchantId
31
	 * @param string $payId
32
	 * @param mixed[] $callbackParams
33
	 */
34 1
	public function __construct(
35
		string $merchantId,
36
		string $payId,
37
		array $callbackParams
38
	)
39
	{
40 1
		Validator::checkPayId($payId);
41
42 1
		$this->merchantId = $merchantId;
43 1
		$this->payId = $payId;
44 1
		$this->callbackParams = $callbackParams;
45 1
	}
46
47 1 View Code Duplication
	public function send(ApiClient $apiClient): PaymentResponse
0 ignored issues
show
Duplication introduced by
This method 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...
48
	{
49
		$requestData = [
50 1
			'merchantId' => $this->merchantId,
51 1
			'payId' => $this->payId,
52 1
			'callbackParams' => $this->callbackParams,
53
		];
54
55 1
		$response = $apiClient->post(
56 1
			'masterpass/basic/finish',
57 1
			$requestData,
58 1
			new SignatureDataFormatter([
59 1
				'merchantId' => null,
60
				'payId' => null,
61
				'callbackParams' => null,
62
			]),
63 1
			new SignatureDataFormatter([
64 1
				'payId' => null,
65
				'dttm' => null,
66
				'resultCode' => null,
67
				'resultMessage' => null,
68
				'paymentStatus' => null,
69
			])
70
		);
71
72 1
		$data = $response->getData();
73
74 1
		return new PaymentResponse(
75 1
			$data['payId'],
76 1
			DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
77 1
			ResultCode::get($data['resultCode']),
78 1
			$data['resultMessage'],
79 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null
80
		);
81
	}
82
83
}
84