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() |
82 | |||
83 | /** |
||
84 | * Fetches the Dealer Balance from SmartCall. |
||
85 | * |
||
86 | * @throws Exception |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | 1 | View Code Duplication | public function isDealerRegistered($msisdn) |
109 | |||
110 | /** |
||
111 | * Fetches the Product from SmartCall. |
||
112 | * |
||
113 | * @param int $productId Product Identifier |
||
114 | * |
||
115 | * @throws Exception |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | 2 | View Code Duplication | public function getProduct($productId) |
138 | |||
139 | /** |
||
140 | * Fetches the Product List from SmartCall. |
||
141 | * |
||
142 | * @throws Exception |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | 1 | View Code Duplication | public function getProducts() |
160 | |||
161 | /** |
||
162 | * Fetches the details of the last transaction processed from SmartCall. |
||
163 | * |
||
164 | * @throws Exception |
||
165 | * |
||
166 | * @return array |
||
167 | */ |
||
168 | 1 | View Code Duplication | public function getLastTransaction() |
182 | |||
183 | /** |
||
184 | * Fetches the Product List by the specified network identifier from SmartCall. |
||
185 | * |
||
186 | * @param int $networkId identifier for the network |
||
187 | * |
||
188 | * @throws Exception |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | 1 | View Code Duplication | public function getProductsByNetwork($networkId) |
211 | |||
212 | /** |
||
213 | * Purchase a voucher or do a pinless recharge on SmartCall. |
||
214 | * |
||
215 | * @param int $productId identifier for the product |
||
216 | * @param int $amount amount in rands of the product |
||
217 | * @param int $msisdn mobile number of the recipient of the product |
||
218 | * @param int $deviceId mobile number or meter number of the device being recharged |
||
219 | * @param string $clientRef Client Reference (use a UUID) |
||
220 | * @param bool $pinless true = device will be recharged via the network's IN platform | false = pinbased virtual voucher |
||
221 | * @param bool $sendSms true = SmartCall will send the voucher via SMS | false don't send the voucher via SMS |
||
222 | * |
||
223 | * @throws Exception |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | 1 | public function purchaseProduct($productId, $amount, $msisdn, $deviceId, $clientRef, $pinless, $sendSms) |
|
256 | |||
257 | /** |
||
258 | * Searches SmartCall for a specified transaction using a specified key and string to search |
||
259 | * against at SmartCall. |
||
260 | * |
||
261 | * @param string $field client_ref | msisdn | order_reference |
||
262 | * @param string $query_string Client Reference when client_ref or a users MSISDN when msisdn |
||
263 | * |
||
264 | * @throws Exception |
||
265 | * |
||
266 | * @return array |
||
267 | */ |
||
268 | 3 | public function searchTransaction($field, $search) |
|
297 | |||
298 | 1 | private function parseError(\GuzzleHttp\Exception\ServerException $e) |
|
310 | } |
||
311 |
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.