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 |
||
12 | class Client extends \GuzzleHttp\Client |
||
13 | { |
||
14 | /** |
||
15 | * @const string Version number |
||
16 | */ |
||
17 | const VERSION = '0.0.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 | * Fetches the Dealer Balance from SmartCall. |
||
63 | * |
||
64 | * @throws Exception |
||
65 | * |
||
66 | * @return array |
||
67 | */ |
||
68 | 1 | View Code Duplication | public function getDealerBalance() |
86 | |||
87 | /** |
||
88 | * Fetches the Dealer Balance from SmartCall. |
||
89 | * |
||
90 | * @throws Exception |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | View Code Duplication | public function isDealerRegistered($msisdn) |
|
117 | |||
118 | /** |
||
119 | * Fetches the Product from SmartCall. |
||
120 | * |
||
121 | * @param int $productId Product Identifier |
||
122 | * |
||
123 | * @throws Exception |
||
124 | * |
||
125 | * @return array |
||
126 | */ |
||
127 | public function getProduct($productId) |
||
154 | |||
155 | /** |
||
156 | * Fetches the Product List from SmartCall. |
||
157 | * |
||
158 | * @throws Exception |
||
159 | * |
||
160 | * @return array |
||
161 | */ |
||
162 | 1 | View Code Duplication | public function getProducts() |
180 | |||
181 | /** |
||
182 | * Fetches the details of the last transaction processed from SmartCall. |
||
183 | * |
||
184 | * @throws Exception |
||
185 | * |
||
186 | * @return array |
||
187 | */ |
||
188 | 1 | View Code Duplication | public function getLastTransaction() |
206 | |||
207 | /** |
||
208 | * Fetches the Product List by the specified network identifier from SmartCall. |
||
209 | * |
||
210 | * @param int $networkId identifier for the network |
||
211 | * |
||
212 | * @throws Exception |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | View Code Duplication | public function getProductsByNetwork($networkId) |
|
239 | |||
240 | /** |
||
241 | * Purchase a voucher or do a pinless recharge on SmartCall. |
||
242 | * |
||
243 | * @param int $productId identifier for the product |
||
244 | * @param int $amount amount in rands of the product |
||
245 | * @param int $msisdn mobile number of the recipient of the product |
||
246 | * @param int $deviceId mobile number or meter number of the device being recharged |
||
247 | * @param string $clientRef Client Reference (use a UUID) |
||
248 | * @param bool $pinless true = device will be recharged via the network's IN platform | false = pinbased virtual voucher |
||
249 | * @param bool $sendSms true = SmartCall will send the voucher via SMS | false don't send the voucher via SMS |
||
250 | * |
||
251 | * @throws Exception |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | 1 | public function purchaseProduct($productId, $amount, $msisdn, $deviceId, $clientRef, $pinless = true, $sendSms = false) |
|
288 | |||
289 | /** |
||
290 | * Searches SmartCall for a specified transaction using a specified key and string to search |
||
291 | * against at SmartCall. |
||
292 | * |
||
293 | * @param string $field client_ref | msisdn | order_reference |
||
294 | * @param string $query_string Client Reference when client_ref or a users MSISDN when msisdn |
||
295 | * |
||
296 | * @throws Exception |
||
297 | * |
||
298 | * @return array |
||
299 | */ |
||
300 | 3 | public function searchTransaction($field, $search) |
|
333 | } |
||
334 |
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.