Completed
Push — master ( 60aec0...f632bc )
by Andreas
12:47 queued 10:41
created

Response::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1.0008

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 9
cts 10
cp 0.9
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 17
nc 1
nop 8
crap 1.0008

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
2
3
namespace Larium\Pay;
4
5
class Response
6
{
7
    /**
8
     * @var bool
9
     */
10
    private $success;
11
12
    /**
13
     * @var string
14
     */
15
    private $message;
16
17
    /**
18
     * @var string
19
     */
20
    private $transactionId;
21
22
    /**
23
     * @var string|int
24
     */
25
    private $errorCode;
26
27
    /**
28
     * @var string
29
     */
30
    private $responseCode;
31
32
    /**
33
     * @var array
34
     */
35
    private $payload;
36
37
    /**
38
     * @var string
39
     */
40
    private $rawRequest;
41
42
    /**
43
     * @var string
44
     */
45
    private $rawResponse;
46
47
    /**
48
     * @param bool $success
49
     * @param string $message
50
     * @param string $transactionId
51
     * @param string $errorCode
52
     * @param string $responseCode
53
     * @param array $payload
54
     * @param string $rawRequest
55
     * @param string $rawResponse
56
     */
57 1
    public function __construct(
58
        $success,
59
        $message,
60
        $transactionId,
61
        $errorCode = '0',
62
        $responseCode = '00',
63
        array $payload = [],
64
        $rawResponse = null,
65
        $rawRequest = null
66
    ) {
67 1
        $this->success = $success;
68 1
        $this->message = $message;
69 1
        $this->transactionId = $transactionId;
70 1
        $this->errorCode = $errorCode;
71 1
        $this->responseCode = $responseCode;
72 1
        $this->payload = $payload;
73 1
        $this->rawRequest = $rawRequest;
74 1
        $this->rawResponse = $rawResponse;
75
    }
76
77
    /**
78
     * Returns whether response is success or not.
79
     *
80
     * @return bool
81
     */
82
    public function isSuccess()
83
    {
84
        return $this->success;
85
    }
86
87
    /**
88
     * Returns the unique transaction id from gateway.
89
     *
90
     * @return string
91
     */
92
    public function getTransactionId()
93
    {
94
        return $this->transactionId;
95
    }
96
97
    /**
98
     * Returns the error code from gateway, if exists.
99
     *
100
     * @return string|int
101
     */
102
    public function getErrorCode()
103
    {
104
        return $this->errorCode;
105
    }
106
107
    /**
108
     * Returns a human readable message for current transaction response,
109
     * either on success or failed transactions.
110
     *
111
     * @return string
112
     */
113
    public function getMessage()
114
    {
115
        return $this->message;
116
    }
117
118
    /**
119
     * Returns the credit card response code from gateway, if exits.
120
     *
121
     * This must be the {@link [https://en.wikipedia.org/wiki/ISO_8583#Response_code][ISO 8583]} ISO 8583 response code.
122
     *
123
     * @return string
124
     */
125
    public function getResponseCode()
126
    {
127
        return $this->responseCode;
128
    }
129
130
    /**
131
     * Returns any gateway response element as an associative array.
132
     * Array may contain nested elements.
133
     *
134
     * @return array
135
     */
136
    public function getPayload()
137
    {
138
        return $this->payload;
139
    }
140
141
    public function getRawRequest()
142
    {
143
        return $this->rawRequest;
144
    }
145
146
    public function getRawResponse()
147
    {
148
        return $this->rawResponse;
149
    }
150
}
151