StandardExtractRequest::send()   B
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 80
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 64
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 80
rs 8.7853
ccs 18
cts 18
cp 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\PaymentStatus;
8
use SlevomatCsobGateway\Call\ResultCode;
9
use SlevomatCsobGateway\Crypto\SignatureDataFormatter;
10
use SlevomatCsobGateway\Validator;
11
12
class StandardExtractRequest
13
{
14
15
	/** @var string */
16
	private $merchantId;
17
18
	/** @var string */
19
	private $payId;
20
21
	/** @var mixed[] */
22
	private $callbackParams;
23
24
	/**
25
	 * @param string $merchantId
26
	 * @param string $payId
27
	 * @param mixed[] $callbackParams
28
	 */
29 2
	public function __construct(
30
		string $merchantId,
31
		string $payId,
32
		array $callbackParams
33
	)
34
	{
35 2
		Validator::checkPayId($payId);
36
37 2
		$this->merchantId = $merchantId;
38 2
		$this->payId = $payId;
39 2
		$this->callbackParams = $callbackParams;
40 2
	}
41
42 1
	public function send(ApiClient $apiClient): ExtractResponse
43
	{
44
		$requestData = [
45 1
			'merchantId' => $this->merchantId,
46 1
			'payId' => $this->payId,
47 1
			'callbackParams' => $this->callbackParams,
48
		];
49
50 1
		$response = $apiClient->post(
51 1
			'masterpass/standard/extract',
52
			$requestData,
53 1
			new SignatureDataFormatter([
54 1
				'merchantId' => null,
55
				'payId' => null,
56
				'dttm' => null,
57
				'callbackParams' => [
58
					'mpstatus' => null,
59
					'oauthToken' => null,
60
					'checkoutResourceUrl' => null,
61
					'oauthVerifier' => null,
62
				],
63
			]),
64 1
			new SignatureDataFormatter([
65 1
				'payId' => null,
66
				'dttm' => null,
67
				'resultCode' => null,
68
				'resultMessage' => null,
69
				'paymentStatus' => null,
70
				'checkoutParams' => [
71
					'card' => [
72
						'maskedCln' => null,
73
						'expiration' => null,
74
						'billingAddress' => [
75
							'city' => null,
76
							'country' => null,
77
							'countrySubdivision' => null,
78
							'line1' => null,
79
							'line2' => null,
80
							'line3' => null,
81
							'postalCode' => null,
82
						],
83
					],
84
					'shippingAddress' => [
85
						'recipientName' => null,
86
						'recipientPhoneNumber' => null,
87
						'city' => null,
88
						'country' => null,
89
						'countrySubdivision' => null,
90
						'line1' => null,
91
						'line2' => null,
92
						'line3' => null,
93
						'postalCode' => null,
94
					],
95
					'contact' => [
96
						'firstName' => null,
97
						'middleName' => null,
98
						'lastName' => null,
99
						'country' => null,
100
						'emailAddress' => null,
101
						'phoneNumber' => null,
102
					],
103
					'rewardProgram' => [
104
						'rewardNumber' => null,
105
						'rewardId' => null,
106
						'rewardName' => null,
107
						'expiration' => null,
108
					],
109
				],
110
			])
111
		);
112
113 1
		$data = $response->getData();
114
115 1
		return new ExtractResponse(
116 1
			$data['payId'],
117 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

117
			/** @scrutinizer ignore-type */ DateTimeImmutable::createFromFormat('YmdHis', $data['dttm']),
Loading history...
118 1
			ResultCode::get($data['resultCode']),
119 1
			$data['resultMessage'],
120 1
			isset($data['paymentStatus']) ? PaymentStatus::get($data['paymentStatus']) : null,
121 1
			$data['checkoutParams'] ?? null
122
		);
123
	}
124
125
}
126