| Conditions | 8 |
| Paths | 34 |
| Total Lines | 61 |
| Code Lines | 46 |
| 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 |
||
| 36 | public function execute($parameters) |
||
| 37 | { |
||
| 38 | $data = array(); |
||
|
|
|||
| 39 | if(isset($parameters["characterID"])) |
||
| 40 | $characterID = (int) $parameters["characterID"][0]; |
||
| 41 | |||
| 42 | $exists = Db::queryField("SELECT characterID FROM zz_characters WHERE characterID = :characterID", "characterID", array(":characterID" => $characterID)); |
||
| 43 | if(!$exists) |
||
| 44 | return array("type" => "error", "message" => "Character does not exist"); |
||
| 45 | |||
| 46 | $data = json_decode(Db::queryField("SELECT history FROM zz_characters WHERE characterID = :charID", "history", array(":charID" => $characterID)), true); |
||
| 47 | $corporationID = $data["corporationID"]; |
||
| 48 | $allianceID = $data["allianceID"]; |
||
| 49 | $lastSeenSystemID = Db::queryField("SELECT solarSystemID FROM zz_participants WHERE characterID = :charID ORDER BY dttm DESC LIMIT 1", "solarSystemID", array(":charID" => $characterID)); |
||
| 50 | $corpActiveSystemID = Db::queryField("SELECT solarSystemID, count(killID) AS hits FROM zz_participants WHERE characterID = :charID AND corporationID = :corpID AND dttm >= date_sub(now(), interval 30 day) GROUP BY solarSystemID ORDER BY hits DESC LIMIT 10000", "solarSystemID", array(":charID" => $characterID, ":corpID" => $corporationID)); |
||
| 51 | $allianceActiveSystemID = Db::queryField("SELECT solarSystemID, count(killID) AS hits FROM zz_participants WHERE characterID = :charID AND allianceID = :alliID AND dttm >= date_sub(now(), interval 30 day) GROUP BY solarSystemID ORDER BY hits DESC LIMIT 10000", "solarSystemID", array(":charID" => $characterID, ":alliID" => $allianceID)); |
||
| 52 | $data["allianceTicker"] = Db::queryField("SELECT ticker FROM zz_alliances WHERE allianceID = :allianceID", "ticker", array(":allianceID" => $allianceID)); |
||
| 53 | $data["corporationTicker"] = Db::queryField("SELECT ticker FROM zz_corporations WHERE corporationID = :corporationID", "ticker", array(":corporationID" => $corporationID)); |
||
| 54 | $data["lastSeenSystem"] = Info::getSystemName($lastSeenSystemID); |
||
| 55 | $data["lastSeenRegion"] = Info::getRegionName(Info::getRegionIDFromSystemID($lastSeenSystemID)); |
||
| 56 | $data["lastSeenDate"] = Db::queryField("SELECT dttm FROM zz_participants WHERE characterID = :charID ORDER BY dttm DESC LIMIT 1", "dttm", array(":charID" => $characterID)); |
||
| 57 | $data["lastSeenShip"] = Info::getShipName(Db::queryField("SELECT shipTypeID FROM zz_participants WHERE characterID = :charID AND shipTypeID != 0 ORDER BY dttm DESC LIMIT 1", "shipTypeID", array(":charID" => $characterID))); |
||
| 58 | $data["corporationActiveArea"] = Info::getRegionName(Info::getRegionIDFromSystemID($corpActiveSystemID)); |
||
| 59 | $data["allianceActiveArea"] = isset($allianceID) ? Info::getRegionName(Info::getRegionIDFromSystemID($allianceActiveSystemID)) : ""; |
||
| 60 | $data["lifeTimeKills"] = Db::queryField("SELECT SUM(destroyed) AS kills FROM zz_stats WHERE typeID = :charID", "kills", array(":charID" => $characterID), 3600); |
||
| 61 | $data["lifeTimeLosses"] = Db::queryField("SELECT SUM(lost) AS losses FROM zz_stats WHERE typeID = :charID", "losses", array(":charID" => $characterID), 3600); |
||
| 62 | $data["top10FlownShips"] = Stats::getTopShips(array("characterID" => $characterID, "kills" => true, "month" => date("m"), "year" => date("y"), "limit" => 10), true); |
||
| 63 | $data["top10ActiveSystems"] = Stats::getTopSystems(array("characterID" => $characterID, "kills" => true, "month" => date("m"), "year" => date("y"), "limit" => 10), true); |
||
| 64 | $data["lastUpdatedOnBackend"] = Db::queryField("SELECT lastUpdated FROM zz_characters WHERE characterID = :charID", "lastUpdated", array(":charID" => $characterID)); |
||
| 65 | $data["soloKills"] = Db::queryField("SELECT count(*) as kills FROM zz_participants WHERE characterID = :charID AND isVictim = 0 AND number_involved = 1", "kills", array(":charID" => $characterID)); |
||
| 66 | $data["blobKills"] = Db::queryField("SELECT count(*) as kills FROM zz_participants WHERE characterID = :charID AND isVictim = 0 AND number_involved >= 50", "kills", array(":charID" => $characterID)); |
||
| 67 | |||
| 68 | if($data["soloKills"] > 0 && $data["blobKills"] > 0) |
||
| 69 | $data["percentageSoloPVPer"] = $data["soloKills"] / $data["blobKills"] * 100; |
||
| 70 | |||
| 71 | $penis = "(..)=="; |
||
| 72 | $cnt = log($data["lifeTimeKills"]) * 3; |
||
| 73 | $i = 0; |
||
| 74 | while($i < $cnt) |
||
| 75 | { |
||
| 76 | $penis .= "="; |
||
| 77 | $i++; |
||
| 78 | } |
||
| 79 | $data["ePeenSize"] = $penis . "D"; |
||
| 80 | |||
| 81 | $facepalmLosses = Db::queryField("SELECT count(*) AS losses FROM zz_participants WHERE characterID = :charID AND shipPrice >= 200000000 AND isVictim = 1", "losses", array(":charID" => $characterID)); |
||
| 82 | $facepalms = "(>ლ)"; |
||
| 83 | $cnt = log($facepalmLosses); |
||
| 84 | $i = 0; |
||
| 85 | while($i < $cnt) |
||
| 86 | { |
||
| 87 | $facepalms .= "(>ლ)"; |
||
| 88 | $i++; |
||
| 89 | } |
||
| 90 | |||
| 91 | $data["facepalms"] = $facepalms; |
||
| 92 | return $data; |
||
| 93 | |||
| 94 | // Do the same with corporation and alliance apis? |
||
| 95 | // Full character list for corporations / alliances ? :D could be usefull for spymasters and shit |
||
| 96 | } |
||
| 97 | } |
||
| 98 |
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.