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 declare(strict_types=1); |
||
12 | class Client extends \GuzzleHttp\Client |
||
13 | { |
||
14 | /** |
||
15 | * @const string Version number |
||
16 | */ |
||
17 | const VERSION = '0.1.1'; |
||
18 | |||
19 | /** |
||
20 | * Defaults to expecting that Apache Tomcat runs on port 8080 on localhost |
||
21 | * (127.0.0.1). |
||
22 | * |
||
23 | * @var array[] |
||
24 | */ |
||
25 | protected $options = [ |
||
26 | 'scheme' => 'http', |
||
27 | 'hostname' => 'localhost', |
||
28 | 'port' => '8080', |
||
29 | ]; |
||
30 | |||
31 | /** |
||
32 | * @param $options array |
||
33 | * |
||
34 | * @return void |
||
|
|||
35 | */ |
||
36 | 2 | public function __construct($options = []) |
|
60 | |||
61 | /** |
||
62 | * Facility provided to cancel recharges. This does not work if the recharge |
||
63 | * has been processed by the MNO. |
||
64 | * |
||
65 | * @param int $reference Order Reference from SmartCall |
||
66 | * |
||
67 | * @throws Exception |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 2 | public function cancelRecharge($reference) |
|
92 | |||
93 | /** |
||
94 | * Transfer funds to another SmartCall Dealer Account. |
||
95 | * |
||
96 | * @param int $amount Amount in rands (ZAR) to transfer to the recipients SmartCall Dealer Account |
||
97 | * @param int $msisdn MSISDN of the account to receive the funds being transfered |
||
98 | * @param bool $sendSms true = send sms | false do not send a sms |
||
99 | * |
||
100 | * @throws Exception |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | 1 | public function fundsTransfer($amount, $msisdn, $sendSms) |
|
127 | |||
128 | /** |
||
129 | * Fetches the Dealer Balance from SmartCall. |
||
130 | * |
||
131 | * @throws Exception |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | 3 | View Code Duplication | public function getDealerBalance() |
149 | |||
150 | /** |
||
151 | * Fetches the Dealer Balance from SmartCall. |
||
152 | * |
||
153 | * @throws Exception |
||
154 | * |
||
155 | * @return array |
||
156 | */ |
||
157 | 1 | View Code Duplication | public function isDealerRegistered($msisdn) |
176 | |||
177 | /** |
||
178 | * Fetches the Product from SmartCall. |
||
179 | * |
||
180 | * @param int $productId Product Identifier |
||
181 | * |
||
182 | * @throws Exception |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | 2 | View Code Duplication | public function getProduct($productId) |
205 | |||
206 | /** |
||
207 | * Fetches the Product List from SmartCall. |
||
208 | * |
||
209 | * @throws Exception |
||
210 | * |
||
211 | * @return array |
||
212 | */ |
||
213 | 1 | View Code Duplication | public function getProducts() |
227 | |||
228 | /** |
||
229 | * Fetches the details of the last transaction processed from SmartCall. |
||
230 | * |
||
231 | * @throws Exception |
||
232 | * |
||
233 | * @return array |
||
234 | */ |
||
235 | 1 | View Code Duplication | public function getLastTransaction() |
249 | |||
250 | /** |
||
251 | * Fetches the Product List by the specified network identifier from SmartCall. |
||
252 | * |
||
253 | * @param int $networkId identifier for the network |
||
254 | * |
||
255 | * @throws Exception |
||
256 | * |
||
257 | * @return array |
||
258 | */ |
||
259 | 1 | View Code Duplication | public function getProductsByNetwork($networkId) |
278 | |||
279 | /** |
||
280 | * Prevend an item. The client reference needs to be passed in when performing the purchase. |
||
281 | * Vodacom requires that the client reference used for the prevend gets passed back in for |
||
282 | * the actual vend. |
||
283 | * |
||
284 | * @param int $productId identifier for the product |
||
285 | * @param int $amount amount in rands of the product |
||
286 | * @param int $msisdn mobile number of the recipient of the product |
||
287 | * @param int $deviceId mobile number or meter number of the device being recharged |
||
288 | * @param string $clientRef Client Reference (use a UUID) |
||
289 | * @param bool $pinless true = device will be recharged via the network's IN platform | false = pinbased virtual voucher |
||
290 | * @param bool $sendSms true = SmartCall will send the voucher via SMS | false don't send the voucher via SMS |
||
291 | * |
||
292 | * @throws Exception |
||
293 | * |
||
294 | * @return array |
||
295 | */ |
||
296 | View Code Duplication | public function prevendProduct($productId, $amount, $msisdn, $deviceId, $clientRef, $pinless, $sendSms) |
|
325 | |||
326 | /** |
||
327 | * Purchase a voucher or do a pinless recharge on SmartCall. |
||
328 | * |
||
329 | * @param int $productId identifier for the product |
||
330 | * @param int $amount amount in rands of the product |
||
331 | * @param int $msisdn mobile number of the recipient of the product |
||
332 | * @param int $deviceId mobile number or meter number of the device being recharged |
||
333 | * @param string $clientRef Client Reference (use a UUID) |
||
334 | * @param bool $pinless true = device will be recharged via the network's IN platform | false = pinbased virtual voucher |
||
335 | * @param bool $sendSms true = SmartCall will send the voucher via SMS | false don't send the voucher via SMS |
||
336 | * |
||
337 | * @throws Exception |
||
338 | * |
||
339 | * @return array |
||
340 | */ |
||
341 | 4 | View Code Duplication | public function purchaseProduct($productId, $amount, $msisdn, $deviceId, $clientRef, $pinless, $sendSms) |
370 | |||
371 | /** |
||
372 | * Searches SmartCall for a specified transaction using a specified key and string to search |
||
373 | * against at SmartCall. |
||
374 | * |
||
375 | * @param string $field client_ref | msisdn | order_reference |
||
376 | * @param string $search Client Reference when client_ref or a users MSISDN when msisdn |
||
377 | * |
||
378 | * @throws Exception |
||
379 | * |
||
380 | * @return array |
||
381 | */ |
||
382 | 6 | public function searchTransaction($field, $search) |
|
411 | |||
412 | /** |
||
413 | * Parse the java exception that we receive from Smartcall's Tomcat's. |
||
414 | * |
||
415 | * @param \GuzzleHttp\Exception\ServerException $exception |
||
416 | * |
||
417 | * @return array |
||
418 | */ |
||
419 | 1 | private function parseError(\GuzzleHttp\Exception\ServerException $exception) |
|
431 | } |
||
432 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.