| Conditions | 11 |
| Paths | 57 |
| Total Lines | 89 |
| Code Lines | 66 |
| Lines | 4 |
| Ratio | 4.49 % |
| Changes | 4 | ||
| Bugs | 2 | Features | 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 | |||
| 73 | $message = $msgData['message']['message']; |
||
| 74 | $user = $msgData['message']['from']; |
||
| 75 | |||
| 76 | $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
||
| 77 | if (isset($data['trigger'])) { |
||
| 78 | |||
| 79 | // Most EVE players on Discord use their ingame name, so lets support @highlights |
||
| 80 | $messageString = stristr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
||
| 81 | if (is_numeric($messageString)) { |
||
| 82 | // The person used @highlighting, so now we got a discord id, lets map that to a name |
||
| 83 | $messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', [':id' => $messageString]); |
||
| 84 | } |
||
| 85 | |||
| 86 | $cleanString = urlencode($messageString); |
||
| 87 | |||
| 88 | $url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$cleanString}"; |
||
| 89 | $xml = makeApiRequest($url); |
||
| 90 | $characterID = null; |
||
| 91 | |||
| 92 | View Code Duplication | if (isset($xml->result->rowset->row)) { |
|
| 93 | foreach ($xml->result->rowset->row as $character) { |
||
| 94 | $characterID = $character->attributes()->characterID; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | if (empty($characterID)) { |
||
| 98 | return $this->message->reply('**Error:** no data available'); |
||
| 99 | } |
||
| 100 | // Get stats |
||
| 101 | $statsURL = 'https://beta.eve-kill.net/api/charInfo/characterID/'.urlencode($characterID).'/'; |
||
| 102 | $stats = json_decode(downloadData($statsURL), true); |
||
| 103 | |||
| 104 | if (empty($stats)) { |
||
| 105 | return $this->message->reply('**Error:** no data available'); |
||
| 106 | } |
||
| 107 | |||
| 108 | $characterName = @$stats['characterName']; |
||
| 109 | if (empty($characterName)) { |
||
| 110 | return $this->message->reply('**Error:** No Character Found'); |
||
| 111 | } |
||
| 112 | $corporationName = @$stats['corporationName']; |
||
| 113 | $allianceName = isset($stats['allianceName']) ? $stats['allianceName'] : 'None'; |
||
| 114 | $factionName = isset($stats['factionName']) ? $stats['factionName'] : 'None'; |
||
| 115 | $securityStatus = @$stats['securityStatus']; |
||
| 116 | $lastSeenSystem = @$stats['lastSeenSystem']; |
||
| 117 | $lastSeenRegion = @$stats['lastSeenRegion']; |
||
| 118 | $lastSeenShip = @$stats['lastSeenShip']; |
||
| 119 | $lastSeenDate = @$stats['lastSeenDate']; |
||
| 120 | $corporationActiveArea = @$stats['corporationActiveArea']; |
||
| 121 | $allianceActiveArea = @$stats['allianceActiveArea']; |
||
| 122 | $soloKills = @$stats['soloKills']; |
||
| 123 | $blobKills = @$stats['blobKills']; |
||
| 124 | $lifeTimeKills = @$stats['lifeTimeKills']; |
||
| 125 | $lifeTimeLosses = @$stats['lifeTimeLosses']; |
||
| 126 | $amountOfSoloPVPer = @$stats['percentageSoloPVPer']; |
||
| 127 | $ePeenSize = @$stats['ePeenSize']; |
||
| 128 | $facepalms = @$stats['facepalms']; |
||
| 129 | $lastUpdated = @$stats['lastUpdatedOnBackend']; |
||
| 130 | $url = 'https://beta.eve-kill.net/character/'.$stats['characterID'].'/'; |
||
| 131 | |||
| 132 | |||
| 133 | $msg = "```characterName: {$characterName} |
||
| 134 | corporationName: {$corporationName} |
||
| 135 | allianceName: {$allianceName} |
||
| 136 | factionName: {$factionName} |
||
| 137 | securityStatus: {$securityStatus} |
||
| 138 | lastSeenSystem: {$lastSeenSystem} |
||
| 139 | lastSeenRegion: {$lastSeenRegion} |
||
| 140 | lastSeenShip: {$lastSeenShip} |
||
| 141 | lastSeenDate: {$lastSeenDate} |
||
| 142 | corporationActiveArea: {$corporationActiveArea} |
||
| 143 | allianceActiveArea: {$allianceActiveArea} |
||
| 144 | soloKills: {$soloKills} |
||
| 145 | blobKills: {$blobKills} |
||
| 146 | lifeTimeKills: {$lifeTimeKills} |
||
| 147 | lifeTimeLosses: {$lifeTimeLosses} |
||
| 148 | percentageSoloPVPer: {$amountOfSoloPVPer} |
||
| 149 | ePeenSize: {$ePeenSize} |
||
| 150 | facepalms: {$facepalms} |
||
| 151 | lastUpdated: $lastUpdated``` |
||
| 152 | For more info, visit: $url"; |
||
| 153 | |||
| 154 | $this->logger->addInfo("Sending character info to {$user}"); |
||
| 155 | $this->message->reply($msg); |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 178 |
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.