Conditions | 21 |
Paths | 11 |
Total Lines | 76 |
Code Lines | 34 |
Lines | 35 |
Ratio | 46.05 % |
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 | $this->recipients = $recipients; |
||
191 | $this->message = $message; |
||
192 | $this->endpoint = $this->config['base_url'] . $this->config['sms_endpoint']; |
||
193 | |||
194 | if ($this->batch_type === BatchType::NOT_BATCH) { |
||
195 | |||
196 | View Code Duplication | if (is_array($this->message) && array_depth($this->message) == 2 && count($this->message) == 1) { |
|
1 ignored issue
–
show
|
|||
197 | |||
198 | if (is_array($this->recipients) && array_depth($this->recipients) == 2 && count($this->recipients) == 1) { |
||
199 | |||
200 | $response = $this->sendForNonBatch($this->buildSendObject($this->recipients, $this->message)); |
||
201 | |||
202 | } else { |
||
203 | |||
204 | throw new BongaTechException('The recipient MUST be an array of depth 2 and count should not be more than 1'); |
||
205 | } |
||
206 | |||
207 | } else { |
||
208 | |||
209 | throw new BongaTechException('Message should be provided as an array whose depth is 2 and count should equal 1'); |
||
210 | } |
||
211 | |||
212 | |||
213 | View Code Duplication | } elseif ($this->batch_type === BatchType::SAME_MESSAGE) { |
|
1 ignored issue
–
show
|
|||
214 | |||
215 | if (is_array($this->message) && array_depth($this->message) == 2 && count($this->message) == 1) { |
||
216 | |||
217 | if (is_array($this->recipients) && array_depth($this->recipients) == 2 && count($this->recipients) > 1) { |
||
218 | |||
219 | $response = $this->sendForBatch($this->buildSendObject($this->recipients, $this->message)); |
||
220 | |||
221 | } else { |
||
222 | |||
223 | throw new BongaTechException('The recipients MUST be an array of depth 2 and count should be more than 1'); |
||
224 | } |
||
225 | |||
226 | |||
227 | } else { |
||
228 | |||
229 | throw new BongaTechException('Message should be provided as an array whose depth and count should equal 1'); |
||
230 | } |
||
231 | |||
232 | } elseif ($this->batch_type === BatchType::DIFFERENT_MESSAGE) { |
||
233 | |||
234 | if (count($this->recipients) == count($this->message)) { |
||
235 | |||
236 | if (is_array($this->message) && array_depth($this->message) == 2) { |
||
237 | |||
238 | if (is_array($this->recipients) && array_depth($this->recipients) == 2) { |
||
239 | |||
240 | $response = $this->sendForBatch($this->buildSendObject($this->recipients, $this->message)); |
||
241 | |||
242 | } else { |
||
243 | |||
244 | throw new BongaTechException('The recipients MUST be an array of depth 2'); |
||
245 | } |
||
246 | |||
247 | } else { |
||
248 | |||
249 | throw new BongaTechException('Message MUST be an array of depth 2'); |
||
250 | } |
||
251 | } else { |
||
252 | |||
253 | throw new BongaTechException('No. of Messages MUST be equal to number of Recipients.'); |
||
254 | } |
||
255 | |||
256 | } else { |
||
257 | |||
258 | throw new BongaTechException('Message Batch Type has not been set.'); |
||
259 | } |
||
260 | |||
261 | return $response; |
||
262 | |||
263 | } |
||
264 | |||
366 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.