| Conditions | 33 |
| Paths | 381 |
| Total Lines | 133 |
| Code Lines | 86 |
| 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 |
||
| 93 | function onMessage($msgData, $message) |
||
| 94 | { |
||
| 95 | $channelID = (int)$msgData["message"]["channelID"]; |
||
| 96 | |||
| 97 | if (in_array($channelID, $this->excludeChannel, true)) { |
||
| 98 | return null; |
||
| 99 | } |
||
| 100 | |||
| 101 | $this->message = $message; |
||
| 102 | $userID = $msgData["message"]["fromID"]; |
||
| 103 | $userName = $msgData["message"]["from"]; |
||
| 104 | $message = $msgData["message"]["message"]; |
||
| 105 | $channelInfo = $this->message->channel; |
||
| 106 | $guildID = $channelInfo[@guild_id]; |
||
| 107 | $data = command($message, $this->information()["trigger"], $this->config["bot"]["trigger"]); |
||
| 108 | if (isset($data["trigger"])) { |
||
| 109 | if (isset($this->config["bot"]["primary"])) { |
||
| 110 | if ($guildID != $this->config["bot"]["primary"]) { |
||
| 111 | $this->message->reply("**Failure:** The auth code your attempting to use is for another discord server"); |
||
| 112 | return null; |
||
| 113 | } |
||
| 114 | |||
| 115 | } |
||
| 116 | // If config is outdated |
||
| 117 | if (is_null($this->authGroups)) { |
||
| 118 | $this->message->reply("**Failure:** Please update the bots config to the latest version."); |
||
| 119 | return null; |
||
| 120 | } |
||
| 121 | |||
| 122 | $code = $data["messageString"]; |
||
| 123 | $result = selectPending($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code); |
||
| 124 | |||
| 125 | if (strlen($code) < 12) { |
||
| 126 | $this->message->reply("Invalid Code, check " . $this->config["bot"]["trigger"] . "help auth for more info."); |
||
| 127 | return null; |
||
| 128 | } |
||
| 129 | |||
| 130 | while ($rows = $result->fetch_assoc()) { |
||
| 131 | $charID = (int)$rows['characterID']; |
||
| 132 | $corpID = (int)$rows['corporationID']; |
||
| 133 | $allianceID = (int)$rows['allianceID']; |
||
| 134 | $url = "https://api.eveonline.com/eve/CharacterName.xml.aspx?ids=$charID"; |
||
| 135 | $xmlCharacter = makeApiRequest($url); |
||
| 136 | |||
| 137 | |||
| 138 | // We have an error, show it it |
||
| 139 | if ($xmlCharacter->error) { |
||
| 140 | $this->message->reply("**Failure:** Eve API error, please try again in a little while."); |
||
| 141 | return null; |
||
| 142 | } |
||
| 143 | |||
| 144 | // Check that the api is working |
||
| 145 | if (!isset($xmlCharacter->result->rowset->row)) { |
||
| 146 | $this->message->reply("**Failure:** Eve API error, please try again in a little while."); |
||
| 147 | return null; |
||
| 148 | } |
||
| 149 | |||
| 150 | //Add corp ticker to name |
||
| 151 | if ($this->corpTickers == 'true') { |
||
| 152 | $url = "https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID={$corpID}"; |
||
| 153 | $xml = makeApiRequest($url); |
||
| 154 | $setTicker = 1; |
||
| 155 | foreach ($xml->result as $corporation) { |
||
| 156 | $corpTicker = $corporation->ticker; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | //Set eve name if nameCheck is true |
||
| 161 | if ($this->nameEnforce == "true") { |
||
| 162 | $nameEnforce = 1; |
||
| 163 | } |
||
| 164 | |||
| 165 | $allianceRoleSet = 0; |
||
| 166 | $corpRoleSet = 0; |
||
| 167 | |||
| 168 | foreach ($xmlCharacter->result->rowset->row as $character) { |
||
| 169 | $roles = $this->message->channel->guild->roles; |
||
| 170 | $member = $this->message->channel->guild->members->get("id", $userID); |
||
| 171 | $eveName = $character->attributes()->name; |
||
| 172 | foreach ($this->authGroups as $authGroup) { |
||
| 173 | //Check if corpID matches |
||
| 174 | if ($corpID === $authGroup["corpID"]) { |
||
| 175 | foreach ($roles as $role) { |
||
| 176 | if ($role->name == $authGroup["corpMemberRole"]) { |
||
| 177 | $member->addRole($role); |
||
| 178 | $corpRoleSet = 1; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | //Check if allianceID matches |
||
| 183 | if ($allianceID === $authGroup["allianceID"] && $authGroup["allianceID"] != 0) { |
||
| 184 | foreach ($roles as $role) { |
||
| 185 | if ($role->name == $authGroup["allyMemberRole"]) { |
||
| 186 | $member->addRole($role); |
||
| 187 | $allianceRoleSet = 1; |
||
| 188 | } |
||
| 189 | } |
||
| 190 | } |
||
| 191 | if ($allianceRoleSet == 1 || $corpRoleSet == 1) { |
||
| 192 | $guild = $this->discord->guilds->get('id', $guildID); |
||
| 193 | insertUser($this->db, $this->dbUser, $this->dbPass, $this->dbName, $userID, $charID, $eveName, 'corp'); |
||
| 194 | disableReg($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code); |
||
| 195 | $msg = ":white_check_mark: **Success:** {$userName} has been successfully authed."; |
||
| 196 | $this->logger->addInfo("auth: {$eveName} authed"); |
||
| 197 | priorityQueueMessage($msg, $channelID, $this->guild); |
||
| 198 | //Add ticker if set and change name if nameEnforce is on |
||
| 199 | if (isset($setTicker) || isset($nameEnforce)) { |
||
| 200 | if (isset($setTicker) && isset($nameEnforce)) { |
||
| 201 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 202 | } elseif (!isset($setTicker) && isset($nameEnforce)) { |
||
| 203 | $nick = "{$eveName}"; |
||
| 204 | } elseif (isset($setTicker) && !isset($nameEnforce)) { |
||
| 205 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 206 | } |
||
| 207 | } |
||
| 208 | if (isset($nick)) { |
||
| 209 | queueRename($userID, $nick, $this->guild); |
||
| 210 | } |
||
| 211 | $guild->members->save($member); |
||
| 212 | return null; |
||
| 213 | } |
||
| 214 | } |
||
| 215 | $this->message->reply("**Failure:** There are no roles available for your corp/alliance."); |
||
| 216 | $this->logger->addInfo("Auth: User was denied due to not being in the correct corp or alliance " . $eveName); |
||
| 217 | return null; |
||
| 218 | } |
||
| 219 | } |
||
| 220 | $this->message->reply("**Failure:** There was an issue with your code."); |
||
| 221 | $this->logger->addInfo("Auth: User was denied due to not being in the correct corp or alliance " . $userName); |
||
| 222 | return null; |
||
| 223 | } |
||
| 224 | return null; |
||
| 225 | } |
||
| 226 | |||
| 242 | } |
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.