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