Passed
Push — master ( 85716f...d04990 )
by John
05:03 queued 10s
created

TransactionResponse::getTransactionResponseField()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 1
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style introduced by
Class found in ".php" file; use ".inc" extension instead
Loading history...
Coding Style introduced by
The PHP open tag does not have a corresponding PHP close tag
Loading history...
Coding Style introduced by
Filename "TransactionResponse.php" doesn't match the expected filename "transactionresponse.php"
Loading history...
2
3
declare(strict_types=1);
4
5
/**
0 ignored issues
show
Coding Style introduced by
Block comments must be started with /*
Loading history...
6
 * This file is part of the AuthnetJSON package.
7
 *
8
 * (c) John Conde <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Authnetjson;
15
16
/**
17
 * Adapter for the Authorize.Net JSON API
18
 *
19
 * @package   AuthnetJSON
20
 * @author    John Conde <[email protected]>
21
 * @copyright John Conde <[email protected]>
22
 * @license   http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0
23
 * @link      https://github.com/stymiee/authnetjson
24
 * @see       https://developer.authorize.net/api/reference/
25
 */
26
class TransactionResponse
27
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class TransactionResponse
Loading history...
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var array Transaction response fields to map to values parsed from a transaction response string
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
30
     */
31
    private static $fieldMap = [
0 ignored issues
show
Coding Style introduced by
Expected 1 blank line(s) before first member var; 0 found
Loading history...
Coding Style introduced by
Private member variable "fieldMap" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "fieldMap" must be prefixed with an underscore
Loading history...
32
        1 => 'ResponseCode',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
33
        2 => 'ResponseSubcode',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
34
        3 => 'ResponseReasonCode',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
35
        4 => 'ResponseReasonText',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
36
        5 => 'AuthorizationCode',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
37
        6 => 'AVSResponse',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
38
        7 => 'TransactionID',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
39
        8 => 'InvoiceNumber',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
40
        9 => 'Description',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Array double arrow not aligned correctly; expected 2 space(s) but found 1
Loading history...
41
        10 => 'Amount',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
42
        11 => 'Method',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
43
        12 => 'TransactionType',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
44
        13 => 'CustomerID',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
45
        14 => 'FirstName',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
46
        15 => 'LastName',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
47
        16 => 'Company',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
48
        17 => 'Address',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
49
        18 => 'City',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
50
        19 => 'State',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
51
        20 => 'ZipCode',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
52
        21 => 'Country',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
53
        22 => 'Phone',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
54
        23 => 'Fax',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
55
        24 => 'EmailAddress',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
56
        25 => 'ShipToFirstName',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
57
        26 => 'ShipToLastName',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
58
        27 => 'ShipToCompany',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
59
        28 => 'ShipToAddress',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
60
        29 => 'ShipToCity',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
61
        30 => 'ShipToState',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
62
        31 => 'ShipToZip',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
63
        32 => 'ShipToCountry',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
64
        33 => 'Tax',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
65
        34 => 'Duty',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
66
        35 => 'Freight',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
67
        36 => 'TaxExempt',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
68
        37 => 'PurchaseOrderNumber',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
69
        38 => 'MD5Hash',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
70
        39 => 'CardCodeResponse',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
71
        40 => 'CardholderAuthenticationVerificationResponse',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
72
        51 => 'AccountNumber',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
73
        52 => 'CardType',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
74
        53 => 'SplitTenderID',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
75
        54 => 'AmountRequested',
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
76
        55 => 'BalanceOnCard'
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 32 spaces, but found 8.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
77
    ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 31 space(s), but found 4.
Loading history...
78
79
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
80
     * @var array Transaction response fields to map to values parsed from a transaction response string
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 104 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
81
     */
82
    private $responseArray;
0 ignored issues
show
Coding Style introduced by
Private member variable "responseArray" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "responseArray" must be prefixed with an underscore
Loading history...
83
84
    /**
85
     * Creates out TransactionResponse object and assigns the response variables to an array
86
     *
87
     * @param string $response Comma delimited transaction response string
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
88
     */
89 2
    public function __construct(string $response)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
90
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
91 2
        $this->responseArray = array_merge([null], explode(',', $response));
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
92 2
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end __construct()
Loading history...
93
94
    /**
95
     * Gets the requested value out of the response array using the provided key. The location of that value
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 108 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
96
     * can be accessed via it's numerical location in the array (starting at zero) or using the key for that field
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 114 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
97
     * as defined by Authorize.Net and mapped in self::$fieldMap.
98
     *
99
     * @param  mixed $field Name or key of the transaction field to be retrieved
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
100
     * @return string Transaction field to be retrieved
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
101
     */
102 4
    public function getTransactionResponseField($field): ?string
103
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
104 4
        $value = null;
0 ignored issues
show
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of null please use NULL.
Loading history...
105 4
        if (is_int($field)) {
106 1
            $value = $this->responseArray[$field] ?? $value;
0 ignored issues
show
Coding Style introduced by
Operation must be bracketed
Loading history...
107 4
        } elseif ($key = array_search($field, self::$fieldMap, true)) {
0 ignored issues
show
Coding Style introduced by
Usage of ELSEIF not allowed; use ELSE IF instead
Loading history...
Coding Style introduced by
Variable assignment found within a condition. Did you mean to do a comparison ?
Loading history...
Coding Style introduced by
Assignments must be the first block of code on a line
Loading history...
Coding Style introduced by
TRUE, FALSE and NULL should be uppercase as per the configured coding-style; instead of true please use TRUE.
Loading history...
108 4
            $value = $this->responseArray[$key];
109
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
110 4
        return $value;
111
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
Coding Style introduced by
Expected 1 blank line before closing function brace; 0 found
Loading history...
Coding Style introduced by
Expected //end getTransactionResponseField()
Loading history...
112
}
0 ignored issues
show
Coding Style introduced by
Expected //end class
Loading history...
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
113