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

AuthnetJsonResponse   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 248
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 56
dl 0
loc 248
ccs 60
cts 60
cp 1
rs 10
c 0
b 0
f 0
wmc 29

16 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 11 1
A getError() 0 11 3
A getTransactionResponses() 0 3 1
A isApproved() 0 3 2
A checkTransactionStatus() 0 8 2
A __get() 0 3 1
A getErrorText() 0 3 1
A isPrePaidCard() 0 3 1
A isDeclined() 0 3 2
A getRawResponse() 0 3 1
B __construct() 0 16 8
A isError() 0 3 1
A getErrorCode() 0 3 1
A getTransactionResponseField() 0 6 2
A isSuccessful() 0 3 1
A getErrorMessage() 0 3 1
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 "AuthnetJsonResponse.php" doesn't match the expected filename "authnetjsonresponse.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
 * @property object  $messages
27
 * @property string  $directResponse
28
 * @property string  $validationDirectResponseList
29
 * @property object  $transactionResponse
30
 *
31
 * @method null createTransactionRequest(array $array)                                 process a payment
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...
32
 * @method null sendCustomerTransactionReceiptRequest(array $array)                    get a list of unsettled transactions
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 123 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...
33
 * @method null ARBCancelSubscriptionRequest(array $array)                             cancel a subscription
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...
34
 * @method null ARBCreateSubscriptionRequest(array $array)                             create a subscription
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...
35
 * @method null ARBGetSubscriptionStatusRequest(array $array)                          get a subscription's status
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...
36
 * @method null ARBUpdateSubscriptionRequest(array $array)                             update a subscription
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...
37
 * @method null createCustomerPaymentProfileRequest(array $array)                      create a payment profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 111 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...
38
 * @method null createCustomerProfileRequest(array $array)                             create a customer profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
39
 * @method null createCustomerProfileTransactionRequest_authCapture(array $array)      process an Authorization and Capture transaction (Sale)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 142 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...
40
 * @method null createCustomerProfileTransactionRequest_authOnly(array $array)         process an Authorization Only transaction
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 128 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...
41
 * @method null createCustomerProfileTransactionRequest_captureOnly(array $array)      process a Capture Only transaction
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 121 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...
42
 * @method null createCustomerProfileTransactionRequest_priorAuthCapture(array $array) process a Prior Authorization Capture transaction
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 136 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...
43
 * @method null createCustomerProfileTransactionRequest_refund(array $array)           process a Refund (credit)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
44
 * @method null createCustomerProfileTransactionRequest_void(array $array)             void a transaction
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 105 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...
45
 * @method null createCustomerShippingAddressRequest(array $array)                     create a shipping profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
46
 * @method null deleteCustomerPaymentProfileRequest(array $array)                      delete a payment profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 111 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...
47
 * @method null deleteCustomerProfileRequest(array $array)                             delete a customer profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
48
 * @method null deleteCustomerShippingAddressRequest(array $array)                     delete a shipping profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
49
 * @method null getCustomerPaymentProfileRequest(array $array)                         retrieve a payment profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 113 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...
50
 * @method null getCustomerProfileIdsRequest(array $array)                             retrieve a list of profile IDs
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 117 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...
51
 * @method null getCustomerProfileRequest(array $array)                                retrieve a customer profile
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...
52
 * @method null getCustomerShippingAddressRequest(array $array)                        retrieve a shipping address
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...
53
 * @method null getHostedProfilePageRequest(array $array)                              retrieve a hosted payment page token
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 123 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...
54
 * @method null updateCustomerPaymentProfileRequest(array $array)                      update a customer profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
55
 * @method null updateCustomerProfileRequest(array $array)                             update a customer profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
56
 * @method null updateCustomerShippingAddressRequest(array $array)                     update a shipping address
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 112 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...
57
 * @method null updateSplitTenderGroupRequest(array $array)                            update a split tender transaction
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 120 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...
58
 * @method null validateCustomerPaymentProfileRequest(array $array)                    validate a payment profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 113 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...
59
 * @method null getBatchStatisticsRequest(array $array)                                get a summary of a settled batch
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 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...
60
 * @method null getSettledBatchListRequest(array $array)                               get a list of settled batches
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 116 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...
61
 * @method null getTransactionDetailsRequest(array $array)                             get the details of a transaction
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 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...
62
 * @method null getTransactionListRequest(array $array)                                get a list of transaction in a batch
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 123 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...
63
 * @method null getUnsettledTransactionListRequest(array $array)                       get a list of unsettled transactions
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 123 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...
64
 */
65
class AuthnetJsonResponse
66
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class AuthnetJsonResponse
Loading history...
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @const Indicates the status code of an approved transaction
69
     */
70
    public const STATUS_APPROVED = 1;
71
72
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
73
     * @const Indicates the status code of an declined transaction
74
     */
75
    public const STATUS_DECLINED = 2;
76
77
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
78
     * @const Indicates the status code of an transaction which has encountered an error
79
     */
80
    public const STATUS_ERROR = 3;
81
82
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
83
     * @const Indicates the status code of a transaction held for review
84
     */
85
    public const STATUS_HELD = 4;
