Conditions | 9 |
Paths | 12 |
Total Lines | 89 |
Code Lines | 53 |
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 |
||
28 | public function onMessage($msgData, $message) |
||
29 | { |
||
30 | $channelID = (int) $msgData['message']['channelID']; |
||
31 | |||
32 | if(in_array($channelID, $this->excludeChannel, true)) |
||
33 | { |
||
34 | return null; |
||
35 | } |
||
36 | |||
37 | $this->message = $message; |
||
38 | |||
39 | $message = $msgData['message']['message']; |
||
40 | $user = $msgData['message']['from']; |
||
41 | |||
42 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
||
43 | if(isset($data['trigger'])) |
||
44 | { |
||
45 | $messageString = strstr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
||
46 | if(is_numeric($messageString)) |
||
47 | { |
||
48 | $messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', array(':id' => $messageString)); |
||
49 | } |
||
50 | $cleanString = urlencode($messageString); |
||
51 | $sysID = urlencode(getSystemID($cleanString)); |
||
52 | |||
53 | //Check if we get a system back, otherwise check for partials |
||
54 | if(empty($sysID)) |
||
55 | { |
||
56 | return $this->message->reply('**Error:** no data available'); |
||
57 | } |
||
58 | |||
59 | $systemDetails = systemDetails($sysID); |
||
60 | if (null === $systemDetails) |
||
61 | { |
||
62 | return $this->message->reply('**Error:** ESI is down. Try again later.'); |
||
63 | } |
||
64 | |||
65 | $url = "https://zkillboard.com/api/stats/solarSystemID/{$sysID}/"; |
||
66 | $json = json_decode(file_get_contents($url)); |
||
67 | |||
68 | $regionID = $json->info->regionID; |
||
69 | $regionName = getRegionName($regionID); |
||
70 | |||
71 | $thisMonth = (string)date('Ym'); |
||
72 | $lastMonth = (string)date('Ym', strtotime('first day of previous month')); |
||
73 | |||
74 | $thisMonthKill = $json->months->$thisMonth->shipsDestroyed; |
||
75 | $lastMonthKill = $json->months->$lastMonth->shipsDestroyed; |
||
76 | |||
77 | $activePVP = $json->activepvp; |
||
78 | $activeKills = $activePVP->kills->count; |
||
79 | $activeChars = $activePVP->characters->count; |
||
80 | |||
81 | $sysName = $systemDetails['name']; |
||
82 | $secStatus = round($systemDetails['security_status'],2); |
||
83 | |||
84 | $npc = "https://api.eveonline.com/map/kills.xml.aspx"; |
||
85 | $npc = new SimpleXMLElement(file_get_contents($npc)); |
||
86 | foreach($npc->result->rowset->row as $row){ |
||
87 | if($row->attributes()->solarSystemID == $sysID){ |
||
88 | $npcKills = $row->attributes()->factionKills; |
||
89 | $podKills = $row->attributes()->podKills; |
||
90 | } |
||
91 | } |
||
92 | |||
93 | $url = "https://zkillboard.com/system/{$sysID}/"; |
||
94 | |||
95 | $msg = "```Systeminfo |
||
96 | Name: {$sysName} |
||
97 | Region: {$regionName} |
||
98 | Security: {$secStatus} |
||
99 | |||
100 | Kills |
||
101 | This Month: {$thisMonthKill} |
||
102 | Last Month: {$lastMonthKill} |
||
103 | |||
104 | Activity |
||
105 | Characters: {$activeChars} |
||
106 | Kills: {$activeKills} |
||
107 | Pod Kills: {$podKills} |
||
108 | NPC Kills: {$npcKills} |
||
109 | ``` |
||
110 | |||
111 | More information: $url"; |
||
112 | $this->logger->addInfo("sysInfo: Sending system information to {$user}"); |
||
113 | $this->message->reply($msg); |
||
114 | } |
||
115 | return null; |
||
116 | } |
||
117 | |||
127 |
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.