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

CardException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 62
rs 10
wmc 4
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 2
A getDeclineCode() 0 4 1
A setDeclineCode() 0 6 1
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