| Conditions | 14 |
| Paths | 21 |
| Total Lines | 87 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 57 | public function onMessage($msgData, $message) |
||
| 58 | { |
||
| 59 | $channelID = (int) $msgData['message']['channelID']; |
||
| 60 | |||
| 61 | if (in_array($channelID, $this->excludeChannel, true)) |
||
| 62 | { |
||
| 63 | return null; |
||
| 64 | } |
||
| 65 | |||
| 66 | $this->message = $message; |
||
| 67 | |||
| 68 | $message = $msgData['message']['message']; |
||
| 69 | $user = $msgData['message']['from']; |
||
| 70 | |||
| 71 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
||
| 72 | if (isset($data['trigger'])) { |
||
| 73 | |||
| 74 | // Most EVE players on Discord use their ingame name, so lets support @highlights |
||
| 75 | $messageString = strstr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
||
| 76 | if (is_numeric($messageString)) { |
||
| 77 | // The person used @highlighting, so now we got a discord id, lets map that to a name |
||
| 78 | $messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', array(':id' => $messageString)); |
||
| 79 | } |
||
| 80 | |||
| 81 | $cleanString = urlencode($messageString); |
||
| 82 | $characterID = urlencode(characterID($cleanString)); |
||
| 83 | |||
| 84 | if (empty($characterID)) { |
||
| 85 | return $this->message->reply('**Error:** no data available'); |
||
| 86 | } |
||
| 87 | |||
| 88 | //Get details |
||
| 89 | $characterDetails = characterDetails($characterID); |
||
| 90 | if (null === $characterDetails) { |
||
| 91 | return $this->message->reply('**Error:** ESI is down. Try again later.'); |
||
| 92 | } |
||
| 93 | $corporationID = $characterDetails['corporation_id']; |
||
| 94 | $corporationName = corpName($corporationID); |
||
| 95 | if (null === $corporationName) { |
||
| 96 | return $this->message->reply('**Error:** ESI is down. Try again later.'); |
||
| 97 | } |
||
| 98 | $corporationDetails = corpDetails($corporationID); |
||
| 99 | $allianceID = $corporationDetails['alliance_id']; |
||
| 100 | $allianceName = allianceName($allianceID); |
||
| 101 | $characterName = $characterDetails['name']; |
||
| 102 | $dateOfBirth = $characterDetails['birthday']; |
||
| 103 | |||
| 104 | if ($characterName === null || $characterName === '') { |
||
| 105 | return $this->message->reply('**Error:** No character found.'); |
||
| 106 | } |
||
| 107 | |||
| 108 | //ZKill lookup |
||
| 109 | $url = "https://zkillboard.com/api/orderDirection/desc/limit/1/no-items/characterID/{$characterID}/xml/"; |
||
| 110 | $xml = makeApiRequest($url); |
||
| 111 | if (empty($xml)) { |
||
| 112 | return $this->message->reply('**Error:** ZKill is down. Try again later.'); |
||
| 113 | } |
||
| 114 | foreach ($xml->result->rowset->row as $kill) { |
||
| 115 | $lastSeenSystemID = $kill->attributes()->solarSystemID; |
||
| 116 | $lastSeenSystem = systemName($lastSeenSystemID); |
||
| 117 | $lastSeenDate = $kill->attributes()->killTime; |
||
| 118 | } |
||
| 119 | foreach ($xml->result->rowset->row->rowset->row as $attacker) { |
||
| 120 | if ($attacker->attributes()->characterID == $characterID) { |
||
| 121 | $lastSeenShipID = $attacker->attributes()->shipTypeID; |
||
| 122 | $lastSeenShip = apiTypeName($lastSeenShipID); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | $url = "https://zkillboard.com/character/{$characterID}/"; |
||
| 126 | |||
| 127 | $msg = "```Name: {$characterName} |
||
| 128 | DOB: {$dateOfBirth} |
||
| 129 | |||
| 130 | Corporation Name: {$corporationName} |
||
| 131 | Alliance Name: {$allianceName} |
||
| 132 | |||
| 133 | Last Seen In System: {$lastSeenSystem} |
||
| 134 | Last Seen Flying a: {$lastSeenShip} |
||
| 135 | Last Seen On: {$lastSeenDate}``` |
||
| 136 | |||
| 137 | For more info, visit: $url"; |
||
| 138 | |||
| 139 | $this->logger->addInfo("charInfo: Sending character info to {$user}"); |
||
| 140 | $this->message->reply($msg); |
||
| 141 | } |
||
| 142 | return null; |
||
| 143 | } |
||
| 144 | |||
| 158 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.