| Conditions | 8 |
| Paths | 12 |
| Total Lines | 52 |
| Code Lines | 38 |
| 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 |
||
| 48 | public function onMessage($msgData, $message) { |
||
| 49 | $channelID = (int) $msgData['message']['channelID']; |
||
| 50 | if (in_array($channelID, $this->excludeChannel, true)) { |
||
| 51 | return null; |
||
| 52 | } |
||
| 53 | $this->message = $message; |
||
| 54 | $user = $msgData['message']['from']; |
||
| 55 | $message = $msgData['message']['message']; |
||
| 56 | $data = command($message, $this->information() ['trigger'], $this->config['bot']['trigger']); |
||
| 57 | if (isset($data['trigger'])) { |
||
| 58 | $keyID = $this->keyID; |
||
| 59 | $vCode = $this->vCode; |
||
| 60 | $characterID = $this->characterID; |
||
| 61 | $channelname = $this->channelname; |
||
| 62 | |||
| 63 | $urlChar = "https://api.eveonline.com/char/ChatChannels.xml.aspx?keyID=$keyID&vCode=$vCode&characterID=$characterID"; |
||
| 64 | $data = file_get_contents($urlChar); |
||
| 65 | $list = new SimpleXMLElement($data); |
||
| 66 | |||
| 67 | |||
| 68 | foreach ($list->result->rowset->row as $row) { |
||
| 69 | $channeln = $row["displayName"]; |
||
| 70 | |||
| 71 | if ($channeln == $channelname) { |
||
| 72 | //scrub the motd, then break it into 1900 chars or less. Limit is 2000 and want to leave room for the name of the person being replied too |
||
| 73 | $comment = $row["motd"]; |
||
| 74 | $comment = str_replace("<BR>", "\n", $comment); |
||
| 75 | $comment = str_replace("<br>", "\n", $comment); |
||
| 76 | $comment = str_replace("<u>", "__", $comment); |
||
| 77 | $comment = str_replace("</u>", "__", $comment); |
||
| 78 | $comment = str_replace("<b>", "**", $comment); |
||
| 79 | $comment = str_replace("</b>", "**", $comment); |
||
| 80 | $comment = str_replace("<i>", "*", $comment); |
||
| 81 | $comment = str_replace("</i>", "*", $comment); |
||
| 82 | $comment = str_replace("&", "&", $comment); |
||
| 83 | $comment = strip_tags($comment); |
||
| 84 | $comment2 = str_split($comment, 1900); |
||
| 85 | |||
| 86 | $this->message->reply("\n $comment2[0]"); |
||
| 87 | if (!empty($comment2[1])) { |
||
| 88 | $this->message->reply("\n $comment2[1]"); |
||
| 89 | } |
||
| 90 | if (!empty($comment2[2])) { |
||
| 91 | $this->message->reply("\n $comment2[2]"); |
||
| 92 | } |
||
| 93 | if (!empty($comment2[3])) { |
||
| 94 | $this->message->reply("\n $comment2[3]"); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | } |
||
| 98 | } |
||
| 99 | } |
||
| 100 | public function information() { |
||
| 105 |
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.