86
87
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
88
     * @const Indicates the status code of a transaction held for review
89
     */
90
    public const STATUS_PAYPAL_NEED_CONSENT = 5;
91
92
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
93
     * @var object  SimpleXML object representing the API response
94
     */
95
    private $response;
0 ignored issues
show
Coding Style introduced by
Private member variable "response" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "response" must be prefixed with an underscore
Loading history...
96
97
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
98
     * @var string  JSON string that is the response sent by Authorize.Net
99
     */
100
    private $responseJson;
0 ignored issues
show
Coding Style introduced by
Private member variable "responseJson" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "responseJson" must be prefixed with an underscore
Loading history...
101
102
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
103
     * @var object  TransactionResponse
104
     */
105
    private $transactionInfo;
0 ignored issues
show
Coding Style introduced by
Private member variable "transactionInfo" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "transactionInfo" must be prefixed with an underscore
Loading history...
106
107
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
108
     * @var array  TransactionResponse
109
     */
110
    private $transactionInfoArray;
0 ignored issues
show
Coding Style introduced by
Private member variable "transactionInfoArray" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "transactionInfoArray" must be prefixed with an underscore
Loading history...
111
112
    /**
113
     * Creates the response object with the response json returned from the API call
114
     *
115
     * @param  string $responseJson Response from Authorize.Net
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
116
     * @throws AuthnetInvalidJsonException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
introduced by
Comment missing for @throws tag in function comment
Loading history...
117
     */
118 4
    public function __construct(string $responseJson)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
119
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
120 4
        $this->responseJson = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $responseJson);
121 4
        if (($this->response = json_decode($this->responseJson, false)) === null) {
0 ignored issues
show
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 false please use FALSE.
Loading history...
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...
122 1
            throw new AuthnetInvalidJsonException('Invalid JSON returned by the API');
123
        }
124
125 3
        if ($this->directResponse || $this->validationDirectResponseList || isset($this->response->validationDirectResponse)) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 127 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...
126 3
            $response = $this->directResponse ?: $this->validationDirectResponseList ?: $this->response->validationDirectResponse;
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
Inline IF statements are not allowed
Loading history...
Coding Style introduced by
Inline shorthand IF statement requires brackets around comparison
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 130 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...
127 3
            if (is_array($response)) {
128
                $this->transactionInfoArray = array_map(static function ($r) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
129 1
                    return new TransactionResponse($r);
130 1
                }, $response);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
131
            } else {
132 2
                $this->transactionInfo = new TransactionResponse($response);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
133 2
                $this->transactionInfoArray = [$this->transactionInfo];
134
            }
135
        }
136 3
    }
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...
137
138
    /**
139
     * Outputs the response JSON in a human readable format
140
     *
141
     * @return string  HTML table containing debugging information
142
     */
143 1
    public function __toString()
144
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
145 1
        $output  = '<table id="authnet-response">'."\n";
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "."; 0 found
Loading history...
146 1
        $output .= '<caption>Authorize.Net Response</caption>'."\n";
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "."; 0 found
Loading history...
147 1
        $output .= '<tr><th colspan="2"><b>Response JSON</b></th></tr>'."\n";
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "."; 0 found
Loading history...
148 1
        $output .= '<tr><td colspan="2"><pre>'."\n";
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "."; 0 found
Loading history...
149 1
        $output .= $this->responseJson."\n";
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "."; 0 found
Loading history...
150 1
        $output .= '</pre></td></tr>'."\n";
0 ignored issues
show
Coding Style introduced by
Expected at least 1 space before "."; 0 found
Loading history...
Coding Style introduced by
Expected at least 1 space after "."; 0 found
Loading history...
151 1
        $output .= '</table>';
152
153 1
        return $output;
154
    }
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 __toString()
Loading history...
155
156
    /**
157
     * Gets a response variable from the API response
158
     *
159
     * @param  string $var unused
0 ignored issues
show
introduced by
Parameter comment must start with a capital letter
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
160
     * @return string requested variable from the API call response
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
161
     */
162 2
    public function __get(string $var)
163
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
164 2
        return $this->response->{$var} ?? null;
0 ignored issues
show
Coding Style introduced by
Operation must be bracketed
Loading history...
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...
165
    }
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 __get()
Loading history...
166
167
    /**
168
     * Checks if the API call is not in an error state
169
     *
170
     * @return bool    Whether the transaction was in an successful state
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
171
     */
172 2
    public function isSuccessful(): bool
173
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
174 2
        return strtolower($this->messages->resultCode) === 'ok';
175
    }
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 isSuccessful()
Loading history...
176
177
    /**
178
     * Checks if the API is reporting an error with the API call
179
     *
180
     * @return bool    Whether the transaction was in an error state
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
181
     */
182 2
    public function isError(): bool
183
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
184 2
        return strtolower($this->messages->resultCode) === 'error';
185
    }
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 isError()
Loading history...
186
187
    /**
188
     * Checks if a transaction was approved
189
     *
190
     * @return bool     true if the transaction is approved
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
191
     */
192 1
    public function isApproved(): bool
193
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
194 1
        return $this->isSuccessful() && $this->checkTransactionStatus(self::STATUS_APPROVED);
