Completed
Pull Request — master (#60)
by ARCANEDEV
08:31
created

CardException::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 13
nc 1
nop 8
dl 0
loc 21
ccs 6
cts 6
cp 1
crap 2
rs 9.3142
c 0
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 namespace Arcanedev\Stripe\Exceptions;
2
3
/**
4
 * Class     CardException
5
 *
6
 * @package  Arcanedev\Stripe\Exceptions
7
 * @author   ARCANEDEV <[email protected]>
8
 */
9
class CardException extends StripeException
10
{
11
    /* ------------------------------------------------------------------------------------------------
12
     |  Properties
13
     | ------------------------------------------------------------------------------------------------
14
     */
15
    protected $declineCode;
16
17
    /* ------------------------------------------------------------------------------------------------
18
     |  Constructor
19
     | ------------------------------------------------------------------------------------------------
20
     */
21
    /**
22
     * CardException constructor.
23
     *
24
     * @param  string       $message
25
     * @param  int          $code
26
     * @param  string|null  $type
27
     * @param  string|null  $stripeCode
28
     * @param  string|null  $httpBody
29
     * @param  array        $jsonBody
30
     * @param  array        $params
31
     * @param  array        $headers
32
     */
33 8
    public function __construct(
34
        $message,
35
        $code,
36
        $type,
37
        $stripeCode,
38
        $httpBody,
39
        array $jsonBody,
40
        array $params = [],
41
        array $headers = []
42
    ) {
43 8
        parent::__construct(
44 8
            $message, $code, $type, $stripeCode, $httpBody, $jsonBody, $params, $headers
45
        );
46
47
        // This one is not like the others because it was added later and we're trying to do our best
48
        // not to change the public interface of this class' constructor.
49
        // We should consider changing its implementation on the next major version bump of this library.
50 8
        $this->setDeclineCode(
51 8
            isset($jsonBody['error']['decline_code']) ? $jsonBody['error']['decline_code'] : null
52
        );
53 8
    }
54
55
    /* ------------------------------------------------------------------------------------------------
56
     |  Getters & Setters
57
     | ------------------------------------------------------------------------------------------------
58
     */
59
    public function getDeclineCode()
60
    {
61
        return $this->declineCode;
62
    }
63
64 8
    private function setDeclineCode($declineCode)
65
    {
66 8
        $this->declineCode = $declineCode;
67
68 8
        return $this;
69
    }
70
}
71