Passed
Branch php72 (829d0c)
by John
03:36
created

AuthnetWebhooksRequest   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 310
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 77
dl 0
loc 310
ccs 79
cts 79
cp 1
rs 10
c 0
b 0
f 0
wmc 20

18 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteWebhook() 0 5 1
A updateWebhook() 0 12 1
A testWebhook() 0 6 1
A post() 0 4 1
A get() 0 4 1
A getRawRequest() 0 3 1
A getWebhook() 0 5 1
A __toString() 0 17 2
A delete() 0 4 1
A put() 0 4 1
A getByUrl() 0 4 1
A handleResponse() 0 9 2
A __construct() 0 3 1
A createWebhooks() 0 12 1
A getEventTypes() 0 5 1
A getWebhooks() 0 5 1
A getNotificationHistory() 0 11 1
A setProcessHandler() 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 "AuthnetWebhooksRequest.php" doesn't match the expected filename "authnetwebhooksrequest.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
use Authnetjson\Exception\AuthnetCurlException;
17
use Authnetjson\Exception\AuthnetInvalidJsonException;
18
use Curl\Curl;
19
20
/**
21
 * Creates a request to the Authorize.Net Webhooks endpoints
22
 *
23
 * @package   AuthnetJSON
24
 * @author    John Conde <[email protected]>
25
 * @copyright John Conde <[email protected]>
26
 * @license   http://www.apache.org/licenses/LICENSE-2.0.html Apache License, Version 2.0
27
 * @link      https://github.com/stymiee/authnetjson
28
 * @see       https://developer.authorize.net/api/reference/features/webhooks.html
29
 */
30
class AuthnetWebhooksRequest
31
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class AuthnetWebhooksRequest
Loading history...
32
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
33
     * @var string  Base URL for processing a webhook
34
     */
35
    private $url;
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 "url" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "url" must be prefixed with an underscore
Loading history...
36
37
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
38
     * @var string  Endpoint for processing a webhook
39
     */
40
    private $endpoint;
0 ignored issues
show
Coding Style introduced by
Private member variable "endpoint" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "endpoint" must be prefixed with an underscore
Loading history...
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
     * @var string  JSON formatted API request
44
     */
45
    private $requestJson;
0 ignored issues
show
Coding Style introduced by
Private member variable "requestJson" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "requestJson" must be prefixed with an underscore
Loading history...
46
47
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
48
     * @var object  Wrapper object representing an endpoint
49
     */
50
    private $processor;
0 ignored issues
show
Coding Style introduced by
Private member variable "processor" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "processor" must be prefixed with an underscore
Loading history...
51
52
    /**
53
     * Creates the request object by setting the Authorize.Net credentials and URL of the endpoint to be used
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...
54
     * for the API call
55
     *
56
     * @param string $api_url URL endpoint for processing a transaction
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
57
     */
58 1
    public function __construct(string $api_url)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
Coding Style introduced by
Variable "api_url" is not in valid camel caps format
Loading history...
59
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
60 1
        $this->url = $api_url;
0 ignored issues
show
Coding Style introduced by
Variable "api_url" is not in valid camel caps format
Loading history...
61 1
    }
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...
62
63
    /**
64
     * Outputs the account credentials, endpoint URL, and request JSON in a human readable format
65
     *
66
     * @return string  HTML table containing debugging information
67
     */
68 2
    public function __toString(): string
69
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
70 2
        $output  = '<table id="authnet-request">'."\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...
71 2
        $output .= '<caption>Authorize.Net Request</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...
72 2
        $output .= '<tr><th colspan="2"><b>Class Parameters</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...
73 2
        $output .= '<tr><td><b>Authnet Server URL</b></td><td>'.$this->url.'</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...
74 2
        $output .= '<tr><th colspan="2"><b>Request 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...
75 2
        if (!empty($this->requestJson)) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
76 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...
77 1
            $output .= $this->requestJson."\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...
