| Conditions | 16 |
| Paths | 396 |
| Total Lines | 86 |
| Code Lines | 55 |
| 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 |
||
| 21 | public static function beSocial($killID) |
||
| 22 | { |
||
| 23 | global $beSocial; |
||
| 24 | if (!isset($beSocial)) |
||
| 25 | $beSocial = false; |
||
| 26 | |||
| 27 | if ($beSocial == false) |
||
|
|
|||
| 28 | return; |
||
| 29 | |||
| 30 | if ($killID < 0) |
||
| 31 | return; |
||
| 32 | |||
| 33 | $ircMin = 5000000000; |
||
| 34 | $twitMin = 10000000000; |
||
| 35 | |||
| 36 | $count = Db::queryField("select count(*) count from zz_social where killID = :killID", "count", array(":killID" => $killID), 0); |
||
| 37 | if ($count != 0) |
||
| 38 | return; |
||
| 39 | |||
| 40 | // Get victim info |
||
| 41 | $victimInfo = Db::queryRow("select * from zz_participants where dttm >= date_sub(now(), interval 1 day) and killID = :killID and isVictim = 1", array(":killID" => $killID)); |
||
| 42 | if ($victimInfo == null) |
||
| 43 | return; |
||
| 44 | |||
| 45 | $totalPrice = $victimInfo["total_price"]; |
||
| 46 | |||
| 47 | Info::addInfo($victimInfo); |
||
| 48 | |||
| 49 | // Reduce spam of freighters and jump freighters |
||
| 50 | $shipGroupID = $victimInfo["groupID"]; |
||
| 51 | if (in_array($shipGroupID, array(513, 902))) |
||
| 52 | { |
||
| 53 | $shipPrice = Price::getItemPrice($victimInfo["shipTypeID"], $victimInfo["dttm"]); |
||
| 54 | $ircMin += $shipPrice; |
||
| 55 | $twitMin += $shipPrice; |
||
| 56 | } |
||
| 57 | |||
| 58 | $worthIt = false; |
||
| 59 | $worthIt |= $totalPrice >= $ircMin; |
||
| 60 | if (!$worthIt) |
||
| 61 | return; |
||
| 62 | |||
| 63 | $tweetIt = false; |
||
| 64 | $tweetIt |= $totalPrice >= $twitMin; |
||
| 65 | |||
| 66 | global $fullAddr, $twitterName; |
||
| 67 | $url = "$fullAddr/kill/$killID/"; |
||
| 68 | |||
| 69 | if ($url == "") |
||
| 70 | $url = "$fullAddr/kill/$killID/"; |
||
| 71 | |||
| 72 | $message = "|g|" . $victimInfo["shipName"] . "|n| worth |r|" . Util::formatIsk($totalPrice) . " ISK|n| was destroyed! $url"; |
||
| 73 | |||
| 74 | if (!isset($victimInfo["characterName"])) |
||
| 75 | $victimInfo["characterName"] = $victimInfo["corporationName"]; |
||
| 76 | |||
| 77 | if (strlen($victimInfo["characterName"]) < 25) |
||
| 78 | { |
||
| 79 | $name = $victimInfo["characterName"]; |
||
| 80 | if (Util::endsWith($name, "s")) |
||
| 81 | $name .= "'"; |
||
| 82 | else |
||
| 83 | $name .= "'s"; |
||
| 84 | |||
| 85 | $message = "$name $message"; |
||
| 86 | } |
||
| 87 | |||
| 88 | Db::execute("insert into zz_social (killID) values (:killID)", array(":killID" => $killID)); |
||
| 89 | |||
| 90 | Log::irc("$message"); |
||
| 91 | $message = Log::stripIRCColors($message); |
||
| 92 | |||
| 93 | $message .= " #tweetfleet #eveonline"; |
||
| 94 | if (strlen($message) > 120) |
||
| 95 | $message = str_replace(" worth ", ": ", $message); |
||
| 96 | |||
| 97 | if (strlen($message) > 120) |
||
| 98 | $message = str_replace(" was destroyed!", "", $message); |
||
| 99 | |||
| 100 | if ($tweetIt && strlen($message) <= 120) |
||
| 101 | { |
||
| 102 | $ret = Twit::sendMessage($message); |
||
| 103 | $twit = "https://twitter.com/{$twitterName}/status/" . $ret->id; |
||
| 104 | Log::irc("Message was also tweeted: |g|$twit"); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | } |
||
| 108 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.