| Conditions | 48 |
| Paths | > 20000 |
| Total Lines | 156 |
| Code Lines | 112 |
| 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 |
||
| 30 | public static function buildFilters(&$tables, &$combined, &$whereClauses, &$parameters, $allTime = true) |
||
| 31 | { |
||
| 32 | $year = null; |
||
| 33 | $month = null; |
||
| 34 | $week = null; |
||
| 35 | // zz_participants filters |
||
| 36 | $participants = "zz_participants p"; |
||
| 37 | $filterColumns = array("allianceID", "characterID", "corporationID", "factionID", "shipTypeID", "groupID", "solarSystemID", "regionID"); |
||
| 38 | foreach ($filterColumns as $filterColumn) { |
||
| 39 | self::buildWhere($tables, $combined, $participants, $filterColumn, $parameters); |
||
| 40 | self::buildWhere($tables, $combined, $participants, "!$filterColumn", $parameters); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (array_key_exists("year", $parameters)) $year = (int)$parameters["year"]; // Optional |
||
| 44 | if (array_key_exists("week", $parameters)) $week = (int)$parameters["week"]; // Optional |
||
| 45 | if (array_key_exists("month", $parameters)) $month = (int)$parameters["month"]; // Optional |
||
| 46 | if (!array_key_exists("pastSeconds", $parameters) && $allTime == false && (!isset($year) || !isset($week))) { |
||
|
|
|||
| 47 | $year = array_key_exists("year", $parameters) ? (int)$parameters["year"] : date("Y"); |
||
| 48 | $week = array_key_exists("week", $parameters) ? (int)$parameters["week"] : date("W"); |
||
| 49 | } |
||
| 50 | |||
| 51 | if (array_key_exists("killID", $parameters)) { |
||
| 52 | $tables[] = "zz_participants p"; |
||
| 53 | $whereClauses[] = "p.killID = " . ((int) $parameters["killID"]); |
||
| 54 | } |
||
| 55 | |||
| 56 | if (array_key_exists("api-only", $parameters)) { |
||
| 57 | $tables[] = "zz_participants p"; |
||
| 58 | $whereClauses[] = "p.killID > 0"; |
||
| 59 | } |
||
| 60 | |||
| 61 | if (array_key_exists("solo", $parameters) && $parameters["solo"] === true) { |
||
| 62 | $tables[] = "zz_participants p"; |
||
| 63 | $whereClauses[] = "p.number_involved = 1"; |
||
| 64 | $whereClauses[] = "p.vGroupID not in (237, 29, 31)"; |
||
| 65 | } |
||
| 66 | |||
| 67 | if (array_key_exists("relatedTime", $parameters)) { |
||
| 68 | $relatedTime = $parameters["relatedTime"]; |
||
| 69 | $unixTime = strtotime($relatedTime); |
||
| 70 | if ($unixTime % 3600 != 0) throw new Exception("User attempted an unsupported value. Fail."); |
||
| 71 | $tables[] = "zz_participants p"; |
||
| 72 | $hourModifier = 1; |
||
| 73 | if (array_key_exists("exHours", $parameters)) { |
||
| 74 | $exHours = (int)$parameters["exHours"]; |
||
| 75 | if ($exHours > 1 && $exHours <= 12) $hourModifier = $exHours; |
||
| 76 | } |
||
| 77 | $whereClauses[] = "p.dttm >= '" . date("Y-m-d H:i:00", $unixTime - ($hourModifier * 3600)) . "'"; |
||
| 78 | $whereClauses[] = "p.dttm <= '" . date("Y-m-d H:i:00", $unixTime + ($hourModifier * 3600)) . "'"; |
||
| 79 | $parameters["limit"] = 10000; |
||
| 80 | } |
||
| 81 | if (array_key_exists("startTime", $parameters)) { |
||
| 82 | $time = $parameters["startTime"]; |
||
| 83 | $unixTime = strtotime($time); |
||
| 84 | $tables[] = "zz_participants p"; |
||
| 85 | $whereClauses[] = "p.dttm >= '" . date("Y-m-d H:i:s", (int)$unixTime) . "'"; |
||
| 86 | } |
||
| 87 | if (array_key_exists("endTime", $parameters)) { |
||
| 88 | $time = $parameters["endTime"]; |
||
| 89 | $unixTime = strtotime($time); |
||
| 90 | $tables[] = "zz_participants p"; |
||
| 91 | $whereClauses[] = "p.dttm <= '" . date("Y-m-d H:i:s", (int)$unixTime) . "'"; |
||
| 92 | } |
||
| 93 | |||
| 94 | if (array_key_exists("pastSeconds", $parameters)) { |
||
| 95 | $tables[] = "zz_participants p"; |
||
| 96 | $whereClauses[] = "p.dttm >= date_sub(now(), interval " . ((int)$parameters["pastSeconds"]) . " second)"; |
||
| 97 | } |
||
| 98 | |||
| 99 | if (array_key_exists("iskValue", $parameters)) { |
||
| 100 | $tables[] = "zz_participants p"; |
||
| 101 | $whereClauses[] = "p.total_price >= '" . ((int)$parameters["iskValue"]) . "'"; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (array_key_exists("w-space", $parameters)) { |
||
| 105 | $tables[] = "zz_participants p"; |
||
| 106 | $whereClauses[] = "(regionID >= '11000001' and regionID <= '11000033')"; |
||
| 107 | } |
||
| 108 | |||
| 109 | if (array_key_exists("lowsec", $parameters)) { |
||
| 110 | $regions = array(); |
||
| 111 | $rows = Db::query("select distinct(regionID) as regionID from ccp_systems where security >= 0 and security <= 0.45", array(), 3600); |
||
| 112 | foreach($rows as $row) $regions[] = $row["regionID"]; |
||
| 113 | $tables[] = "zz_participants p"; |
||
| 114 | $whereClauses[] = " regionID in (" . implode(",", $regions) . ")"; |
||
| 115 | } |
||
| 116 | |||
| 117 | if (array_key_exists("highsec", $parameters)) { |
||
| 118 | $regions = array(); |
||
| 119 | $rows = Db::query("select distinct(regionID) as regionID from ccp_systems where security > 0.45", array(), 3600); |
||
| 120 | foreach($rows as $row) $regions[] = $row["regionID"]; |
||
| 121 | $tables[] = "zz_participants p"; |
||
| 122 | $whereClauses[] = " regionID in (" . implode(",", $regions) . ")"; |
||
| 123 | } |
||
| 124 | |||
| 125 | if (array_key_exists("nullsec", $parameters)) { |
||
| 126 | $regions = array(); |
||
| 127 | $rows = Db::query("select distinct(regionID) as regionID from ccp_systems where security < 0 and (regionID < 11000001 or regionID > 11000030)", array(), 3600); |
||
| 128 | foreach($rows as $row) $regions[] = $row["regionID"]; |
||
| 129 | $tables[] = "zz_participants p"; |
||
| 130 | $whereClauses[] = " regionID in (" . implode(",", $regions) . ")"; |
||
| 131 | } |
||
| 132 | |||
| 133 | if (array_key_exists("beforeKillID", $parameters)) { |
||
| 134 | $killID = (int)$parameters["beforeKillID"]; |
||
| 135 | $tables[] = "zz_participants p"; |
||
| 136 | $whereClauses[] = "p.killID < $killID"; |
||
| 137 | //$killdttm = Db::queryField("select dttm from zz_participants where killID = :killID limit 1", "dttm", array(":killID" => $killID)); |
||
| 138 | //$whereClauses[] = "p.dttm <= '$killdttm'"; |
||
| 139 | } |
||
| 140 | if (array_key_exists("afterKillID", $parameters)) { |
||
| 141 | $killID = (int)$parameters["afterKillID"]; |
||
| 142 | $tables[] = "zz_participants p"; |
||
| 143 | $whereClauses[] = "p.killID > $killID"; |
||
| 144 | //$killdttm = Db::queryField("select dttm from zz_participants where killID = :killID limit 1", "dttm", array(":killID" => $killID)); |
||
| 145 | //$whereClauses[] = "p.dttm >= '$killdttm'"; |
||
| 146 | } |
||
| 147 | if (array_key_exists("war", $parameters) || array_key_exists("warID", $parameters)) { |
||
| 148 | $warID = isset($parameters["war"]) ? (int)$parameters["war"] : (int)$parameters["warID"]; |
||
| 149 | $tables[] = "zz_participants p"; |
||
| 150 | $tables[] = "zz_warmails w"; |
||
| 151 | $whereClauses[] = "w.warID = $warID"; |
||
| 152 | } |
||
| 153 | |||
| 154 | $kills = array_key_exists("kills", $parameters); |
||
| 155 | $losses = array_key_exists("losses", $parameters); //|| (array_key_exists("solo", $parameters)); |
||
| 156 | if ((array_key_exists("mixed", $parameters) && $parameters["mixed"] == true) || array_key_exists("iskValue", $parameters)) { |
||
| 157 | } else if ($losses) { |
||
| 158 | $tables[] = $participants; |
||
| 159 | $whereClauses[] = "p.isVictim = '1'"; |
||
| 160 | } else if ($kills) { |
||
| 161 | $tables[] = $participants; |
||
| 162 | $whereClauses[] = "p.isVictim = '0'"; |
||
| 163 | } |
||
| 164 | |||
| 165 | $tables = array_unique($tables); |
||
| 166 | if (sizeof($tables) == 0) $tables[] = "zz_participants p"; |
||
| 167 | foreach ($tables as $table) { |
||
| 168 | $tablePrefix = substr($table, strlen($table) - 1, 1); |
||
| 169 | if (isset($year)) { |
||
| 170 | $whereClauses[] = "{$tablePrefix}.dttm >= '$year-01-01 00:00:00'"; |
||
| 171 | $whereClauses[] = "{$tablePrefix}.dttm <= '$year-12-31 23:59:59'"; |
||
| 172 | } |
||
| 173 | if (isset($week)) { |
||
| 174 | if (!isset($year)) throw new Exception("Must include a year when setting week!"); |
||
| 175 | $weekStart = date("Y-m-d H:i:00", strtotime("{$year}W{$week}")); |
||
| 176 | $whereClauses[] = "{$tablePrefix}.dttm >= '$weekStart'"; |
||
| 177 | $whereClauses[] = "{$tablePrefix}.dttm <= date_add('$weekStart', interval 7 day)"; |
||
| 178 | } |
||
| 179 | if (isset($month)) { |
||
| 180 | if (!isset($year)) throw new Exception("Must include a year when setting month!"); |
||
| 181 | $whereClauses[] = "{$tablePrefix}.dttm >= '$year-$month-01 00:00:00'"; |
||
| 182 | $whereClauses[] = "{$tablePrefix}.dttm <= '$year-$month-31 23:59:59'"; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 226 | } |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.