Completed
Pull Request — master (#16)
by Josef
02:45
created

RequestFactory::createInitPayment()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 32

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 32
nc 1
nop 14
dl 0
loc 35
rs 8.8571
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway;
4
5
use SlevomatCsobGateway\Api\HttpMethod;
6
use SlevomatCsobGateway\Call\ClosePaymentRequest;
7
use SlevomatCsobGateway\Call\CustomerInfoRequest;
8
use SlevomatCsobGateway\Call\EchoRequest;
9
use SlevomatCsobGateway\Call\InitPaymentRequest;
10
use SlevomatCsobGateway\Call\OneclickInitPaymentRequest;
11
use SlevomatCsobGateway\Call\OneclickStartPaymentRequest;
12
use SlevomatCsobGateway\Call\PaymentStatusRequest;
13
use SlevomatCsobGateway\Call\PayMethod;
14
use SlevomatCsobGateway\Call\PayOperation;
15
use SlevomatCsobGateway\Call\PostEchoRequest;
16
use SlevomatCsobGateway\Call\ProcessPaymentRequest;
17
use SlevomatCsobGateway\Call\ReceivePaymentRequest;
18
use SlevomatCsobGateway\Call\RefundPaymentRequest;
19
use SlevomatCsobGateway\Call\ReversePaymentRequest;
20
21
class RequestFactory
22
{
23
24
	/**
25
	 * @var string
26
	 */
27
	private $merchantId;
28
29
	public function __construct(string $merchantId)
30
	{
31
		$this->merchantId = $merchantId;
32
	}
33
34
	public function createInitPayment(
35
		string $orderId,
36
		PayOperation $payOperation,
37
		PayMethod $payMethod,
38
		bool $closePayment,
39
		string $returnUrl,
40
		HttpMethod $returnMethod,
41
		Cart $cart,
42
		string $description,
43
		string $merchantData = null,
44
		string $customerId = null,
45
		Language $language,
46
		int $ttlSec = null,
47
		int $logoVersion = null,
48
		int $colorSchemeVersion = null
49
	): InitPaymentRequest
50
	{
51
		return new InitPaymentRequest(
52
			$this->merchantId,
53
			$orderId,
54
			$payOperation,
55
			$payMethod,
56
			$closePayment,
57
			$returnUrl,
58
			$returnMethod,
59
			$cart,
60
			$description,
61
			$merchantData,
62
			$customerId,
63
			$language,
64
			$ttlSec,
65
			$logoVersion,
66
			$colorSchemeVersion
67
		);
68
	}
69
70
	public function createProcessPayment(string $payId): ProcessPaymentRequest
71
	{
72
		return new ProcessPaymentRequest(
73
			$this->merchantId,
74
			$payId
75
		);
76
	}
77
78
	public function createPaymentStatus(string $payId): PaymentStatusRequest
79
	{
80
		return new PaymentStatusRequest(
81
			$this->merchantId,
82
			$payId
83
		);
84
	}
85
86
	public function createReversePayment(string $payId): ReversePaymentRequest
87
	{
88
		return new ReversePaymentRequest(
89
			$this->merchantId,
90
			$payId
91
		);
92
	}
93
94
	public function createClosePayment(string $payId): ClosePaymentRequest
95
	{
96
		return new ClosePaymentRequest(
97
			$this->merchantId,
98
			$payId
99
		);
100
	}
101
102
	public function createRefundPayment(string $payId, int $amount = null): RefundPaymentRequest
103
	{
104
		return new RefundPaymentRequest(
105
			$this->merchantId,
106
			$payId,
107
			$amount
108
		);
109
	}
110
111
	public function createEchoRequest(): EchoRequest
112
	{
113
		return new EchoRequest(
114
			$this->merchantId
115
		);
116
	}
117
118
	public function createPostEchoRequest(): PostEchoRequest
119
	{
120
		return new PostEchoRequest(
121
			$this->merchantId
122
		);
123
	}
124
125
	public function createCustomerInfo(string $customerId): CustomerInfoRequest
126
	{
127
		return new CustomerInfoRequest(
128
			$this->merchantId,
129
			$customerId
130
		);
131
	}
132
133
	public function createReceivePaymentRequest(): ReceivePaymentRequest
134
	{
135
		return new ReceivePaymentRequest();
136
	}
137
138
	public function createOneclickInitPayment(
139
		string $origPayId,
140
		string $orderId,
141
		Price $price = null,
142
		string $description = null
143
	): OneclickInitPaymentRequest
144
	{
145
		return new OneclickInitPaymentRequest(
146
			$this->merchantId,
147
			$origPayId,
148
			$orderId,
149
			$price,
150
			$description
151
		);
152
	}
153
154
	public function createOneclickStartPayment(string $payId): OneclickStartPaymentRequest
155
	{
156
		return new OneclickStartPaymentRequest(
157
			$this->merchantId,
158
			$payId
159
		);
160
	}
161
162
}
163