| Conditions | 16 |
| Paths | 3 |
| Total Lines | 37 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 89 | public function processResponse() |
||
| 90 | { |
||
| 91 | $server_data = parent::processResponse(); |
||
| 92 | |||
| 93 | if (!$server_data) { |
||
| 94 | throw new Exception('No server data received from EOS API.'); |
||
| 95 | } |
||
| 96 | |||
| 97 | // Filter by port to match server sessions |
||
| 98 | $filtered = array_filter($server_data, function ($session) { |
||
| 99 | return $session['attributes']['ADDRESSBOUND_s'] === "{$this->serverIp}:{$this->serverPortQuery}" || |
||
| 100 | $session['attributes']['ADDRESSBOUND_s'] === "0.0.0.0:{$this->serverPortQuery}"; |
||
| 101 | }); |
||
| 102 | |||
| 103 | if (!$filtered) { |
||
| 104 | throw new Exception('No matching sessions found for the specified port.'); |
||
| 105 | } |
||
| 106 | |||
| 107 | $session = reset($filtered); |
||
| 108 | |||
| 109 | $result = new Result(); |
||
| 110 | |||
| 111 | // Add server items to the result object |
||
| 112 | $result->add('hostname', isset($session['attributes']['CUSTOMSERVERNAME_s']) ? $session['attributes']['CUSTOMSERVERNAME_s'] : 'Unknown'); |
||
| 113 | $result->add('mapname', isset($session['attributes']['MAPNAME_s']) ? $session['attributes']['MAPNAME_s'] : 'Unknown'); |
||
| 114 | $result->add('password', isset($session['attributes']['SERVERPASSWORD_b']) ? $session['attributes']['SERVERPASSWORD_b'] : false); |
||
|
|
|||
| 115 | $result->add('numplayers', isset($session['totalPlayers']) ? $session['totalPlayers'] : 0); |
||
| 116 | $result->add('maxplayers', isset($session['settings']['maxPublicPlayers']) ? $session['settings']['maxPublicPlayers'] : 0); |
||
| 117 | $result->add('anticheat', isset($session['attributes']['SERVERUSESBATTLEYE_b']) ? $session['attributes']['SERVERUSESBATTLEYE_b'] : false); |
||
| 118 | $result->add('allowJoinInProgress', isset($session['settings']['allowJoinInProgress']) ? $session['settings']['allowJoinInProgress'] : false); |
||
| 119 | $result->add('day', isset($session['attributes']['DAYTIME_s']) ? $session['attributes']['DAYTIME_s'] : ''); |
||
| 120 | $result->add('version', "v" . (isset($session['attributes']['BUILDID_s']) ? $session['attributes']['BUILDID_s'] : '0') . "." . (isset($session['attributes']['MINORBUILDID_s']) ? $session['attributes']['MINORBUILDID_s'] : '0')); |
||
| 121 | $result->add('pve', isset($session['attributes']['SESSIONISPVE_l']) ? boolval($session['attributes']['SESSIONISPVE_l']) : false); |
||
| 122 | $result->add('officialserver', isset($session['attributes']['OFFICIALSERVER_s']) ? boolval($session['attributes']['OFFICIALSERVER_s']) : false); |
||
| 123 | |||
| 124 | // Return the final result |
||
| 125 | return $result->fetch(); |
||
| 126 | } |
||
| 128 |