Completed
Pull Request — master (#29)
by ARCANEDEV
17:52
created

StripeException::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 2
b 0
f 0
nc 1
nop 8
dl 0
loc 22
ccs 4
cts 4
cp 1
crap 2
rs 9.2

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 namespace Arcanedev\Stripe\Bases;
2
3
use Exception;
4
5
/**
6
 * Class     StripeException
7
 *
8
 * @package  Arcanedev\Stripe\Bases
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
abstract class StripeException extends Exception
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Properties
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Stripe Error type.
19
     *
20
     * @var string|null
21
     */
22
    protected $type;
23
24
    /**
25
     * Stripe Error code.
26
     *
27
     * @var string|null
28
     */
29
    protected $stripeCode;
30
31
    /**
32
     * HTTP Response Body (json).
33
     *
34
     * @var string|null
35
     */
36
    protected $httpBody;
37
38
    /**
39
     * HTTP Response Body (array).
40
     *
41
     * @var array|null
42
     */
43
    protected $jsonBody;
44
45
    /**
46
     * Parameters.
47
     *
48
     * @var array
49
     */
50
    protected $params = [];
51
52
    /**
53
     * Headers.
54
     *
55
     * @var array
56
     */
57
    protected $headers;
58
59
    /**
60
     * Request ID.
61
     *
62
     * @var string
63
     */
64
    protected $requestId;
65 279
66
    /* ------------------------------------------------------------------------------------------------
67
     |  Constructor
68
     | ------------------------------------------------------------------------------------------------
69
     */
70
    /**
71
     * Create Stripe Exception instance.
72
     *
73
     * @param  string       $message
74 279
     * @param  int          $code
75
     * @param  string|null  $type
76
     * @param  string|null  $stripeCode
77
     * @param  string|null  $httpBody
78 279
     * @param  array        $jsonBody
79 279
     * @param  array        $params
80 279
     * @param  array        $headers
81 279
     */
82 279
    public function __construct(
83 279
        $message,
84
        $code = 0,
85
        $type = null,
86
        $stripeCode = null,
87
        $httpBody = null,
88
        $jsonBody = [],
89
        $params = [],
90
        $headers = []
91
    ) {
92
        parent::__construct($message, $code);
93
94 5
        // Stripe Properties
95
        //--------------------------------------
96 5
        $this->setType($type);
97
        $this->setStripeCode($stripeCode);
98
        $this->setHttpBody($httpBody);
99
        $this->setJsonBody($jsonBody);
100
        $this->setParams($params);
101
        $this->setHeaders($headers);
102
        $this->setRequestId(isset($headers['Request-Id']) ? $headers['Request-Id'] : null);
103
    }
104
105
    /* ------------------------------------------------------------------------------------------------
106 279
     |  Getters & Setters
107
     | ------------------------------------------------------------------------------------------------
108 279
     */
109
    /**
110 279
     * Get Stripe Error type.
111
     *
112
     * @return string
113
     */
114
    public function getType()
115
    {
116
        return $this->type;
117
    }
118 5
119
    /**
120 5
     * Set Type.
121
     *
122
     * @param  string|null  $type
123
     *
124
     * @return self
125
     */
126
    private function setType($type)
127
    {
128
        $this->type = $type;
129
130 279
        return $this;
131
    }
132 279
133
    /**
134 279
     * Get Stripe code.
135
     *
136
     * @return string|null
137
     */
138
    public function getStripeCode()
139
    {
140
        return $this->stripeCode;
141
    }
142 5
143
    /**
144 5
     * Set Stripe code.
145
     *
146
     * @param  string|null  $stripeCode
147
     *
148
     * @return self
149
     */
150
    private function setStripeCode($stripeCode)
151
    {
152 5
        $this->stripeCode = $stripeCode;
153
154 5
        return $this;
155
    }
156
157
    /**
158
     * Get HTTP status code.
159
     *
160
     * @return int
161
     */
162
    public function getHttpStatus()
163
    {
164 279
        return $this->getCode();
165
    }
166 279
167
    /**
168 279
     * Get HTTP Body.
169
     *
170
     * @return string|null
171
     */
172
    public function getHttpBody()
173
    {
174
        return $this->httpBody;
175
    }
176 5
177
    /**
178 5
     * Set HTTP Body.
179
     *
180
     * @param  string|null  $httpBody
181
     *
182
     * @return self
183
     */
184
    private function setHttpBody($httpBody)
185
    {
186
        $this->httpBody = $httpBody;
187
188 279
        return $this;
189
    }
190 279
191
    /**
192 279
     * Get Json Body.
193
     *
194
     * @return array|null
195
     */
196
    public function getJsonBody()
197
    {
198
        return $this->jsonBody;
199
    }
200 5
201
    /**
202 5
     * Set Json Body.
203
     *
204
     * @param  array|null  $jsonBody
205
     *
206
     * @return self
207
     */
208
    private function setJsonBody($jsonBody)
209
    {
210
        $this->jsonBody = $jsonBody;
211
212 279
        return $this;
213
    }
214 279
215
    /**
216 279
     * Get Parameters.
217
     *
218
     * @return array
219
     */
220
    public function getParams()
221
    {
222
        return $this->params;
223
    }
224
225
    /**
226
     * Set parameters.
227
     *
228
     * @param  array  $params
229
     *
230
     * @return self
231
     */
232
    private function setParams($params)
233
    {
234
        $this->params = $params;
235
236
        return $this;
237
    }
238
239
    public function getHeaders()
240
    {
241
        return $this->headers;
242
    }
243
244
    private function setHeaders($headers)
245
    {
246
        $this->headers = $headers;
247
248
        return $this;
249
    }
250
251
    /**
252
     * Get the Request ID.
253
     *
254
     * @return string|null
255
     */
256
    public function getRequestId()
257
    {
258
        return $this->requestId;
259
    }
260
261
    /**
262
     * Set the Request ID.
263
     *
264
     * @param  string  $requestId
265
     *
266
     * @return $this
267
     */
268
    private function setRequestId($requestId)
269
    {
270
        $this->requestId = $requestId;
271
272
        return $this;
273
    }
274
}
275