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

AuthnetWebhooksResponse   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 184
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 37
dl 0
loc 184
ccs 46
cts 46
cp 1
rs 10
c 0
b 0
f 0
wmc 18

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 3 1
A getNotificationHistory() 0 9 3
A getWebhooksId() 0 3 1
A getDeliveryStatus() 0 3 1
A __toString() 0 11 1
A getNotificationId() 0 3 1
A __construct() 0 5 2
A getStatus() 0 3 1
A getEventTypes() 0 11 3
A getEventDate() 0 3 1
A getEventType() 0 3 1
A getWebhooks() 0 7 2
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 "AuthnetWebhooksResponse.php" doesn't match the expected filename "authnetwebhooksresponse.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 Webhooks 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 AuthnetWebhooksResponse
27
{
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration for class AuthnetWebhooksResponse
Loading history...
28
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
29
     * @var object  SimpleXML object representing the API response
30
     */
31
    private $response;
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 "response" must contain a leading underscore
Loading history...
Coding Style introduced by
Private member variable "response" must be prefixed with an underscore
Loading history...
32
33
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
34
     * @var string  JSON string that is the response sent by Authorize.Net
35
     */
36
    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...
37
38
    /**
39
     * Creates the response object with the response json returned from the API call
40
     *
41
     * @param  string $responseJson Response from Authorize.Net
0 ignored issues
show
introduced by
Parameter comment must end with a full stop
Loading history...
42
     * @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...
43
     */
44 2
    public function __construct(string $responseJson)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
45
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
46 2
        $this->responseJson = $responseJson;
47 2
        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...
48 1
            throw new AuthnetInvalidJsonException('Invalid JSON returned by the API');
49
        }
50 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...
51
52
    /**
53
     * Outputs the response JSON in a human readable format
54
     *
55
     * @return string  HTML table containing debugging information
56
     */
57 1
    public function __toString()
58
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
59 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...
60 1
        $output .= '<caption>Authorize.Net Webhook 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...
61 1
        $output .= '<tr><th colspan="2"><b>Webhook 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...
62 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...
63 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...
64 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...
65 1
        $output .= '</table>';
66
67 1
        return $output;
68
    }
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...
69
70
    /**
71
     * Gets a response variable from the API response
72
     *
73
     * net.authorize.customer.created
0 ignored issues
show
Coding Style introduced by
Doc comment long description must start with a capital letter
Loading history...
74
     * net.authorize.customer.deleted
75
     * net.authorize.customer.updated
76
     * net.authorize.customer.paymentProfile.created
77
     * net.authorize.customer.paymentProfile.deleted
78
     * net.authorize.customer.paymentProfile.updated
79
     * net.authorize.customer.subscription.cancelled
80
     * net.authorize.customer.subscription.created
81
     * net.authorize.customer.subscription.expiring
82
     * net.authorize.customer.subscription.suspended
83
     * net.authorize.customer.subscription.terminated
84
     * net.authorize.customer.subscription.updated
85
     * net.authorize.payment.authcapture.created
86
     * net.authorize.payment.authorization.created
87
     * net.authorize.payment.capture.created
88
     * net.authorize.payment.fraud.approved
89
     * net.authorize.payment.fraud.declined
90
     * net.authorize.payment.fraud.held
91
     * net.authorize.payment.priorAuthCapture.created
92
     * net.authorize.payment.refund.created
93
     * net.authorize.payment.void.created
94
     *
95
     * @return array   Array of event types supported by Webhooks API
96
     */
97 2
    public function getEventTypes(): array
98
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
99 2
        $events = [];
100 2
        if (isset($this->response->eventTypes)) {
101 1
            foreach ($this->response->eventTypes as $event) {
102 1
                $events[] = $event;
103
            }
104
        } else {
105 1
            $events = array_column($this->response, 'name');
0 ignored issues
show
Bug introduced by
$this->response of type object is incompatible with the type array expected by parameter $input of array_column(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

105
            $events = array_column(/** @scrutinizer ignore-type */ $this->response, 'name');
Loading history...
106
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
107 2
        return $events;
108
    }
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...
109
110
    /**
111
     * Gets the webhooks ID
112
     *
113
     * @return string  Webhooks ID
114
     */
115 1
    public function getWebhooksId(): string
116
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
117 1
        return $this->response->webhookId;
118
    }
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 getWebhooksId()
Loading history...
119
120
    /**
121
     * Gets the status of the Webhooks
122
     *
123
     * @return string  Status of the webhooks [active|inactive]
124
     */
125 1
    public function getStatus(): string
126
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
127 1
        return $this->response->status;
128
    }
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 getStatus()
Loading history...
129
130
    /**
131
     * Gets the URL the Webhooks API will use for these Webhooks
132
     *
133
     * @return string
134
     */
135 1
    public function getUrl(): string
136
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
137 1
        return $this->response->url;
138
    }
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 getUrl()
Loading history...
139
140
    /**
141
     * Gets a list of webhooks
142
     *
143
     * @return array
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(): array
147
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
148 1
        $webhooks = [];
149 1
        foreach ($this->response as $webhook) {
150 1
            $webhooks[] = new AuthnetWebhooksResponse(json_encode($webhook));
151
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
152 1
        return $webhooks;
153
    }
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...
154
155
    /**
156
     * Gets a list of webhooks
157
     *
158
     * @return array
159
     * @throws AuthnetInvalidJsonException
0 ignored issues
show
introduced by
Comment missing for @throws tag in function comment
Loading history...
160
     */
161 1
    public function getNotificationHistory(): array
162
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
163 1
        $notifications = [];
164 1
        if (count($this->response->notifications)) {
165 1
            foreach ($this->response->notifications as $notification) {
166 1
                $notifications[] = new AuthnetWebhooksResponse(json_encode($notification));
167
            }
168
        }
0 ignored issues
show
Coding Style introduced by
No blank line found after control structure
Loading history...
169 1
        return $notifications;
170
    }
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...
171
172
    /**
173
     * Gets the notification ID of a notification
174
     *
175
     * @return string
176
     */
177 1
    public function getNotificationId(): string
178
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
179 1
        return $this->response->notificationId;
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 getNotificationId()
Loading history...
181
182
    /**
183
     * Gets the delivery status of a notification
184
     *
185
     * @return string
186
     */
187 1
    public function getDeliveryStatus(): string
188
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
189 1
        return $this->response->deliveryStatus;
190
    }
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 getDeliveryStatus()
Loading history...
191
192
    /**
193
     * Gets the event type of a notification
194
     *
195
     * @return string
196
     */
197 1
    public function getEventType(): string
198
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
199 1
        return $this->response->eventType;
200
    }
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 getEventType()
Loading history...
201
202
    /**
203
     * Gets the event date of a notification
204
     *
205
     * @return string
206
     */
207 1
    public function getEventDate(): string
208
    {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
209 1
        return $this->response->eventDate;
210
    }
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 getEventDate()
Loading history...
211
}
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...
212