| Conditions | 6 |
| Paths | 6 |
| Total Lines | 51 |
| Code Lines | 35 |
| 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 |
||
| 78 | public function onMessage($msgData, $message) |
||
| 79 | { |
||
| 80 | $channelID = (int) $msgData['message']['channelID']; |
||
| 81 | |||
| 82 | if (in_array($channelID, $this->excludeChannel, true)) |
||
| 83 | { |
||
| 84 | return null; |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->message = $message; |
||
| 88 | $user = $msgData['message']['from']; |
||
| 89 | $channelID = $msgData['message']['channelID']; |
||
| 90 | $message = $msgData['message']['message']; |
||
| 91 | date_default_timezone_set('UTC'); |
||
| 92 | |||
| 93 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
||
| 94 | if (isset($data['trigger'])) { |
||
| 95 | |||
| 96 | // Check if the channel is restricted |
||
| 97 | if ($channelID === $this->excludeChannel) { |
||
| 98 | return $this->message->reply('**Upcoming Ops not allowed in this channel**'); |
||
| 99 | } |
||
| 100 | //fleetUp post upcoming operations |
||
| 101 | $ops = json_decode(downloadData("http://api.fleet-up.com/Api.svc/tlYgBRjmuXj2Yl1lEOyMhlDId/{$this->userID}/{$this->apiKey}/Operations/{$this->groupID}"), true); |
||
| 102 | if ($ops['Data'] === null) { |
||
| 103 | $this->message->reply('No upcoming operations detected.'); |
||
| 104 | return null; |
||
| 105 | } |
||
| 106 | $this->logger->addInfo("Sending ops info to {$user}"); |
||
| 107 | foreach ($ops['Data'] as $operation) { |
||
| 108 | $name = $operation['Subject']; |
||
| 109 | $startTime = $operation['StartString']; |
||
| 110 | $desto = $operation['Location']; |
||
| 111 | $formUp = $operation['LocationInfo']; |
||
| 112 | $info = $operation['Details']; |
||
| 113 | $id = $operation['Id']; |
||
| 114 | $link = "https://fleet-up.com/Operation#{$id}\ |
||
| 115 | "; |
||
| 116 | $this->message->reply(" |
||
| 117 | **Upcoming Operation**. |
||
| 118 | Title - {$name}. |
||
| 119 | Form Up Time - {$startTime}. EVE time |
||
| 120 | Form Up System - {$formUp}. |
||
| 121 | Target System - {$desto}. |
||
| 122 | Details - {$info}. |
||
| 123 | Link - {$link}"); |
||
| 124 | } |
||
| 125 | return null; |
||
| 126 | } |
||
| 127 | return null; |
||
| 128 | } |
||
| 129 | |||
| 142 |
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.