| Conditions | 10 |
| Paths | 38 |
| Total Lines | 91 |
| 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 |
||
| 64 | public function onMessage($msgData, $message) |
||
| 65 | { |
||
| 66 | $this->message = $message; |
||
| 67 | $user = $msgData['message']['from']; |
||
| 68 | $channelID = (int) $msgData['message']['channelID']; |
||
| 69 | |||
| 70 | if (in_array($channelID, $this->excludeChannel, true)) |
||
| 71 | { |
||
| 72 | return null; |
||
| 73 | } |
||
| 74 | |||
| 75 | |||
| 76 | // Bind a few things to vars for the plugins |
||
| 77 | $message = $msgData['message']['message']; |
||
| 78 | |||
| 79 | // Quick Lookups |
||
| 80 | $quickLookUps = array( |
||
| 81 | 'plex' => array( |
||
| 82 | 'typeID' => 29668, |
||
| 83 | 'typeName' => "30 Day Pilot's License Extension (PLEX)" |
||
| 84 | ), |
||
| 85 | '30 day' => array( |
||
| 86 | 'typeID' => 29668, |
||
| 87 | 'typeName' => "30 Day Pilot's License Extension (PLEX)" |
||
| 88 | ) |
||
| 89 | ); |
||
| 90 | |||
| 91 | $data = command(strtolower($message), $this->information()['trigger'], $this->config['bot']['trigger']); |
||
| 92 | |||
| 93 | if (isset($data['trigger'])) { |
||
| 94 | |||
| 95 | $systemName = $data['trigger']; |
||
| 96 | $itemName = $data['messageString']; |
||
| 97 | $single = apiTypeID(urlencode($itemName)); |
||
| 98 | |||
| 99 | // Quick lookups |
||
| 100 | if (isset($quickLookUps[$itemName])) { |
||
| 101 | $single = $quickLookUps[$itemName]; |
||
| 102 | } |
||
| 103 | |||
| 104 | // Check if the channel is restricted |
||
| 105 | if (in_array($channelID, $this->excludeChannel, true)) { |
||
| 106 | return $this->message->reply('**Price Check not allowed in this channel**'); |
||
| 107 | } |
||
| 108 | |||
| 109 | // If there is a single result, we'll get data now! |
||
| 110 | if ($single) { |
||
| 111 | $typeID = $single['typeID']; |
||
| 112 | |||
| 113 | if (null === $typeID) { |
||
| 114 | $typeID = $single; |
||
| 115 | } |
||
| 116 | |||
| 117 | if ($systemName === 'pc') { |
||
| 118 | $solarSystemID = 'global'; |
||
| 119 | } else { |
||
| 120 | $solarSystemID = apiCharacterID(urlencode($systemName)); |
||
| 121 | } |
||
| 122 | |||
| 123 | // Get pricing data |
||
| 124 | if ($solarSystemID === 'global') { |
||
| 125 | $data = new SimpleXMLElement(downloadData("https://api.eve-central.com/api/marketstat?typeid={$typeID}")); |
||
| 126 | } else { |
||
| 127 | $data = new SimpleXMLElement(downloadData("https://api.eve-central.com/api/marketstat?usesystem={$solarSystemID}&typeid={$typeID}")); |
||
| 128 | } |
||
| 129 | |||
| 130 | $lowBuy = number_format((float) $data->marketstat->type->buy->min, 2); |
||
| 131 | $avgBuy = number_format((float) $data->marketstat->type->buy->avg, 2); |
||
| 132 | $highBuy = number_format((float) $data->marketstat->type->buy->max, 2); |
||
| 133 | $lowSell = number_format((float) $data->marketstat->type->sell->min, 2); |
||
| 134 | $avgSell = number_format((float) $data->marketstat->type->sell->avg, 2); |
||
| 135 | $highSell = number_format((float) $data->marketstat->type->sell->max, 2); |
||
| 136 | |||
| 137 | $this->logger->addInfo("Price: Sending pricing info to {$user}"); |
||
| 138 | $solarSystemName = $systemName === 'pc' ? 'Global' : ucfirst($systemName); |
||
| 139 | $messageData = "**System: {$solarSystemName}** |
||
| 140 | **Buy:** |
||
| 141 | Low: {$lowBuy} |
||
| 142 | Avg: {$avgBuy} |
||
| 143 | High: {$highBuy} |
||
| 144 | **Sell:** |
||
| 145 | Low: {$lowSell} |
||
| 146 | Avg: {$avgSell} |
||
| 147 | High: {$highSell}"; |
||
| 148 | $this->message->reply($messageData); |
||
| 149 | } else { |
||
| 150 | $this->message->reply("**Error:** ***{$itemName}*** not found"); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | return null; |
||
| 154 | } |
||
| 155 | |||
| 168 |
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.