78 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...
79
        } else {
80 1
            $output .= '<tr><td colspan="2" style="text-align: center;"><pre>N/A</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...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 103 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
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
82 2
        $output .= '</table>';
83
84 2
        return $output;
85
    }
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...
86
87
    /**
88
     * Creates a new webhook
89
     *
90
     * @param  array  $webhooks   Array of webhooks to be created or modified
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
91
     * @param  string $webhookUrl URL of where webhook notifications will be sent
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
92
     * @param  string $status     Status of webhooks to be created or modified [active/inactive]
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
93
     * @return AuthnetWebhooksResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
94
     * @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...
95
     * @throws AuthnetCurlException
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...
96
     */
97 1
    public function createWebhooks(array $webhooks, string $webhookUrl, string $status = 'active'): object
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$status" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$status"; expected 0 but found 1
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 106 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...
98
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
99 1
        $this->endpoint = 'webhooks';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
100 1
        $this->url = sprintf('%s%s', $this->url, $this->endpoint);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
101
        $request = [
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
102 1
            'url'        => $webhookUrl,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 20 spaces, but found 12.
Loading history...
103 1
            'eventTypes' => $webhooks,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 20 spaces, but found 12.
Loading history...
104 1
            'status'     => $status
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 20 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
105
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 19 space(s), but found 8.
Loading history...
106 1
        $this->requestJson = json_encode($request);
107 1
        $response = $this->post($this->url, $this->requestJson);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
108 1
        return new AuthnetWebhooksResponse($response);
109
    }
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 createWebhooks()
Loading history...
110
111
    /**
112
     * Sends a test ping to a URL for (a) designated webhook(s)
113
     *
114
     * @param  string $webhookId Webhook ID to be tested
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
115
     * @throws AuthnetCurlException
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...
116
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
117 1
    public function testWebhook(string $webhookId): void
118
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
119 1
        $this->endpoint = 'webhooks';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
120 1
        $this->url = sprintf('%s%s/%s/pings', $this->url, $this->endpoint, $webhookId);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
121 1
        $this->requestJson = json_encode([]);
122 1
        $this->post($this->url, $this->requestJson);
123 1
    }
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 testWebhook()
Loading history...
124
125
    /**
126
     * Gets all of the available event types
127
     *
128
     * @return AuthnetWebhooksResponse
129
     * @throws AuthnetCurlException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
130
     * @throws AuthnetInvalidJsonException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
131
     */
132 1
    public function getEventTypes(): object
133
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
134 1
        $this->endpoint = 'eventtypes';
135 1
        $this->url = sprintf('%s%s', $this->url, $this->endpoint);
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...
136 1
        return $this->getByUrl($this->url);
137
    }
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 getEventTypes()
Loading history...
138
139
    /**
140
     * List all of your webhooks
141
     *
142
     * @return AuthnetWebhooksResponse
143
     * @throws AuthnetCurlException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
144
     * @throws AuthnetInvalidJsonException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
145
     */
146 1
    public function getWebhooks(): object
147
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
148 1
        $this->endpoint = 'webhooks';
149 1
        $this->url = sprintf('%s%s', $this->url, $this->endpoint);
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...
150 1
        return $this->getByUrl($this->url);
151
    }
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 getWebhooks()
Loading history...
152
153
    /**
154
     * Get a webhook
155
     *
156
     * @param  string $webhookId Webhook ID to be retrieved
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
157
     * @return AuthnetWebhooksResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
158
     * @throws AuthnetCurlException
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...
159
     * @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...
160
     */
161 1
    public function getWebhook(string $webhookId): object
162
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
163 1
        $this->endpoint = 'webhooks';
164 1
        $this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
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...
165 1
        return $this->getByUrl($this->url);
166
    }
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 getWebhook()
Loading history...
167
168
    /**
169
     * GET API request
170
     *
171
     * @param  string $url API endpoint to hit
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
172
     * @return object
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
173
     * @throws AuthnetCurlException
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...
174
     * @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...
175
     */
176 3
    private function getByUrl(string $url): object
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetWebhooksRequest::getByUrl" must be prefixed with an underscore
Loading history...
177
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
178 3
        $response = $this->get($url);
