| Conditions | 22 |
| Paths | 12 |
| Total Lines | 77 |
| Code Lines | 36 |
| Lines | 35 |
| Ratio | 45.45 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 188 | public function send($recipients, $message) |
||
| 189 | { |
||
| 190 | if ($this->message_type < 1) { |
||
| 191 | throw new BongaTechException('The Message Type has not been set.'); |
||
| 192 | } |
||
| 193 | |||
| 194 | $this->recipients = $recipients; |
||
| 195 | $this->message = $message; |
||
| 196 | $this->endpoint = $this->config['base_url'].$this->config['sms_endpoint']; |
||
| 197 | |||
| 198 | if ($this->batch_type === BatchType::NOT_BATCH) { |
||
| 199 | |||
| 200 | View Code Duplication | if (is_array($this->message) && array_depth($this->message) == 2 && count($this->message) == 1) { |
|
| 201 | |||
| 202 | if (is_array($this->recipients) && array_depth($this->recipients) == 2 && count($this->recipients) == 1) { |
||
| 203 | |||
| 204 | $response = $this->sendForNonBatch($this->buildSendObject($this->recipients, $this->message)); |
||
| 205 | |||
| 206 | } else { |
||
| 207 | throw new BongaTechException('The recipient MUST be an array of depth 2 and count should not be more than 1'); |
||
| 208 | } |
||
| 209 | } else { |
||
| 210 | |||
| 211 | throw new BongaTechException('Message should be provided as an array whose depth is 2 and count should equal 1'); |
||
| 212 | } |
||
| 213 | |||
| 214 | |||
| 215 | View Code Duplication | } elseif ($this->batch_type === BatchType::SAME_MESSAGE) { |
|
| 216 | |||
| 217 | if (is_array($this->message) && array_depth($this->message) == 2 && count($this->message) == 1) { |
||
| 218 | |||
| 219 | if (is_array($this->recipients) && array_depth($this->recipients) == 2 && count($this->recipients) > 1) { |
||
| 220 | |||
| 221 | $response = $this->sendForBatch($this->buildSendObject($this->recipients, $this->message)); |
||
| 222 | |||
| 223 | } else { |
||
| 224 | |||
| 225 | throw new BongaTechException('The recipients MUST be an array of depth 2 and count should be more than 1'); |
||
| 226 | } |
||
| 227 | |||
| 228 | |||
| 229 | } else { |
||
| 230 | |||
| 231 | throw new BongaTechException('Message should be provided as an array whose depth and count should equal 1'); |
||
| 232 | } |
||
| 233 | |||
| 234 | } elseif ($this->batch_type === BatchType::DIFFERENT_MESSAGE) { |
||
| 235 | |||
| 236 | if (count($this->recipients) == count($this->message)) { |
||
| 237 | |||
| 238 | if (is_array($this->message) && array_depth($this->message) == 2) { |
||
| 239 | |||
| 240 | if (is_array($this->recipients) && array_depth($this->recipients) == 2) { |
||
| 241 | |||
| 242 | $response = $this->sendForBatch($this->buildSendObject($this->recipients, $this->message)); |
||
| 243 | |||
| 244 | } else { |
||
| 245 | |||
| 246 | throw new BongaTechException('The recipients MUST be an array of depth 2'); |
||
| 247 | } |
||
| 248 | |||
| 249 | } else { |
||
| 250 | |||
| 251 | throw new BongaTechException('Message MUST be an array of depth 2'); |
||
| 252 | } |
||
| 253 | } else { |
||
| 254 | |||
| 255 | throw new BongaTechException('No. of Messages MUST be equal to number of Recipients.'); |
||
| 256 | } |
||
| 257 | |||
| 258 | } else { |
||
| 259 | |||
| 260 | throw new BongaTechException('Message Batch Type has not been set.'); |
||
| 261 | } |
||
| 262 | |||
| 263 | return $response; |
||
| 264 | } |
||
| 265 | |||
| 358 |