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

CardException::setDeclineCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
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