179 3
        return new AuthnetWebhooksResponse($response);
180
    }
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 getByUrl()
Loading history...
181
182
    /**
183
     * Updates webhook event types
184
     *
185
     * @param  string $webhookId  Webhook ID to be modified
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
186
     * @param  string $webhookUrl URL of where webhook notifications will be sent
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
187
     * @param  array  $eventTypes Array of event types to be added/removed
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
188
     * @param  string $status     Status of webhooks to be modified [active/inactive]
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
189
     * @return AuthnetWebhooksResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
190
     * @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...
191
     * @throws AuthnetCurlException
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...
192
     */
193 1
    public function updateWebhook(string $webhookId, string $webhookUrl, array $eventTypes, string $status = 'active'): object
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$status" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$status"; expected 0 but found 1
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 126 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...
194
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
195 1
        $this->endpoint = 'webhooks';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
196 1
        $this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
197
        $request = [
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
198 1
            'url'        => $webhookUrl,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 20 spaces, but found 12.
Loading history...
199 1
            'eventTypes' => $eventTypes,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 20 spaces, but found 12.
Loading history...
200 1
            'status'     => $status
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 20 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
201
        ];
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 19 space(s), but found 8.
Loading history...
202 1
        $this->requestJson = json_encode($request);
203 1
        $response = $this->put($this->url, $this->requestJson);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
204 1
        return new AuthnetWebhooksResponse($response);
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 updateWebhook()
Loading history...
206
207
    /**
208
     * Delete a webhook
209
     *
210
     * @param  string $webhookId Webhook ID to be deleted
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
211
     * @throws AuthnetCurlException
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...
212
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
213 1
    public function deleteWebhook(string $webhookId): void
214
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
215 1
        $this->endpoint = 'webhooks';
216 1
        $this->url = sprintf('%s%s/%s', $this->url, $this->endpoint, $webhookId);
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...
217 1
        $this->delete($this->url);
218 1
    }
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 deleteWebhook()
Loading history...
219
220
    /**
221
     * Retrieve Notification History
222
     *
223
     * @param  int $limit  Default: 1000
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
224
     * @param  int $offset Default: 0
0 ignored issues
show
Coding Style introduced by
Expected "integer" but found "int" for parameter type
Loading history...
introduced by
Parameter comment must end with a full stop
Loading history...
225
     * @return AuthnetWebhooksResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
226
     * @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...
227
     * @throws AuthnetCurlException
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...
228
     */
229 1
    public function getNotificationHistory(int $limit = 1000, int $offset = 0): object
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$limit" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$limit"; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$offset" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$offset"; expected 0 but found 1
Loading history...
230
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
231 1
        $this->endpoint = 'notifications';
232 1
        $this->url = sprintf('%s%s', $this->url, $this->endpoint);
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...
233 1
        $response = $this->get(
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
234 1
            $this->url, [
235 1
            'offset' => $offset,
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 25 spaces, but found 12.
Loading history...
236 1
            'limit'  => $limit
0 ignored issues
show
Coding Style introduced by
This array key does not seem to be aligned correctly; expected 25 spaces, but found 12.
Loading history...
Coding Style introduced by
Each line in an array declaration must end in a comma
Loading history...
237
            ]
0 ignored issues
show
Coding Style introduced by
The closing parenthesis does not seem to be aligned correctly; expected 24 space(s), but found 12.
Loading history...
238
        );
239 1
        return new AuthnetWebhooksResponse($response);
240
    }
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 getNotificationHistory()
Loading history...
241
242
    /**
243
     * Tells the handler to make the API call to Authorize.Net
244
     *
245
     * @return string
246
     * @throws AuthnetCurlException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
247
     */
248 4
    private function handleResponse(): string
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetWebhooksRequest::handleResponse" must be prefixed with an underscore
Loading history...
249
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
250 4
        if (!$this->processor->error) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after NOT operator; 0 found
