| Conditions | 12 |
| Paths | 366 |
| Total Lines | 68 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 48 | private function sendRequest($type, $end_point, $data = [], $headers = [], $file = false) |
||
| 49 | { |
||
| 50 | try { |
||
| 51 | $ch = curl_init(); |
||
| 52 | curl_setopt($ch, CURLOPT_URL, $this->config['base_url'].$end_point); |
||
| 53 | curl_setopt($ch, CURLOPT_USERAGENT, $this->config['user_agent']); |
||
| 54 | |||
| 55 | if (! empty($headers)) { |
||
| 56 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
||
| 57 | } |
||
| 58 | |||
| 59 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); |
||
| 60 | |||
| 61 | if ($type == 'POST' && ! empty($data)) { |
||
| 62 | curl_setopt($ch, CURLOPT_POST, 1); |
||
| 63 | if (! empty($file)) { |
||
| 64 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
||
| 65 | } else { |
||
| 66 | curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | |||
| 70 | if (! empty($file)) { |
||
| 71 | curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']); |
||
| 72 | } |
||
| 73 | |||
| 74 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
||
| 75 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
||
| 76 | curl_setopt($ch, CURLOPT_ENCODING, ''); |
||
| 77 | curl_setopt($ch, CURLOPT_MAXREDIRS, 10); |
||
| 78 | curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); |
||
| 79 | curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1); |
||
| 80 | curl_setopt($ch, CURLOPT_FORBID_REUSE, 1); |
||
| 81 | curl_setopt($ch, CURLOPT_TIMEOUT, 0); |
||
| 82 | $result = curl_exec($ch); |
||
| 83 | |||
| 84 | $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
| 85 | $curlError = curl_error($ch); |
||
| 86 | $requestSize = curl_getinfo($ch, CURLINFO_REQUEST_SIZE); |
||
| 87 | $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); |
||
| 88 | $redirectCount = curl_getinfo($ch, CURLINFO_REDIRECT_COUNT); |
||
| 89 | $effectiveUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); |
||
| 90 | $totalTime = curl_getinfo($ch, CURLINFO_TOTAL_TIME); |
||
| 91 | |||
| 92 | $this->response->request = ['request_size' => $requestSize, 'curl_error' => $curlError, 'base_url' => $this->config['base_url'], 'content_type' => $contentType, 'redirect_count' => $redirectCount, 'effective_url' => $effectiveUrl, 'total_time' => $totalTime]; |
||
| 93 | $this->response->http_code = $httpCode; |
||
| 94 | |||
| 95 | if (! empty($data) && ! $file) { |
||
| 96 | $this->response->data = $this->parseXmlData($result); |
||
| 97 | } else { |
||
| 98 | $this->response->data["statusmessage"] = $result; |
||
| 99 | } |
||
| 100 | |||
| 101 | if ($httpCode == "200" && (isset($this->response->data["statusmessage"]) && |
||
| 102 | in_array( |
||
| 103 | $this->response->data["statusmessage"], |
||
| 104 | ["Message Sent Successfully!","In Process.. and check your campaign logs.", "Your Campaign runs successfully. Please check your campaign logs."] |
||
| 105 | ))) { |
||
| 106 | $this->response->status = 'success'; |
||
| 107 | } else { |
||
| 108 | $this->response->status = 'failed'; |
||
| 109 | } |
||
| 110 | curl_close($ch); |
||
| 111 | } catch (\Exception $ex) { |
||
| 112 | $this->response->request = ['request_size' => null, 'base_url' => $this->config['base_url'], 'curl_error' => null, 'content_type' => null, 'redirect_count' => null, 'effective_url' => null, 'total_time' => null]; |
||
| 113 | $this->response->http_code = null; |
||
| 114 | $this->response->status = 'failed'; |
||
| 115 | $this->response->data = $ex; |
||
| 116 | } |
||
| 190 |