| Conditions | 30 |
| Paths | 729 |
| Total Lines | 122 |
| Code Lines | 81 |
| 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 |
||
| 73 | public function onMessage($msgData, $message) |
||
| 74 | { |
||
| 75 | $channelID = (int) $msgData['message']['channelID']; |
||
| 76 | |||
| 77 | if (in_array($channelID, $this->excludeChannel, true)) { |
||
| 78 | return null; |
||
| 79 | } |
||
| 80 | |||
| 81 | $this->message = $message; |
||
| 82 | $userID = $msgData['message']['fromID']; |
||
| 83 | $userName = $msgData['message']['from']; |
||
| 84 | $message = $msgData['message']['message']; |
||
| 85 | $channelInfo = $this->message->channel; |
||
| 86 | $guildID = $channelInfo[@guild_id]; |
||
| 87 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
||
| 88 | if (isset($data['trigger'])) { |
||
| 89 | if (isset($this->config['bot']['primary'])) { |
||
| 90 | if ($guildID != $this->config['bot']['primary']) { |
||
| 91 | $this->message->reply('**Failure:** The auth code your attempting to use is for another discord server'); |
||
| 92 | return null; |
||
| 93 | } |
||
| 94 | |||
| 95 | } |
||
| 96 | // If config is outdated |
||
| 97 | if (null === $this->authGroups) { |
||
| 98 | $this->message->reply('**Failure:** Please update the bots config to the latest version.'); |
||
| 99 | return null; |
||
| 100 | } |
||
| 101 | |||
| 102 | $code = $data['messageString']; |
||
| 103 | $result = selectPending($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code); |
||
| 104 | |||
| 105 | if (strlen($code) < 12) { |
||
| 106 | $this->message->reply('Invalid Code, check ' . $this->config['bot']['trigger'] . 'help auth for more info.'); |
||
| 107 | return null; |
||
| 108 | } |
||
| 109 | |||
| 110 | while ($rows = $result->fetch_assoc()) { |
||
| 111 | $charID = (int) $rows['characterID']; |
||
| 112 | $corpID = (int) $rows['corporationID']; |
||
| 113 | $allianceID = (int) $rows['allianceID']; |
||
| 114 | |||
| 115 | //If corp is new store in DB |
||
| 116 | $corpInfo = getCorpInfo($corpID); |
||
| 117 | if (null === $corpInfo) { |
||
| 118 | $corpDetails = corpDetails($corpID); |
||
| 119 | $corpTicker = $corpDetails['ticker']; |
||
| 120 | $corpName = corpName($corpID); |
||
| 121 | addCorpInfo($corpID, $corpTicker, $corpName); |
||
| 122 | } else { |
||
| 123 | $corpTicker = $corpInfo['corpTicker']; |
||
| 124 | } |
||
| 125 | |||
| 126 | //Add corp ticker to name |
||
| 127 | if ($this->corpTickers === 'true') { |
||
| 128 | $setTicker = 1; |
||
| 129 | } |
||
| 130 | |||
| 131 | //Set eve name if nameCheck is true |
||
| 132 | if ($this->nameEnforce === 'true') { |
||
| 133 | $nameEnforce = 1; |
||
| 134 | } |
||
| 135 | |||
| 136 | $allianceRoleSet = 0; |
||
| 137 | $corpRoleSet = 0; |
||
| 138 | |||
| 139 | $roles = @$this->message->channel->guild->roles; |
||
| 140 | $member = @$this->message->channel->guild->members->get('id', $userID); |
||
| 141 | $eveName = characterName($charID); |
||
| 142 | foreach ($this->authGroups as $authGroup) { |
||
| 143 | //Check if corpID matches |
||
| 144 | if ($corpID === $authGroup['corpID']) { |
||
| 145 | foreach ($roles as $role) { |
||
| 146 | if ((string)$role->name === (string)$authGroup['corpMemberRole']) { |
||
| 147 | $member->addRole($role); |
||
| 148 | $corpRoleSet = 1; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | } |
||
| 152 | //Check if allianceID matches |
||
| 153 | if ($allianceID === $authGroup['allianceID'] && $authGroup['allianceID'] != 0) { |
||
| 154 | foreach ($roles as $role) { |
||
| 155 | if ((string)$role->name === (string)$authGroup['allyMemberRole']) { |
||
| 156 | $member->addRole($role); |
||
| 157 | $allianceRoleSet = 1; |
||
| 158 | } |
||
| 159 | } |
||
| 160 | } |
||
| 161 | if ($allianceRoleSet === 1 || $corpRoleSet === 1) { |
||
| 162 | $guild = $this->discord->guilds->get('id', $guildID); |
||
| 163 | insertUser($this->db, $this->dbUser, $this->dbPass, $this->dbName, $userID, $charID, $eveName, 'corp'); |
||
| 164 | disableReg($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code); |
||
| 165 | $msg = ":white_check_mark: **Success:** {$userName} has been successfully authed."; |
||
| 166 | $this->logger->addInfo("auth: {$eveName} authed"); |
||
| 167 | $this->message->reply($msg); |
||
| 168 | //Add ticker if set and change name if nameEnforce is on |
||
| 169 | if (isset($setTicker) || isset($nameEnforce)) { |
||
| 170 | if (isset($setTicker) && isset($nameEnforce)) { |
||
| 171 | $nick = "[{$corpTicker}] {$eveName}"; |
||
| 172 | } elseif (null === $setTicker && isset($nameEnforce)) { |
||
| 173 | $nick = "{$eveName}"; |
||
| 174 | } elseif (isset($setTicker) && !isset($nameEnforce)) { |
||
| 175 | $nick = "[{$corpTicker}] {$userName}"; |
||
| 176 | } |
||
| 177 | } |
||
| 178 | if (null !== $nick) { |
||
| 179 | queueRename($userID, $nick, $this->guild); |
||
| 180 | } |
||
| 181 | $guild->members->save($member); |
||
| 182 | return null; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | $this->message->reply('**Failure:** There are no roles available for your corp/alliance.'); |
||
| 186 | $this->logger->addInfo('Auth: User was denied due to not being in the correct corp or alliance ' . $eveName); |
||
| 187 | return null; |
||
| 188 | } |
||
| 189 | $this->message->reply('**Failure:** There was an issue with your code.'); |
||
| 190 | $this->logger->addInfo('Auth: User was denied due to the code being invalid ' . $userName); |
||
| 191 | return null; |
||
| 192 | } |
||
| 193 | return null; |
||
| 194 | } |
||
| 195 | |||
| 208 |
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.