| Conditions | 6 |
| Paths | 4 |
| Total Lines | 73 |
| Code Lines | 46 |
| 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 |
||
| 140 | public function processResponse() |
||
| 141 | { |
||
| 142 | |||
| 143 | $buffer_search = implode(array_map(function ($val) { |
||
| 144 | return pack("C", $val); |
||
| 145 | }, array_reverse(explode(".", $this->realIp)))).pack("S", ($this->realPortQuery + 2)); |
||
| 146 | |||
| 147 | // No response, assume offline |
||
| 148 | if (empty($this->packets_response)) { |
||
| 149 | return [ |
||
| 150 | 'gq_address' => $this->realIp, |
||
| 151 | 'gq_port_client' => $this->realPortQuery, |
||
| 152 | 'gq_port_query' => ($this->realPortQuery + 2), |
||
| 153 | 'gq_online' => false |
||
| 154 | ]; |
||
| 155 | } |
||
| 156 | |||
| 157 | $buffer = new Buffer( implode('', $this->packets_response) ); |
||
| 158 | |||
| 159 | if (str_contains( $buffer->getData() , $buffer_search )) { |
||
| 160 | |||
| 161 | $buffer->readString($buffer_search); |
||
| 162 | $buffer->skip(5); |
||
| 163 | |||
| 164 | $result = new Result(); |
||
| 165 | |||
| 166 | // Server is always dedicated and Mod is scum |
||
| 167 | $result->add('dedicated', 1); |
||
| 168 | $result->add('mod', 'scum'); |
||
| 169 | |||
| 170 | $result->add('gq_address', $this->realIp); |
||
| 171 | $result->add('gq_port_client', $this->realPortQuery); |
||
| 172 | $result->add('gq_port_query', ($this->realPortQuery + 2)); |
||
| 173 | |||
| 174 | // Add server items |
||
| 175 | $result->add('hostname', $buffer->read(101) ); |
||
| 176 | $result->add('numplayers', $buffer->readInt8(2) ); |
||
|
|
|||
| 177 | $result->add('maxplayers', $buffer->readInt8(2) ); |
||
| 178 | |||
| 179 | //Get From 109 until 110 |
||
| 180 | $time = base_convert(bin2hex( $buffer->read(1) ), 16, 10); |
||
| 181 | $result->add('time', (strlen($time) != 1 ? $time : '0' . $time) . ':00'); |
||
| 182 | |||
| 183 | //Get From 111 until 112 |
||
| 184 | $buffer->skip(1); |
||
| 185 | $pwd_bin = ( base_convert(bin2hex($buffer->read(1)), 16, 2 )); |
||
| 186 | if(strlen($pwd_bin) >= 2){ |
||
| 187 | $result->add('password', ($pwd_bin[-2] == '1' ? 1 : 0) ); |
||
| 188 | } |
||
| 189 | |||
| 190 | //Get From 120 until 126 |
||
| 191 | $buffer->skip(7); |
||
| 192 | $byte8 = bin2hex($buffer->read(1)); |
||
| 193 | $byte7 = bin2hex($buffer->read(1)); |
||
| 194 | $byte6 = bin2hex($buffer->read(1)); |
||
| 195 | $byte5 = bin2hex($buffer->read(1)); |
||
| 196 | $byte4 = bin2hex($buffer->read(1)); |
||
| 197 | $byte3 = bin2hex($buffer->read(1)); |
||
| 198 | $byte2 = hexdec(bin2hex($buffer->read(1))); |
||
| 199 | $byte1 = hexdec(bin2hex($buffer->read(1))); |
||
| 200 | |||
| 201 | $result->add('version', $byte1 . "." . $byte2 . "." . hexdec( $byte3 . $byte4 ) . "." . hexdec( $byte5.$byte6.$byte7.$byte8 )); |
||
| 202 | |||
| 203 | unset($buffer); |
||
| 204 | |||
| 205 | return $result->fetch(); |
||
| 206 | } else { |
||
| 207 | |||
| 208 | return [ |
||
| 209 | 'gq_address' => $this->realIp, |
||
| 210 | 'gq_port_client' => $this->realPortQuery, |
||
| 211 | 'gq_port_query' => ($this->realPortQuery + 2), |
||
| 212 | 'gq_online' => false |
||
| 213 | ]; |
||
| 217 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.