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 |
||
| 5 | class Advantasms |
||
| 6 | { |
||
| 7 | private $apikey, $partnerId, $shortcode; |
||
| 8 | private $message, $to; |
||
| 9 | private $baseUrl = "https://quicksms.advantasms.com"; |
||
| 10 | private $sendsms = "/api/services/sendsms"; |
||
| 11 | /** |
||
| 12 | * Advantasms constructor. |
||
| 13 | * @param string $apiKey |The advanta sms API Key. See documentation for more details |
||
| 14 | * @param string $partnerId | The Partner ID. See advantaSMS documentation for more details |
||
| 15 | * @param string $shortCode | The Shortcode of used to send sms. See documentation for more details |
||
| 16 | * @param string|null $domain | The base domain in case it is different from https://quicksms.advantasms.com |
||
|
|
|||
| 17 | * @return Advantasms |
||
| 18 | */ |
||
| 19 | public function __construct($apiKey, $partnerId, $shortCode, $baseUrl="https://quicksms.advantasms.com") |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Instantiate the Advantasms class. |
||
| 30 | * @param string $apiKey |The advanta sms API Key. See documentation for more details |
||
| 31 | * @param string $partnerId | The Partner ID. See advantaSMS documentation for more details |
||
| 32 | * @param string $shortCode | The Shortcode of used to send sms. See documentation for more details |
||
| 33 | * @param string|null $domain | The base domain in case it is different from quicksms.advantasms.com |
||
| 34 | * @return Advantasms |
||
| 35 | */ |
||
| 36 | public static function init($apiKey,$partnerId, $shortCode, $baseUrl="https://quicksms.advantasms.com") { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param $mobileNumber |
||
| 43 | * @return Advantasms |
||
| 44 | */ |
||
| 45 | public function to($mobileNumber) { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param string $message |
||
| 52 | * @return Advantasms |
||
| 53 | */ |
||
| 54 | public function message(string $message="") { |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Execute sms sending action |
||
| 61 | * @return array|mixed |
||
| 62 | * |
||
| 63 | * 200;Successful Request Call |
||
| 64 | * 1001;Invalid sender id |
||
| 65 | * 1002;Network not allowed |
||
| 66 | * 1003;Invalid mobile number |
||
| 67 | * 1004;Low bulk credits |
||
| 68 | * 1005;Failed. System error |
||
| 69 | * 1006;Invalid credentials |
||
| 70 | * 1007;Failed. System error |
||
| 71 | * 1008;No Delivery Report |
||
| 72 | * 1009;unsupported data type |
||
| 73 | * 1010;unsupported request type |
||
| 74 | * 4090;Internal Error. Try again after 5 minutes |
||
| 75 | * 4091;No Partner ID is Set |
||
| 76 | * 4092;No API KEY Provided |
||
| 77 | * 4093;Details Not Found |
||
| 78 | * */ |
||
| 79 | View Code Duplication | public function send() { |
|
| 131 | |||
| 132 | /** |
||
| 133 | * Schedule sms sending action |
||
| 134 | * @param string $time | Time to send in Y-m-d H:i format |
||
| 135 | * @return array|mixed |
||
| 136 | * |
||
| 137 | * 200;Successful Request Call |
||
| 138 | * 1001;Invalid sender id |
||
| 139 | * 1002;Network not allowed |
||
| 140 | * 1003;Invalid mobile number |
||
| 141 | * 1004;Low bulk credits |
||
| 142 | * 1005;Failed. System error |
||
| 143 | * 1006;Invalid credentials |
||
| 144 | * 1007;Failed. System error |
||
| 145 | * 1008;No Delivery Report |
||
| 146 | * 1009;unsupported data type |
||
| 147 | * 1010;unsupported request type |
||
| 148 | * 4090;Internal Error. Try again after 5 minutes |
||
| 149 | * 4091;No Partner ID is Set |
||
| 150 | * 4092;No API KEY Provided |
||
| 151 | * 4093;Details Not Found |
||
| 152 | * */ |
||
| 153 | View Code Duplication | public function schedule($time) { |
|
| 206 | /** |
||
| 207 | * @param string $endpoint |
||
| 208 | * @param array $data |
||
| 209 | * @param array $headers |
||
| 210 | * @return array|mixed |
||
| 211 | */ |
||
| 212 | private function curlPost(string $endpoint, array $data, array $headers=[]) { |
||
| 226 | |||
| 227 | } |
||
| 228 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.