| Conditions | 4 |
| Paths | 4 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 60 | public function send() { |
||
| 61 | $data = [ |
||
| 62 | "apikey"=>$this->apikey, |
||
| 63 | "partnerID"=>trim($this->partnerId), |
||
| 64 | "message"=>trim($this->message), |
||
| 65 | "shortcode"=>$this->shortcode, |
||
| 66 | "mobile"=>trim($this->to) |
||
| 67 | ]; |
||
| 68 | $response = $this->curlPost($this->sendsms,$data); |
||
| 69 | /* |
||
| 70 | 200;Successful Request Call |
||
| 71 | 1001;Invalid sender id |
||
| 72 | 1002;Network not allowed |
||
| 73 | 1003;Invalid mobile number |
||
| 74 | 1004;Low bulk credits |
||
| 75 | 1005;Failed. System error |
||
| 76 | 1006;Invalid credentials |
||
| 77 | 1007;Failed. System error |
||
| 78 | 1008;No Delivery Report |
||
| 79 | 1009;unsupported data type |
||
| 80 | 1010;unsupported request type |
||
| 81 | 4090;Internal Error. Try again after 5 minutes |
||
| 82 | 4091;No Partner ID is Set |
||
| 83 | 4092;No API KEY Provided |
||
| 84 | 4093;Details Not Found |
||
| 85 | */ |
||
| 86 | $return = [ |
||
| 87 | "success" => false, |
||
| 88 | "message" => "", |
||
| 89 | "payload" => [] |
||
| 90 | ]; |
||
| 91 | if (!$response) { |
||
| 92 | $return["success"] = false; |
||
| 93 | $return["message"] = "No response from the server."; |
||
| 94 | return $return; |
||
| 95 | } else { |
||
| 96 | if (isset($response['responses'])) { |
||
| 97 | $first = $response["responses"][0]; |
||
| 98 | $return["success"] = $first["response-code"] ===200; |
||
| 99 | $return["code"] = $first["response-code"]; |
||
| 100 | $return["message"] = $first["response-description"]; |
||
| 101 | $return["payload"] = $response["responses"]; |
||
| 102 | return $return; |
||
| 103 | } |
||
| 104 | if (isset($response["response-code"])) { |
||
| 105 | $first = $response; |
||
| 106 | $return["success"] = $first["response-code"] ===200; |
||
| 107 | $return["code"] = $first["response-code"]; |
||
| 108 | $return["message"] = $first["response-description"]; |
||
| 109 | $return["payload"] = $response; |
||
| 110 | return $return; |
||
| 111 | } |
||
| 112 | $return["success"] = false; |
||
| 113 | $return["message"] = "Unknown Error"; |
||
| 114 | $return["payload"] = $response; |
||
| 115 | return $response; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 159 |
Adding a
@returnannotation 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.