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