| Conditions | 11 |
| Paths | 22 |
| Total Lines | 53 |
| Code Lines | 22 |
| 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 namespace Comodojo\RpcClient\Processor; |
||
| 36 | public function decode($response) { |
||
| 37 | |||
| 38 | try { |
||
| 39 | |||
| 40 | if ( sizeof($this->ids) == 0 ) { |
||
| 41 | |||
| 42 | return true; |
||
| 43 | |||
| 44 | } |
||
| 45 | |||
| 46 | $content = json_decode($response, true); |
||
| 47 | |||
| 48 | if ( is_null($content) ) throw new Exception("Incomprehensible or empty response"); |
||
| 49 | |||
| 50 | if ( $this->isMulticall === false ) { |
||
| 51 | |||
| 52 | $content = $content[0]; |
||
| 53 | |||
| 54 | if ( $content["id"] != $this->ids[0] ) throw new Exception("Invalid response ID received"); |
||
| 55 | |||
| 56 | $return = $content["result"]; |
||
| 57 | |||
| 58 | } else { |
||
| 59 | |||
| 60 | $batch_content = array(); |
||
| 61 | |||
| 62 | foreach ( $this->ids as $key => $id ) { |
||
| 63 | |||
| 64 | if ( !isset($content[$key]) ) $batch_content[$key] = array("error" => array("code" => null, "message" => "Empty response")); |
||
| 65 | |||
| 66 | else if ( isset($content[$key]["error"]) ) $batch_content[$key] = array("error" => $content["error"]); |
||
| 67 | |||
| 68 | else if ( !isset($content[$key]["id"]) ) $batch_content[$key] = array("error" => array("code" => null, "message" => "Malformed response received")); |
||
| 69 | |||
| 70 | else if ( $content[$key]["id"] != $id ) $batch_content[$key] = array("error" => array("code" => null, "message" => "Invalid response ID received")); |
||
| 71 | |||
| 72 | else $batch_content[$key] = array("result" => $content[$key]["result"]); |
||
| 73 | |||
| 74 | } |
||
| 75 | |||
| 76 | $return = $batch_content; |
||
| 77 | |||
| 78 | } |
||
| 79 | |||
| 80 | } catch (Exception $xe) { |
||
| 81 | |||
| 82 | throw $xe; |
||
| 83 | |||
| 84 | } |
||
| 85 | |||
| 86 | return $return; |
||
| 87 | |||
| 88 | } |
||
| 89 | |||
| 119 |