| Conditions | 12 |
| Paths | 44 |
| Total Lines | 49 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 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 |
||
| 37 | public function execute($parameters) |
||
| 38 | {
|
||
| 39 | $command = isset($parameters["battles"]) ? $parameters["battles"] : NULL; |
||
| 40 | $battleID = isset($parameters["battle"]) ? $parameters["battle"] : 0; |
||
| 41 | |||
| 42 | if($command == "list") |
||
| 43 | {
|
||
| 44 | $data = array(); |
||
|
|
|||
| 45 | $battles = Db::query("SELECT * FROM zz_battles", array(), 360);
|
||
| 46 | foreach($battles as $key => $value) |
||
| 47 | {
|
||
| 48 | unset($battles[$key]["teamAJson"]); |
||
| 49 | unset($battles[$key]["teamBJson"]); |
||
| 50 | } |
||
| 51 | return $battles; |
||
| 52 | } |
||
| 53 | elseif($command == "battle") |
||
| 54 | {
|
||
| 55 | $getData = Db::queryRow("SELECT * FROM zz_battles WHERE battleID = :battleID", array(":battleID" => $battleID), 360);
|
||
| 56 | |||
| 57 | foreach($getData as $key => $value) |
||
| 58 | {
|
||
| 59 | switch($key) |
||
| 60 | {
|
||
| 61 | case "teamAinvolved": |
||
| 62 | case "teamBinvolved": |
||
| 63 | $data[$key] = json_decode($value, true); |
||
| 64 | break; |
||
| 65 | |||
| 66 | case "teamAJson": |
||
| 67 | case "teamBJson": |
||
| 68 | $subJson = json_decode($value, true); |
||
| 69 | foreach($subJson as $d) |
||
| 70 | $data[$key][] = json_decode($d, true); |
||
| 71 | break; |
||
| 72 | |||
| 73 | default: |
||
| 74 | $data[$key] = $value; |
||
| 75 | break; |
||
| 76 | } |
||
| 77 | } |
||
| 78 | return $data; |
||
| 79 | } |
||
| 80 | else |
||
| 81 | return array( |
||
| 82 | "type" => "error", |
||
| 83 | "message" => "No valid parameter passed." |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | } |
||
| 87 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.