Loading history...
251 1
            return $this->processor->response;
252
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
253 3
        $response = json_decode($this->processor->response, false);
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...
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...
254 3
        $error_message = sprintf('(%u) %s: %s', $response->status, $response->reason, $response->message);
0 ignored issues
show
Coding Style introduced by
Variable "error_message" is not in valid camel caps format
Loading history...
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 106 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...
255
256 3
        throw new AuthnetCurlException(sprintf('Connection error: %s', $error_message));
0 ignored issues
show
Coding Style introduced by
Variable "error_message" is not in valid camel caps format
Loading history...
257
    }
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 handleResponse()
Loading history...
258
259
    /**
260
     * Make GET request via Curl
261
     *
262
     * @param  string $url
0 ignored issues
show
Documentation introduced by
Missing parameter comment
Loading history...
263
     * @param  array  $params
0 ignored issues
show
Documentation introduced by
Missing parameter comment
Loading history...
264
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
265
     * @throws AuthnetCurlException
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...
266
     *
267
     * @codeCoverageIgnore
268
     */
269
    private function get(string $url, array $params = []): string
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetWebhooksRequest::get" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Incorrect spacing between argument "$params" and equals sign; expected 0 but found 1
Loading history...
Coding Style introduced by
Incorrect spacing between default value and equals sign for argument "$params"; expected 0 but found 1
Loading history...
270
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
271
        $this->processor->get($url, $params);
272
        return $this->handleResponse();
273
    }
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...
274
275
    /**
276
     * Make POST request via Curl
277
     *
278
     * @param  string $url     API endpoint
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
279
     * @param  string $request JSON request payload
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
280
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
281
     * @throws AuthnetCurlException
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...
282
     *
283
     * @codeCoverageIgnore
284
     */
285
    private function post(string $url, string $request): string
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetWebhooksRequest::post" must be prefixed with an underscore
Loading history...
286
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
287
        $this->processor->post($url, $request);
288
        return $this->handleResponse();
289
    }
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 post()
Loading history...
290
291
    /**
292
     * Make PUT request via Curl
293
     *
294
     * @param  string $url     API endpoint
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
295
     * @param  string $request JSON request payload
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
296
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
297
     * @throws AuthnetCurlException
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...
298
     *
299
     * @codeCoverageIgnore
300
     */
301
    private function put(string $url, string $request): string
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetWebhooksRequest::put" must be prefixed with an underscore
Loading history...
302
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
303
        $this->processor->put($url, $request, true);
0 ignored issues
show
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...
304
        return $this->handleResponse();
305
    }
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 put()
Loading history...
306
307
    /**
308
     * Make DELETE request via Curl
309
     *
310
     * @param  string $url API endpoint
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
311
     * @return string
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
312
     * @throws AuthnetCurlException
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...
313
     *
314
     * @codeCoverageIgnore
315
     */
316
    private function delete(string $url): string
0 ignored issues
show
Coding Style introduced by
Private method name "AuthnetWebhooksRequest::delete" must be prefixed with an underscore
Loading history...
317
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
318
        $this->processor->delete($url, [], true);
0 ignored issues
show
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...
319
        return $this->handleResponse();
320
    }
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 delete()
Loading history...
321
322
    /**
323
     * Sets the handler to be used to handle our API call. Mainly used for unit testing as Curl is used by default.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 100 characters; contains 115 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...
324
     *
325
     * @param Curl $processor
0 ignored issues
show
Documentation introduced by
Missing parameter comment
Loading history...
326
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
327 1
    public function setProcessHandler(Curl $processor): void
328
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
329 1
        $this->processor = $processor;
330 1
    }
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 setProcessHandler()
Loading history...
331
332
    /**
333
     * Gets the request sent to Authorize.Net in JSON format for logging purposes
334
     *
335
     * @return string transaction request sent to Authorize.Net in JSON format
336
     */
337 1
    public function getRawRequest(): string
338
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
339 1
        return $this->requestJson;
340
    }
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 getRawRequest()
Loading history...
341
}
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...
342