ResponseCode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 96.15%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 79
ccs 25
cts 26
cp 0.9615
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A isSuccess() 0 7 2
A getErrorMessage() 0 4 1
A toJson() 0 4 1
A toArray() 0 13 1
1
<?php
2
3
namespace PHPieces\ANZGateway\models;
4
5
use PHPieces\ANZGateway\enums\FormFields\ResponseCodeFields;
6
use PHPieces\ANZGateway\enums\TransactionResponseCode;
7
8
class ResponseCode extends Model
9
{
10
    protected static $fields = ResponseCodeFields::class;
11
12
    /**
13
     * A response code that is generated by the Payment Server to indicate the status of the transaction.
14
     * vpc_TxnResponseCode
15
     * A vpc_TxnResponseCode of “0” (zero) indicates that the transaction was processed successfully and
16
     * approved by the acquiring bank. Any other value indicates the transaction was declined.
17
     *
18
     * Required
19
     *
20
     * @var int
21
     */
22
    private $txnResponseCode;
23
24
    /**
25
     * Human readable message for the error code.
26
     * @var String
27
     */
28
    private $message;
29
30
    /**
31
     * The subsequent fields are relevant to the card provider.
32
     * If the card could not be charged then the txnResponseCode will show that there was an error,
33
     * These fields are kept for posterity.
34
     * @var String
35
     */
36
    private $AVSResultCode;
37
    private $acqAVSRespCode;
38
    private $acqCSCRespCode;
39
    private $acqResponseCode;
40
    private $CSCResultCode;
41
42 15
    public function __construct($txnResponseCode, $message, $AVSResultCode = '', $acqAVSRespCode
43
    = '', $acqCSCRespCode = '', $acqResponseCode = '', $CSCResultCode = '')
44
    {
45 15
        $this->txnResponseCode = (int) $txnResponseCode;
46 15
        $this->message = (string) $message;
47 15
        $this->AVSResultCode = $AVSResultCode;
48 15
        $this->acqAVSRespCode = $acqAVSRespCode;
49 15
        $this->acqCSCRespCode = $acqCSCRespCode;
50 15
        $this->acqResponseCode = $acqResponseCode;
51 15
        $this->CSCResultCode = $CSCResultCode;
52
//        $this->validate();
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53 15
    }
54
55 3
    public function isSuccess() : bool
56
    {
57 3
        if ($this->txnResponseCode !== TransactionResponseCode::TRANSACTION_APPROVED) {
58
            return false;
59
        }
60 3
        return true;
61
    }
62
63 6
    public function getErrorMessage() : string
64
    {
65 6
        return TransactionResponseCode::MESSAGE[$this->txnResponseCode].", ".$this->message;
66
    }
67
68 3
    public function toJson() : string
69
    {
70 3
        return json_encode($this->toArray());
71
    }
72
73 3
    public function toArray() : array
74
    {
75
        return [
76 3
            'AVSResultCode'     => $this->AVSResultCode,
77 3
            'acqAVSRespCode'    => $this->acqAVSRespCode,
78 3
            'acqCSCRespCode'    => $this->acqCSCRespCode,
79 3
            'acqResponseCode'   => $this->acqResponseCode,
80 3
            'CSCResultCode'     => $this->CSCResultCode,
81 3
            'txnResponseCode'   => $this->txnResponseCode,
82 3
            'message'           => $this->message,
83 3
            'formatted_message' => $this->getErrorMessage()
84
        ];
85
    }
86
}
87