| Conditions | 11 |
| Paths | 22 |
| Total Lines | 53 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 namespace Comodojo\RpcClient\Processor; |
||
| 50 | public function decode($response) { |
||
| 51 | |||
| 52 | try { |
||
| 53 | |||
| 54 | if ( sizeof($this->ids) == 0 ) { |
||
| 55 | |||
| 56 | return true; |
||
| 57 | |||
| 58 | } |
||
| 59 | |||
| 60 | $content = json_decode($response, true); |
||
| 61 | |||
| 62 | if ( is_null($content) ) throw new Exception("Incomprehensible or empty response"); |
||
| 63 | |||
| 64 | if ( $this->isMulticall === false ) { |
||
| 65 | |||
| 66 | $content = $content[0]; |
||
| 67 | |||
| 68 | if ( $content["id"] != $this->ids[0] ) throw new Exception("Invalid response ID received"); |
||
| 69 | |||
| 70 | $return = $content["result"]; |
||
| 71 | |||
| 72 | } else { |
||
| 73 | |||
| 74 | $batch_content = array(); |
||
| 75 | |||
| 76 | foreach ( $this->ids as $key => $id ) { |
||
| 77 | |||
| 78 | if ( !isset($content[$key]) ) $batch_content[$key] = array("error" => array("code" => null, "message" => "Empty response")); |
||
| 79 | |||
| 80 | else if ( isset($content[$key]["error"]) ) $batch_content[$key] = array("error" => $content["error"]); |
||
| 81 | |||
| 82 | else if ( !isset($content[$key]["id"]) ) $batch_content[$key] = array("error" => array("code" => null, "message" => "Malformed response received")); |
||
| 83 | |||
| 84 | else if ( $content[$key]["id"] != $id ) $batch_content[$key] = array("error" => array("code" => null, "message" => "Invalid response ID received")); |
||
| 85 | |||
| 86 | else $batch_content[$key] = array("result" => $content[$key]["result"]); |
||
| 87 | |||
| 88 | } |
||
| 89 | |||
| 90 | $return = $batch_content; |
||
| 91 | |||
| 92 | } |
||
| 93 | |||
| 94 | } catch (Exception $xe) { |
||
| 95 | |||
| 96 | throw $xe; |
||
| 97 | |||
| 98 | } |
||
| 99 | |||
| 100 | return $return; |
||
| 101 | |||
| 102 | } |
||
| 103 | |||
| 133 |
This check marks private properties in classes that are never used. Those properties can be removed.