| Conditions | 6 |
| Paths | 5 |
| Total Lines | 52 |
| Code Lines | 34 |
| 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 |
||
| 55 | public function onMessage($msgData, $message) |
||
| 56 | { |
||
| 57 | $channelID = (int) $msgData['message']['channelID']; |
||
| 58 | |||
| 59 | if (in_array($channelID, $this->excludeChannel, true)) |
||
| 60 | { |
||
| 61 | return null; |
||
| 62 | } |
||
| 63 | |||
| 64 | $this->message = $message; |
||
| 65 | |||
| 66 | $message = $msgData['message']['message']; |
||
| 67 | $user = $msgData['message']['from']; |
||
| 68 | |||
| 69 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
||
| 70 | if (isset($data['trigger'])) { |
||
| 71 | $messageString = $data['messageString']; |
||
| 72 | $cleanString = urlencode($messageString); |
||
| 73 | $corpID = corpID($cleanString); |
||
| 74 | |||
| 75 | if (empty($corpID)) { |
||
| 76 | return $this->message->reply('**Error:** Unable to find any group matching that name.'); |
||
| 77 | } |
||
| 78 | |||
| 79 | $corporation = corpDetails($corpID); |
||
| 80 | $corporationName = $corporation['corporation_name']; |
||
| 81 | $allianceID = $corporation['alliance_id']; |
||
| 82 | $allianceName = allianceName($allianceID); |
||
| 83 | $ceoID = $corporation['ceo_id']; |
||
| 84 | $ceoName = characterName($ceoID); |
||
| 85 | $memberCount = $corporation['member_count']; |
||
| 86 | $corpTicker = $corporation['ticker']; |
||
| 87 | $url = "https://zkillboard.com/corporation/{$corpID}/"; |
||
| 88 | |||
| 89 | if ($corporationName === null || $corporationName === '') { |
||
| 90 | return $this->message->reply('**Error:** No corporation found.'); |
||
| 91 | } |
||
| 92 | |||
| 93 | |||
| 94 | $msg = "```Corp Name: {$corporationName} |
||
| 95 | Corp Ticker: {$corpTicker} |
||
| 96 | CEO: {$ceoName} |
||
| 97 | Alliance Name: {$allianceName} |
||
| 98 | Member Count: {$memberCount} |
||
| 99 | ``` |
||
| 100 | For more info, visit: $url"; |
||
| 101 | |||
| 102 | $this->logger->addInfo("corpInfo: Sending corp info to {$user}"); |
||
| 103 | $this->message->reply($msg); |
||
| 104 | } |
||
| 105 | return null; |
||
| 106 | } |
||
| 107 | |||
| 120 |
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.