Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 29 | class AuthnetWebhooksResponse |
||
| 30 | { |
||
| 31 | /** |
||
| 32 | * @var object SimpleXML object representing the API response |
||
| 33 | */ |
||
| 34 | private $response; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string JSON string that is the response sent by Authorize.Net |
||
| 38 | */ |
||
| 39 | private $responseJson; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Creates the response object with the response json returned from the API call |
||
| 43 | * |
||
| 44 | * @param string $responseJson Response from Authorize.Net |
||
| 45 | * @throws \JohnConde\Authnet\AuthnetInvalidJsonException |
||
| 46 | */ |
||
| 47 | public function __construct($responseJson) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Outputs the response JSON in a human readable format |
||
| 57 | * |
||
| 58 | * @return string HTML table containing debugging information |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function __toString() |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Gets a response variable from the API response |
||
| 75 | * |
||
| 76 | * net.authorize.customer.created |
||
| 77 | * net.authorize.customer.deleted |
||
| 78 | * net.authorize.customer.updated |
||
| 79 | * net.authorize.customer.paymentProfile.created |
||
| 80 | * net.authorize.customer.paymentProfile.deleted |
||
| 81 | * net.authorize.customer.paymentProfile.updated |
||
| 82 | * net.authorize.customer.subscription.cancelled |
||
| 83 | * net.authorize.customer.subscription.created |
||
| 84 | * net.authorize.customer.subscription.expiring |
||
| 85 | * net.authorize.customer.subscription.suspended |
||
| 86 | * net.authorize.customer.subscription.terminated |
||
| 87 | * net.authorize.customer.subscription.updated |
||
| 88 | * net.authorize.payment.authcapture.created |
||
| 89 | * net.authorize.payment.authorization.created |
||
| 90 | * net.authorize.payment.capture.created |
||
| 91 | * net.authorize.payment.fraud.approved |
||
| 92 | * net.authorize.payment.fraud.declined |
||
| 93 | * net.authorize.payment.fraud.held |
||
| 94 | * net.authorize.payment.priorAuthCapture.created |
||
| 95 | * net.authorize.payment.refund.created |
||
| 96 | * net.authorize.payment.void.created |
||
| 97 | * |
||
| 98 | * @return array Array of event types supported by Webhooks API |
||
| 99 | */ |
||
| 100 | public function getEventTypes() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Gets the webhooks ID |
||
| 118 | * |
||
| 119 | * @return string Webhooks ID |
||
| 120 | */ |
||
| 121 | public function getWebhooksId() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Gets the status of the Webhooks |
||
| 128 | * |
||
| 129 | * @return string Staus of the webhooks [active|inactive] |
||
| 130 | */ |
||
| 131 | public function getStatus() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Gets the URL the Webhooks API will use for these Webhooks |
||
| 138 | * |
||
| 139 | * @return string |
||
| 140 | */ |
||
| 141 | public function getUrl() |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Gets a list of webhooks |
||
| 148 | * |
||
| 149 | * @return array |
||
| 150 | */ |
||
| 151 | public function getWebhooks() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Gets a list of webhooks |
||
| 162 | * |
||
| 163 | * @return array |
||
| 164 | */ |
||
| 165 | public function getNotificationHistory() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Gets the notification ID of a notification |
||
| 178 | * |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | public function getNotificationId() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Gets the delivery status of a notification |
||
| 188 | * |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | public function getDeliveryStatus() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Gets the event type of a notification |
||
| 198 | * |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | public function getEventType() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Gets the event date of a notification |
||
| 208 | * |
||
| 209 | * @return string |
||
| 210 | */ |
||
| 211 | public function getEventDate() |
||
| 215 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.