| Conditions | 58 | 
| Paths | > 20000 | 
| Total Lines | 182 | 
| Code Lines | 123 | 
| Lines | 32 | 
| Ratio | 17.58 % | 
| 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  | 
            ||
| 78 | public function onMessage($msgData, $message)  | 
            ||
| 79 |     { | 
            ||
| 80 | $channelID = (int) $msgData['message']['channelID'];  | 
            ||
| 81 | |||
| 82 |         if (in_array($channelID, $this->excludeChannel, true)) { | 
            ||
| 83 | return null;  | 
            ||
| 84 | }  | 
            ||
| 85 | |||
| 86 | $this->message = $message;  | 
            ||
| 87 | $userID = $msgData['message']['fromID'];  | 
            ||
| 88 | $userName = $msgData['message']['from'];  | 
            ||
| 89 | $message = $msgData['message']['message'];  | 
            ||
| 90 | $guildID = $this->guild;  | 
            ||
| 91 |         $guild = $this->discord->guilds->get('id', $guildID); | 
            ||
| 92 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']);  | 
            ||
| 93 |         if (isset($data['trigger'])) { | 
            ||
| 94 | |||
| 95 | // If config is outdated  | 
            ||
| 96 |             if (null === $this->authGroups) { | 
            ||
| 97 |                 $this->message->reply('**Failure:** Please update the bots config to the latest version.'); | 
            ||
| 98 | return null;  | 
            ||
| 99 | }  | 
            ||
| 100 | |||
| 101 | $code = $data['messageString'];  | 
            ||
| 102 | $result = selectPending($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code);  | 
            ||
| 103 | |||
| 104 |             if (strlen($code) < 12) { | 
            ||
| 105 |                 $this->message->reply('Invalid Code, check ' . $this->config['bot']['trigger'] . 'help auth for more info.'); | 
            ||
| 106 | return null;  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 |             while ($rows = $result->fetch_assoc()) { | 
            ||
| 110 | $charID = (int) $rows['characterID'];  | 
            ||
| 111 | $corpID = (int) $rows['corporationID'];  | 
            ||
| 112 | $allianceID = (int) $rows['allianceID'];  | 
            ||
| 113 | |||
| 114 | //If corp is new store in DB  | 
            ||
| 115 | $corpInfo = getCorpInfo($corpID);  | 
            ||
| 116 |                 if (null === $corpInfo) { | 
            ||
| 117 | $corpDetails = corpDetails($corpID);  | 
            ||
| 118 |                     if (null === $corpDetails) { // Make sure it's always set. | 
            ||
| 119 |                         $this->message->reply('**Failure:** Unable to auth at this time, ESI is down. Please try again later.'); | 
            ||
| 120 | return null;  | 
            ||
| 121 | }  | 
            ||
| 122 | $corpTicker = $corpDetails['ticker'];  | 
            ||
| 123 | $corpName = (string) $corpDetails['corporation_name'];  | 
            ||
| 124 |                     if (null !== $corpTicker) { | 
            ||
| 125 | addCorpInfo($corpID, $corpTicker, $corpName);  | 
            ||
| 126 | }  | 
            ||
| 127 |                 } else { | 
            ||
| 128 | $corpTicker = $corpInfo['corpTicker'];  | 
            ||
| 129 | }  | 
            ||
| 130 | |||
| 131 | //Add corp ticker to name  | 
            ||
| 132 |                 if ($this->corpTickers === 'true') { | 
            ||
| 133 | $setTicker = 1;  | 
            ||
| 134 | }  | 
            ||
| 135 | |||
| 136 | //Set eve name if nameCheck is true  | 
            ||
| 137 |                 if ($this->nameEnforce === 'true') { | 
            ||
| 138 | $nameEnforce = 1;  | 
            ||
| 139 | }  | 
            ||
| 140 | $role = null;  | 
            ||
| 141 | |||
| 142 | $roles = @$guild->roles;  | 
            ||
| 143 |                 $member = @$guild->members->get('id', $userID); | 
            ||
| 144 |                 if (null === $member) { | 
            ||
| 145 |                     $this->message->reply("**Failure:** You're not a member of the correct guild."); | 
            ||
| 146 | return null;  | 
            ||
| 147 | }  | 
            ||
| 148 | $eveName = characterName($charID);  | 
            ||
| 149 |                 if (null === $eveName) { | 
            ||
| 150 |                     $this->message->reply('**Failure:** Unable to auth at this time, ESI is down. Please try again later.'); | 
            ||
| 151 | return null;  | 
            ||
| 152 | }  | 
            ||
| 153 |                 foreach ($this->authGroups as $authGroup) { | 
            ||
| 154 | //Check if it's set to match corp and alliance  | 
            ||
| 155 |                     if ($authGroup['corpID'] !== 0 && $authGroup['allianceID'] !== 0) { | 
            ||
| 156 | //Check if corpID matches  | 
            ||
| 157 |                         if ($corpID === $authGroup['corpID'] && $allianceID === $authGroup['allianceID']) { | 
            ||
| 158 |                             foreach ($roles as $role) { | 
            ||
| 159 |                                 if ((string) $role->name === (string) $authGroup['corpMemberRole']) { | 
            ||
| 160 | $member->addRole($role);  | 
            ||
| 161 | }  | 
            ||
| 162 |                                 if ((string) $role->name === (string) $authGroup['allyMemberRole']) { | 
            ||
| 163 | $member->addRole($role);  | 
            ||
| 164 | $role = 'corp/ally';  | 
            ||
| 165 | }  | 
            ||
| 166 | }  | 
            ||
| 167 | break;  | 
            ||
| 168 | }  | 
            ||
| 169 |                     } elseif ($authGroup['corpID'] !== 0 || $authGroup['allianceID'] !== 0) { | 
            ||
| 170 | //Check if corpID matches  | 
            ||
| 171 |                         if ($corpID === $authGroup['corpID']) { | 
            ||
| 172 | View Code Duplication |                             foreach ($roles as $role) { | 
            |
| 173 |                                 if ((string) $role->name === (string) $authGroup['corpMemberRole']) { | 
            ||
| 174 | $member->addRole($role);  | 
            ||
| 175 | $role = 'corp';  | 
            ||
| 176 | }  | 
            ||
| 177 | }  | 
            ||
| 178 | break;  | 
            ||
| 179 | }  | 
            ||
| 180 | //Check if allianceID matches  | 
            ||
| 181 |                         if ($allianceID === $authGroup['allianceID'] && $authGroup['allianceID'] !== 0) { | 
            ||
| 182 | View Code Duplication |                             foreach ($roles as $role) { | 
            |
| 183 |                                 if ((string) $role->name === (string) $authGroup['allyMemberRole']) { | 
            ||
| 184 | $member->addRole($role);  | 
            ||
| 185 | $role = 'ally';  | 
            ||
| 186 | }  | 
            ||
| 187 | }  | 
            ||
| 188 | break;  | 
            ||
| 189 | }  | 
            ||
| 190 | }  | 
            ||
| 191 | }  | 
            ||
| 192 | //check for standings based roles  | 
            ||
| 193 |                 if ($this->standingsBased === 'true' && $role === null) { | 
            ||
| 194 | $allianceContacts = getContacts($allianceID);  | 
            ||
| 195 | $corpContacts = getContacts($corpID);  | 
            ||
| 196 |                     foreach ($roles as $role) { | 
            ||
| 197 | View Code Duplication |                         if ((@(int) $allianceContacts['standing'] === 5 || @(int) $corpContacts['standing'] === 5) && (string) $role->name === (string) $this->config['plugins']['auth']['standings']['plus5Role']) { | 
            |
| 198 | $member->addRole($role);  | 
            ||
| 199 | $role = 'blue';  | 
            ||
| 200 | break;  | 
            ||
| 201 | }  | 
            ||
| 202 | View Code Duplication |                         if ((@(int) $allianceContacts['standing'] === 10 || @(int) $corpContacts['standing'] === 10) && (string) $role->name === (string) $this->config['plugins']['auth']['standings']['plus10Role']) { | 
            |
| 203 | $member->addRole($role);  | 
            ||
| 204 | $role = 'blue';  | 
            ||
| 205 | break;  | 
            ||
| 206 | }  | 
            ||
| 207 | View Code Duplication |                         if ((@(int) $allianceContacts['standing'] === -5 || @(int) $corpContacts['standing'] === -5) && (string) $role->name === (string) $this->config['plugins']['auth']['standings']['minus5Role']) { | 
            |
| 208 | $member->addRole($role);  | 
            ||
| 209 | $role = 'red';  | 
            ||
| 210 | break;  | 
            ||
| 211 | }  | 
            ||
| 212 | View Code Duplication |                         if ((@(int) $allianceContacts['standing'] === -10 || @(int) $corpContacts['standing'] === -10) && (string) $role->name === (string) $this->config['plugins']['auth']['standings']['minus10Role']) { | 
            |
| 213 | $member->addRole($role);  | 
            ||
| 214 | $role = 'red';  | 
            ||
| 215 | break;  | 
            ||
| 216 | }  | 
            ||
| 217 | }  | 
            ||
| 218 |                     if ($role === null) { | 
            ||
| 219 |                         foreach ($roles as $role) { | 
            ||
| 220 |                             if ((string) $role->name === (string) $this->config['plugins']['auth']['standings']['neutralRole']) { | 
            ||
| 221 | $member->addRole($role);  | 
            ||
| 222 | $role = 'neut';  | 
            ||
| 223 | break;  | 
            ||
| 224 | }  | 
            ||
| 225 | }  | 
            ||
| 226 | }  | 
            ||
| 227 | }  | 
            ||
| 228 |                 if (null !== $role) { | 
            ||
| 229 | $guild->members->save($member);  | 
            ||
| 230 | insertUser($this->db, $this->dbUser, $this->dbPass, $this->dbName, $userID, $charID, $eveName, $role);  | 
            ||
| 231 | disableReg($this->db, $this->dbUser, $this->dbPass, $this->dbName, $code);  | 
            ||
| 232 |                     $msg = ":white_check_mark: **Success:** {$eveName} has been successfully authed."; | 
            ||
| 233 |                     $this->logger->addInfo("auth: {$eveName} authed"); | 
            ||
| 234 | $this->message->reply($msg);  | 
            ||
| 235 | //Add ticker if set and change name if nameEnforce is on  | 
            ||
| 236 |                     if (isset($setTicker) || isset($nameEnforce)) { | 
            ||
| 237 |                         if (isset($setTicker) && isset($nameEnforce)) { | 
            ||
| 238 |                             $nick = "[{$corpTicker}] {$eveName}"; | 
            ||
| 239 |                         } elseif (null === $setTicker && isset($nameEnforce)) { | 
            ||
| 240 |                             $nick = "{$eveName}"; | 
            ||
| 241 |                         } elseif (isset($setTicker) && !isset($nameEnforce)) { | 
            ||
| 242 |                             $nick = "[{$corpTicker}] {$userName}"; | 
            ||
| 243 | }  | 
            ||
| 244 | }  | 
            ||
| 245 |                     if (null !== $nick) { | 
            ||
| 246 | queueRename($userID, $nick, $this->guild);  | 
            ||
| 247 | }  | 
            ||
| 248 | return null;  | 
            ||
| 249 | }  | 
            ||
| 250 |                 $this->message->reply('**Failure:** There are no roles available for your corp/alliance.'); | 
            ||
| 251 |                 $this->logger->addInfo('Auth: User was denied due to not being in the correct corp or alliance ' . $eveName); | 
            ||
| 252 | return null;  | 
            ||
| 253 | }  | 
            ||
| 254 |             $this->message->reply('**Failure:** There was an issue with your code.'); | 
            ||
| 255 |             $this->logger->addInfo('Auth: User was denied due to the code being invalid ' . $userName); | 
            ||
| 256 | return null;  | 
            ||
| 257 | }  | 
            ||
| 258 | return null;  | 
            ||
| 259 | }  | 
            ||
| 260 | |||
| 273 | 
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.