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

CardException::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 1
nop 8
dl 0
loc 21
rs 9.3142

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