| Conditions | 12 |
| Paths | 130 |
| Total Lines | 41 |
| Code Lines | 29 |
| 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 |
||
| 51 | public static function getJSON($kills, $parameters) |
||
| 52 | { |
||
| 53 | if ($kills == null) return array(); |
||
| 54 | $retValue = array(); |
||
| 55 | |||
| 56 | foreach ($kills as $kill) { |
||
| 57 | $killID = $kill["killID"]; |
||
| 58 | $jsonText = Killmail::get($killID); |
||
| 59 | $json = json_decode($jsonText, true); |
||
| 60 | $involvedCount = count($json["attackers"]); |
||
| 61 | |||
| 62 | if (array_key_exists("no-items", $parameters)) |
||
| 63 | unset($json["items"]); |
||
| 64 | |||
| 65 | if (array_key_exists("finalblow-only", $parameters)) |
||
| 66 | { |
||
| 67 | $data = $json["attackers"]; |
||
| 68 | unset($json["attackers"]); |
||
| 69 | foreach($data as $attacker) |
||
| 70 | if($attacker["finalBlow"] == "1") |
||
| 71 | $json["attackers"][] = $attacker; |
||
| 72 | } |
||
| 73 | |||
| 74 | if (array_key_exists("no-attackers", $parameters)) |
||
| 75 | unset($json["attackers"]); |
||
| 76 | |||
| 77 | if(isset($json["_stringValue"])) |
||
| 78 | unset($json["_stringValue"]); |
||
| 79 | |||
| 80 | $json["zkb"]["involved"] = count($involvedCount); |
||
| 81 | if(!isset($json["zkb"]["totalValue"])) |
||
| 82 | $json["zkb"]["totalValue"] = Db::queryField("SELECT total_price FROM zz_participants WHERE killID = :killID AND isVictim = 1", "total_price", array(":killID" => $killID)); |
||
| 83 | if(!isset($json["zkb"]["points"])) |
||
| 84 | $json["zkb"]["points"] = Db::queryField("SELECT points FROM zz_participants WHERE killID = :killID AND isVictim = 1", "points", array(":killID" => $killID)); |
||
| 85 | if(!isset($json["zkb"]["source"])) |
||
| 86 | $json["zkb"]["source"] = Db::queryField("SELECT source FROM zz_killmails WHERE killID = :killID", "source", array(":killID" => $killID)); |
||
| 87 | |||
| 88 | $retValue[] = json_encode($json); |
||
| 89 | } |
||
| 90 | return $retValue; |
||
| 91 | } |
||
| 92 | } |
||
| 93 |
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.