0 ignored issues
show
Coding Style introduced by
Boolean operators are not allowed outside of control structure conditions
Loading history...
195
    }
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 isApproved()
Loading history...
196
197
    /**
198
     * Checks if a transaction was completed using a prepaid card
199
     *
200
     * @return bool     true if the transaction was completed using a prepaid card
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
201
     */
202 1
    public function isPrePaidCard(): bool
203
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
204 1
        return isset($this->transactionResponse->prePaidCard);
205
    }
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 isPrePaidCard()
Loading history...
206
207
    /**
208
     * Checks if a transaction was declined
209
     *
210
     * @return bool     true if the transaction is declined
0 ignored issues
show
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
211
     */
212 1
    public function isDeclined(): bool
213
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
214 1
        return $this->isSuccessful() && $this->checkTransactionStatus(self::STATUS_DECLINED);
0 ignored issues
show
Coding Style introduced by
Boolean operators are not allowed outside of control structure conditions
Loading history...
215
    }
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 isDeclined()
Loading history...
216
217
    /**
218
     * Check to see if the ResponseCode matches the expected value
219
     *
220
     * @param  int $status
0 ignored issues
show
Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
221
     * @return bool Check to see if the ResponseCode matches the expected value
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
Coding Style introduced by
Expected "boolean" but found "bool" for function return type
Loading history...
222
     */
223 2
    protected function checkTransactionStatus(int $status): bool
224
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
225 2
        if ($this->transactionInfo instanceof TransactionResponse) {
226 1
            $match = (int) $this->transactionInfo->getTransactionResponseField('ResponseCode') === $status;
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
A cast statement should not be followed as per the coding-style.
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 107 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...
227
        } else {
228 1
            $match = (int) $this->transactionResponse->responseCode === $status;
0 ignored issues
show
Coding Style introduced by
The value of a comparison must not be assigned to a variable
Loading history...
Coding Style introduced by
A cast statement should not be followed as per the coding-style.
Loading history...
229
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
230 2
        return $match;
231
    }
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 checkTransactionStatus()
Loading history...
232
233
    /**
234
     * Gets the transaction response field for AIM and CIM transactions.
235
     *
236
     * @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...
237
     * @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...
238
     * @throws AuthnetTransactionResponseCallException
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
introduced by
Comment missing for @throws tag in function comment
Loading history...
239
     */
240 2
    public function getTransactionResponseField($field): string
241
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
242 2
        if ($this->transactionInfo instanceof TransactionResponse) {
243 1
            return $this->transactionInfo->getTransactionResponseField($field);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->transactio...onResponseField($field) could return the type null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
244
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
245 1
        throw new AuthnetTransactionResponseCallException('This API call does not have any transaction response data');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 119 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...
246
    }
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 getTransactionResponseField()
Loading history...
247
248
    /**
249
     * Returns the results of a test charge for each payment account provided when created a customer profile
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 109 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...
250
     *
251
     * @return array
252
     */
253 1
    public function getTransactionResponses(): array
254
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
255 1
        return $this->transactionInfoArray;
256
    }
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 getTransactionResponses()
Loading history...
257
258
    /**
259
     * Gets the transaction response from Authorize.Net in JSON format for logging purposes
260
     *
261
     * @return string transaction response from Authorize.Net in JSON format
262
     */
263 1
    public function getRawResponse(): string
264
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
265 1
        return $this->responseJson;
266
    }
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 getRawResponse()
Loading history...
267
268
    /**
269
     * An alias of self::getErrorText()
270
     *
271
     * @return string Error response from Authorize.Net
272
     */
273 1
    public function getErrorMessage(): string
274
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
275 1
        return $this->getErrorText();
276
    }
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 getErrorMessage()
Loading history...
277
278
    /**
279
     * If an error has occurred, returns the error message
280
     *
281
     * @return string Error response from Authorize.Net
282
     */
283 2
    public function getErrorText(): string
284
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
285 2
        return $this->getError('text');
286
    }
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 getErrorText()
Loading history...
287
288
    /**
289
     * If an error has occurred, returns the error message
290
     *
291
     * @return string Error response from Authorize.Net
292
     */
293 2
    public function getErrorCode(): string
294
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
295 2
        return $this->getError('code');
296
    }
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 getErrorCode()
Loading history...
297
298
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
299
     * @param  string $type Whether to get the error code or text
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
300
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
301
     */
302 2
    private function getError(string $type): string
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetJsonResponse::getError" must be prefixed with an underscore
Loading history...
303
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
304 2
        $msg = '';
305 2
        if ($this->isError()) {
306 2
            $prop = sprintf('error%s', ucfirst($type));
307 2
            $msg = $this->messages->message[0]->{$type};
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
308 2
            if (@$this->transactionResponse->errors[0]->{$prop}) {
0 ignored issues
show
Coding Style introduced by
Silencing errors is discouraged; found: @$this->transactionResponse...
Loading history...
309 1
                $msg = $this->transactionResponse->errors[0]->{$prop};
310
            }
311
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
312 2
        return $msg;
313
    }
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 getError()
Loading history...
314
}
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...
315