Conditions | 10 |
Paths | 8 |
Total Lines | 140 |
Code Lines | 103 |
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 |
||
226 | public function getDatabase(string $nick = null) |
||
227 | { |
||
228 | $database = []; |
||
229 | $row = 0; |
||
230 | if (($handle = fopen($this->config['bot_db'], "r")) !== false) { |
||
231 | while (($data = fgetcsv($handle, 1024, "\t")) !== false) { |
||
232 | $row++; |
||
233 | if ($row == 1) { |
||
234 | continue; |
||
235 | } |
||
236 | |||
237 | if ($nick !== null && strcmp($data[0], $nick) !== 0) { |
||
238 | continue; |
||
239 | } |
||
240 | |||
241 | $record = [ |
||
242 | 'nick' => $data[0], // nick |
||
243 | 'level' => $data[3], // level |
||
244 | 'admin' => ($data[2] ? 'Yes' : 'No'), // admin |
||
245 | 'class' => $data[4], // class |
||
246 | 'ttl' => [ |
||
247 | 'display' => $this->secondsToTime((int) $data[5]), |
||
248 | 'numeric' => (int) $data[5], // ttl |
||
249 | ], |
||
250 | 'nick_host' => $data[7], // nick and host |
||
251 | 'online' => ($data[8] ? 'Yes' : 'No'), // online |
||
252 | 'idled' => [ |
||
253 | 'display' => $this->secondsToTime((int) $data[9]), // idled |
||
254 | 'numeric' => (int) $data[9], |
||
255 | ], |
||
256 | 'x_pos' => (int) $data[10], // x pos |
||
257 | 'y_pos' => (int) $data[11], // y pos |
||
258 | 'msg_pen' => [ |
||
259 | 'display' => $this->secondsToTime((int) $data[12]), // msg pen |
||
260 | 'numeric' => (int) $data[12], |
||
261 | ], |
||
262 | 'nick_pen' => [ |
||
263 | 'display' => $this->secondsToTime((int) $data[13]), // nick pen |
||
264 | 'numeric' => (int) $data[13], |
||
265 | ], |
||
266 | 'part_pen' => [ |
||
267 | 'display' => $this->secondsToTime((int) $data[14]), // part pen |
||
268 | 'numeric' => (int) $data[14], |
||
269 | ], |
||
270 | 'kick_pen' => [ |
||
271 | 'display' => $this->secondsToTime((int) $data[15]), // kick pen |
||
272 | 'numeric' => (int) $data[15], |
||
273 | ], |
||
274 | 'quit_pen' => [ |
||
275 | 'display' => $this->secondsToTime((int) $data[16]), // quit pen |
||
276 | 'numeric' => (int) $data[16], |
||
277 | ], |
||
278 | 'quest_pen' => [ |
||
279 | 'display' => $this->secondsToTime((int) $data[17]), // quest pen |
||
280 | 'numeric' => (int) $data[17], |
||
281 | ], |
||
282 | 'logout_pen' => [ |
||
283 | 'display' => $this->secondsToTime((int) $data[18]), // logout pen |
||
284 | 'numeric' => (int) $data[18], |
||
285 | ], |
||
286 | 'total_pen' => [ |
||
287 | 'display' => $this->secondsToTime($this->sumFields($data, 12, 18)), |
||
288 | 'numeric' => $this->sumFields($data, 12, 18), |
||
289 | ], |
||
290 | 'created' => [ |
||
291 | 'display' => date('Y-m-d H:i:s', (int) $data[19]), // created |
||
292 | 'numeric' => (int) $data[19], |
||
293 | ], |
||
294 | 'last_login' => [ |
||
295 | 'display' => date('Y-m-d H:i:s', (int) $data[20]), // last login |
||
296 | 'numeric' => (int) $data[20], |
||
297 | ], |
||
298 | 'amulet' => [ |
||
299 | 'display' => $data[21], // amulet |
||
300 | 'numeric' => (int) $data[21], |
||
301 | 'unique' => $this->parseUniqueItem($data[21]) |
||
302 | ], |
||
303 | 'charm' => [ |
||
304 | 'display' => $data[22], // charm |
||
305 | 'numeric' => (int) $data[22], |
||
306 | 'unique' => $this->parseUniqueItem($data[22]) |
||
307 | ], |
||
308 | 'helm' => [ |
||
309 | 'display' => $data[23], // helm |
||
310 | 'numeric' => (int) $data[23], |
||
311 | 'unique' => $this->parseUniqueItem($data[23]) |
||
312 | ], |
||
313 | 'boots' => [ |
||
314 | 'display' => $data[24], // boots |
||
315 | 'numeric' => (int) $data[24], |
||
316 | 'unique' => $this->parseUniqueItem($data[24]) |
||
317 | ], |
||
318 | 'gloves' => [ |
||
319 | 'display' => $data[25], // gloves |
||
320 | 'numeric' => (int) $data[25], |
||
321 | 'unique' => $this->parseUniqueItem($data[25]) |
||
322 | ], |
||
323 | 'ring' => [ |
||
324 | 'display' => $data[26], // ring |
||
325 | 'numeric' => (int) $data[26], |
||
326 | 'unique' => $this->parseUniqueItem($data[26]) |
||
327 | ], |
||
328 | 'leggings' => [ |
||
329 | 'display' => $data[27], // leggings |
||
330 | 'numeric' => (int) $data[27], |
||
331 | 'unique' => $this->parseUniqueItem($data[27]) |
||
332 | ], |
||
333 | 'shield' => [ |
||
334 | 'display' => $data[28], // shield |
||
335 | 'numeric' => (int) $data[28], |
||
336 | 'unique' => $this->parseUniqueItem($data[28]) |
||
337 | ], |
||
338 | 'tunic' => [ |
||
339 | 'display' => $data[29], // tunic |
||
340 | 'numeric' => (int) $data[29], |
||
341 | 'unique' => $this->parseUniqueItem($data[29]) |
||
342 | ], |
||
343 | 'weapon' => [ |
||
344 | 'display' => $data[30], // weapon |
||
345 | 'numeric' => (int) $data[30], |
||
346 | 'unique' => $this->parseUniqueItem($data[30]) |
||
347 | ], |
||
348 | 'sum' => $this->sumFields($data, 21, 30), |
||
349 | 'alignment' => $this->parseAlignment($data[31]), // alignment |
||
350 | ]; |
||
351 | |||
352 | if ($nick !== null) { |
||
353 | return $record; |
||
354 | } |
||
355 | |||
356 | $database[] = $record; |
||
357 | } |
||
358 | fclose($handle); |
||
359 | } |
||
360 | |||
361 | if ($nick !== null) { |
||
362 | return 0; |
||
363 | } |
||
364 | |||
365 | return $database; |
||
366 | } |
||
532 |