Conditions | 55 |
Paths | 16386 |
Total Lines | 166 |
Code Lines | 115 |
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 |
||
246 | public static function getRawMail($killID, $array = array(), $edk = true) |
||
247 | { |
||
248 | $cacheName = $killID; |
||
249 | $sem = Semaphore::fetch($killID); |
||
250 | if($edk) |
||
251 | $cacheName = $killID."EDK"; |
||
252 | |||
253 | // Check if the mail has already been generated, then return it from the cache.. |
||
254 | $Cache = Cache::get($cacheName); |
||
255 | if($Cache) { |
||
256 | Semaphore::release($sem); |
||
257 | return $Cache; |
||
258 | } |
||
259 | |||
260 | // Find all groupIDs where they contain Deadspace |
||
261 | $deadspaceIDs = array(); |
||
262 | $dIDs = Db::query("SELECT groupID FROM ccp_invGroups WHERE groupName LIKE '%deadspace%' OR groupName LIKE 'FW%' OR groupName LIKE 'Asteroid%'"); |
||
263 | foreach($dIDs as $dd) |
||
264 | $deadspaceIDs[] = $dd["groupID"]; |
||
265 | |||
266 | // ADD ALL THE FLAGS!!!!!!!!!!! |
||
267 | //$flags = array("(Cargo)" => 5, "(Drone Bay)" => 87, "(Implant)" => 89); |
||
268 | $dbFlags = Db::query("SELECT flagText, flagID FROM ccp_invFlags", array(), 3600); |
||
269 | $flags = array(); |
||
270 | foreach($dbFlags as $f) |
||
271 | $flags[(int) $f["flagID"]] = $f["flagText"]; |
||
272 | |||
273 | if(!$array) |
||
274 | $k = self::getArray($killID); |
||
275 | else |
||
276 | $k = $array; |
||
277 | |||
278 | $mail = $k["killTime"] . "\n"; |
||
279 | $mail .= "\n"; |
||
280 | $mail .= "Victim: " . $k["victim"]["characterName"] . "\n"; |
||
281 | $mail .= "Corp: " . $k["victim"]["corporationName"] . "\n"; |
||
282 | if (!isset($k["victim"]["allianceName"]) || $k["victim"]["allianceName"] == "") |
||
283 | $k["victim"]["allianceName"] = "None"; |
||
284 | $mail .= "Alliance: " . $k["victim"]["allianceName"] . "\n"; |
||
285 | if (!isset($k["victim"]["factionName"]) || $k["victim"]["factionName"] == "") |
||
286 | $k["victim"]["factionName"] = "None"; |
||
287 | $mail .= "Faction: " . $k["victim"]["factionName"] . "\n"; |
||
288 | if (!isset($k["victim"]["shipName"]) || $k["victim"]["shipName"] == "") |
||
289 | $k["victim"]["shipName"] = "None"; |
||
290 | $mail .= "Destroyed: " . $k["victim"]["shipName"] . "\n"; |
||
291 | if (!isset($k["solarSystemName"]) || $k["solarSystemName"] == "") |
||
292 | $k["solarSystemName"] = "None"; |
||
293 | $mail .= "System: " . $k["solarSystemName"] . "\n"; |
||
294 | if (!isset($k["solarSystemSecurity"]) || $k["solarSystemSecurity"] == "") |
||
295 | $k["solarSystemSecurity"] = (int) 0; |
||
296 | $mail .= "Security: " . $k["solarSystemSecurity"] . "\n"; |
||
297 | if (!isset($k["victim"]["damageTaken"]) || $k["victim"]["damageTaken"] == "") |
||
298 | $k["victim"]["damageTaken"] = (int) 0; |
||
299 | $mail .= "Damage Taken: " . $k["victim"]["damageTaken"] . "\n\n"; |
||
300 | if(isset($k["attackers"])) |
||
301 | { |
||
302 | $mail .= "Involved parties:\n\n"; |
||
303 | foreach ($k["attackers"] as $inv) |
||
304 | { |
||
305 | // find groupID for the ship |
||
306 | if(!isset($inv["shipName"])) $inv["shipName"] = "Unknown"; |
||
307 | $groupID = Db::queryField("SELECT groupID FROM ccp_invTypes WHERE typeName LIKE :shipName", "groupID", array(":shipName" => $inv["shipName"])); |
||
308 | if(in_array($groupID, $deadspaceIDs)) |
||
309 | { |
||
310 | // shipName isn't set, but it's an npc.. fml.. |
||
311 | if ($inv["finalBlow"] == 1) |
||
312 | $mail .= "Name: ". $inv["shipName"] . " / " . $inv["corporationName"] . " (laid the final blow)\n"; |
||
313 | else |
||
314 | $mail .= "Name: ". $inv["shipName"] . " / " . $inv["corporationName"] . "\n"; |
||
315 | $mail .= "Damage Done: " . $inv["damageDone"] . "\n\n"; |
||
316 | } |
||
317 | else |
||
318 | { |
||
319 | if ($inv["finalBlow"] == 1) |
||
320 | $mail .= "Name: " . $inv["characterName"] . " (laid the final blow)\n"; |
||
321 | else if (strlen($inv["characterName"])) |
||
322 | $mail .= "Name: " . $inv["characterName"] . "\n"; |
||
323 | if (strlen($inv["characterName"])) $mail .= "Security: " . $inv["securityStatus"] . "\n"; |
||
324 | $mail .= "Corp: " . $inv["corporationName"] . "\n"; |
||
325 | if (!isset($inv["allianceName"]) || $inv["allianceName"] == "") |
||
326 | $inv["allianceName"] = "None"; |
||
327 | $mail .= "Alliance: " . $inv["allianceName"] . "\n"; |
||
328 | if (!isset($inv["factionName"]) || $inv["factionName"] == "") |
||
329 | $inv["factionName"] = "None"; |
||
330 | $mail .= "Faction: " . $inv["factionName"] . "\n"; |
||
331 | if (!isset($inv["shipName"]) || $inv["shipName"] == "") |
||
332 | $inv["shipName"] = "None"; |
||
333 | $mail .= "Ship: " . $inv["shipName"] . "\n"; |
||
334 | if (!isset($inv["weaponName"]) || $inv["weaponName"] == "") |
||
335 | $inv["weaponName"] = $inv["shipName"]; |
||
336 | $mail .= "Weapon: " . $inv["weaponName"] . "\n"; |
||
337 | $mail .= "Damage Done: " . $inv["damageDone"] . "\n\n"; |
||
338 | } |
||
339 | } |
||
340 | } |
||
341 | |||
342 | $mail .= "\n"; |
||
343 | $dropped = array(); |
||
344 | $destroyed = array(); |
||
345 | if(isset($k["items"])) |
||
346 | { |
||
347 | foreach($k["items"] as $itm) |
||
348 | { |
||
349 | // Take the flags we get from $itemToSlot and replace it with the proper flag from the database |
||
350 | if (!(isset($itm["flag"]) && isset($flags[$itm["flag"]]))) continue; |
||
351 | $itm["flagName"] = $flags[$itm["flag"]]; |
||
352 | |||
353 | // create the flag! |
||
354 | $copy = null; |
||
355 | if($itm["singleton"] == 2) |
||
356 | $copy = " (Copy)"; |
||
357 | |||
358 | $edkValidFlags = array("Cargo", "Drone Bay"); |
||
359 | if($edk && !in_array($itm["flagName"], $edkValidFlags)) |
||
360 | $flagName = null; |
||
361 | else |
||
362 | $flagName = " (". $itm["flagName"] . ")"; |
||
363 | |||
364 | |||
365 | if($itm["qtyDropped"]) // go to dropped list |
||
366 | { |
||
367 | $line = $itm["typeName"] . ", Qty: " . $itm["qtyDropped"] . $flagName . ($copy ? $copy : null); |
||
368 | $dropped[] = $line; |
||
369 | } |
||
370 | |||
371 | if($itm["qtyDestroyed"]) // go to destroyed list |
||
372 | { |
||
373 | $line = $itm["typeName"] . ", Qty: " . $itm["qtyDestroyed"] . $flagName . ($copy ? $copy : null); |
||
374 | $destroyed[] = $line; |
||
375 | } |
||
376 | |||
377 | if(isset($itm["items"])) |
||
378 | foreach($itm["items"] as $key => $sub) |
||
379 | { |
||
380 | if($sub["qtyDropped"]) // go to dropped list |
||
381 | { |
||
382 | $line = $sub["typeName"] . ", Qty: " . $sub["qtyDropped"] . $flagName . ($copy ? $copy : null) . " (In Container)"; |
||
383 | $dropped[] = $line; |
||
384 | } |
||
385 | if($sub["qtyDestroyed"]) // go to destroyed list |
||
386 | { |
||
387 | $line = $sub["typeName"] . ", Qty: " . $sub["qtyDestroyed"] . $flagName . ($copy ? $copy : null) . " (In Container)"; |
||
388 | $destroyed[] = $line; |
||
389 | } |
||
390 | } |
||
391 | } |
||
392 | } |
||
393 | |||
394 | if ($destroyed) { |
||
395 | $mail .= "Destroyed items:\n\n"; |
||
396 | foreach ($destroyed as $items) |
||
397 | $mail .= $items . "\n"; |
||
398 | } |
||
399 | $mail .= "\n"; |
||
400 | if ($dropped) { |
||
401 | $mail .= "Dropped items:\n\n"; |
||
402 | foreach ($dropped as $items) |
||
403 | $mail .= $items . "\n"; |
||
404 | } |
||
405 | |||
406 | // Store the generated mail in cache |
||
407 | Cache::set($cacheName, $mail, 604800); |
||
408 | |||
409 | Semaphore::release($sem); |
||
410 | return $mail; |
||
411 | } |
||
412 | |||
419 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.