Passed
Pull Request — master (#39)
by Jan
08:36
created

PaymentButtonResponse::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 8

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\Call\Button;
4
5
use DateTimeImmutable;
6
use SlevomatCsobGateway\Api\HttpMethod;
7
use SlevomatCsobGateway\Call\PaymentStatus;
8
use SlevomatCsobGateway\Call\ResultCode;
9
use SlevomatCsobGateway\Validator;
10
11
class PaymentButtonResponse
12
{
13
14
	/** @var string */
15
	private $payId;
16
17
	/** @var DateTimeImmutable */
18
	private $responseDateTime;
19
20
	/** @var ResultCode */
21
	private $resultCode;
22
23
	/** @var string */
24
	private $resultMessage;
25
26
	/** @var PaymentStatus|null */
27
	private $paymentStatus;
28
29
	/** @var \SlevomatCsobGateway\Api\HttpMethod|null */
30
	private $redirectMethod;
31
32
	/** @var string|null */
33
	private $redirectUrl;
34
35
	/** @var mixed[]|null */
36
	private $redirectParams;
37
38
	/**
39
	 * @param string $payId
40
	 * @param \DateTimeImmutable $responseDateTime
41
	 * @param \SlevomatCsobGateway\Call\ResultCode $resultCode
42
	 * @param string $resultMessage
43
	 * @param \SlevomatCsobGateway\Call\PaymentStatus|null $paymentStatus
44
	 * @param \SlevomatCsobGateway\Api\HttpMethod|null $redirectMethod
45
	 * @param string|null $redirectUrl
46
	 * @param mixed[]|null $redirectParams
47
	 */
48
	public function __construct(
49
		string $payId,
50
		DateTimeImmutable $responseDateTime,
51
		ResultCode $resultCode,
52
		string $resultMessage,
53
		?PaymentStatus $paymentStatus,
54
		?HttpMethod $redirectMethod,
55
		?string $redirectUrl,
56
		?array $redirectParams
57
	)
58
	{
59
		Validator::checkPayId($payId);
60
61
		$this->payId = $payId;
62
		$this->responseDateTime = $responseDateTime;
63
		$this->resultCode = $resultCode;
64
		$this->resultMessage = $resultMessage;
65
		$this->paymentStatus = $paymentStatus;
66
		$this->redirectMethod = $redirectMethod;
67
		$this->redirectUrl = $redirectUrl;
68
		$this->redirectParams = $redirectParams;
69
	}
70
71
	public function getPayId(): string
72
	{
73
		return $this->payId;
74
	}
75
76
	public function getResponseDateTime(): DateTimeImmutable
77
	{
78
		return $this->responseDateTime;
79
	}
80
81
	public function getResultCode(): ResultCode
82
	{
83
		return $this->resultCode;
84
	}
85
86
	public function getResultMessage(): string
87
	{
88
		return $this->resultMessage;
89
	}
90
91
	public function getPaymentStatus(): ?PaymentStatus
92
	{
93
		return $this->paymentStatus;
94
	}
95
96
	public function getRedirectMethod(): ?HttpMethod
97
	{
98
		return $this->redirectMethod;
99
	}
100
101
	public function getRedirectUrl(): ?string
102
	{
103
		return $this->redirectUrl;
104
	}
105
106
	/**
107
	 * @return mixed[]|null
108
	 */
109
	public function getRedirectParams(): ?array
110
	{
111
		return $this->redirectParams;
112
	}
113
114
}
115