| Conditions | 1 |
| Paths | 1 |
| Total Lines | 129 |
| Code Lines | 95 |
| 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 |
||
| 173 | public function testDatabase() |
||
| 174 | { |
||
| 175 | $testcase = 'irpg-scoreboard.db'; |
||
| 176 | $config = [ |
||
| 177 | 'bot_db' => __DIR__ . '/../testcases/' . $testcase, |
||
| 178 | ]; |
||
| 179 | |||
| 180 | $parser = new BotParser($config); |
||
| 181 | |||
| 182 | $db = $parser->getDatabase(); |
||
| 183 | |||
| 184 | // Number of players |
||
| 185 | $this->assertEquals(12, count($db)); |
||
| 186 | |||
| 187 | // Test for invalid player |
||
| 188 | $this->assertEquals(0, $parser->getDatabase('ZBR123')); |
||
| 189 | |||
| 190 | $expectedUser = [ |
||
| 191 | 'nick' => 'fALSO', |
||
| 192 | 'level' => 43, |
||
| 193 | 'admin' => 'No', |
||
| 194 | 'class' => 'GLORIOSO', |
||
| 195 | 'ttl' => [ |
||
| 196 | 'display' => '3 days 12 hours', |
||
| 197 | 'numeric' => 304376, |
||
| 198 | ], |
||
| 199 | 'nick_host' => 'secret!secret@secret', |
||
| 200 | 'online' => 'Yes', |
||
| 201 | 'idled' => [ |
||
| 202 | 'display' => '2 weeks 5 days', |
||
| 203 | 'numeric' => 1675484, |
||
| 204 | ], |
||
| 205 | 'x_pos' => 259, |
||
| 206 | 'y_pos' => 390, |
||
| 207 | 'msg_pen' => [ |
||
| 208 | 'display' => '10 minutes 3 seconds', |
||
| 209 | 'numeric' => 603, |
||
| 210 | ], |
||
| 211 | 'nick_pen' => [ |
||
| 212 | 'display' => 'None', |
||
| 213 | 'numeric' => 0, |
||
| 214 | ], |
||
| 215 | 'part_pen' => [ |
||
| 216 | 'display' => 'None', |
||
| 217 | 'numeric' => 0, |
||
| 218 | ], |
||
| 219 | 'kick_pen' => [ |
||
| 220 | 'display' => 'None', |
||
| 221 | 'numeric' => 0, |
||
| 222 | ], |
||
| 223 | 'quit_pen' => [ |
||
| 224 | 'display' => 'None', |
||
| 225 | 'numeric' => 0, |
||
| 226 | ], |
||
| 227 | 'quest_pen' => [ |
||
| 228 | 'display' => 'None', |
||
| 229 | 'numeric' => 0, |
||
| 230 | ], |
||
| 231 | 'logout_pen' => [ |
||
| 232 | 'display' => 'None', |
||
| 233 | 'numeric' => 0, |
||
| 234 | ], |
||
| 235 | 'total_pen' => [ |
||
| 236 | 'display' => '10 minutes 3 seconds', |
||
| 237 | 'numeric' => 603, |
||
| 238 | ], |
||
| 239 | 'created' => [ |
||
| 240 | 'display' => '2018-06-20 22:58:00', |
||
| 241 | 'numeric' => 1529535480, |
||
| 242 | ], |
||
| 243 | 'last_login' => [ |
||
| 244 | 'display' => '2018-06-28 13:35:35', |
||
| 245 | 'numeric' => 1530192935, |
||
| 246 | ], |
||
| 247 | 'amulet' => [ |
||
| 248 | 'display' => '43', |
||
| 249 | 'numeric' => 43, |
||
| 250 | 'unique' => NULL, |
||
| 251 | ], |
||
| 252 | 'charm' => [ |
||
| 253 | 'display' => '40', |
||
| 254 | 'numeric' => 40, |
||
| 255 | 'unique' => NULL, |
||
| 256 | ], |
||
| 257 | 'helm' => [ |
||
| 258 | 'display' => '23', |
||
| 259 | 'numeric' => 23, |
||
| 260 | 'unique' => NULL, |
||
| 261 | ], |
||
| 262 | 'boots' => [ |
||
| 263 | 'display' => '27', |
||
| 264 | 'numeric' => 27, |
||
| 265 | 'unique' => NULL, |
||
| 266 | ], |
||
| 267 | 'gloves' => [ |
||
| 268 | 'display' => '30', |
||
| 269 | 'numeric' => 30, |
||
| 270 | 'unique' => NULL, |
||
| 271 | ], |
||
| 272 | 'ring' => [ |
||
| 273 | 'display' => '52h', |
||
| 274 | 'numeric' => 52, |
||
| 275 | 'unique' => 'Juliet\'s Glorious Ring of Sparkliness', |
||
| 276 | ], |
||
| 277 | 'leggings' => [ |
||
| 278 | 'display' => '21', |
||
| 279 | 'numeric' => 21, |
||
| 280 | 'unique' => NULL, |
||
| 281 | ], |
||
| 282 | 'shield' => [ |
||
| 283 | 'display' => '43', |
||
| 284 | 'numeric' => 43, |
||
| 285 | 'unique' => NULL, |
||
| 286 | ], |
||
| 287 | 'tunic' => [ |
||
| 288 | 'display' => '55', |
||
| 289 | 'numeric' => 55, |
||
| 290 | 'unique' => NULL, |
||
| 291 | ], |
||
| 292 | 'weapon' => [ |
||
| 293 | 'display' => '46', |
||
| 294 | 'numeric' => 46, |
||
| 295 | 'unique' => NULL, |
||
| 296 | ], |
||
| 297 | 'sum' => 380, |
||
| 298 | 'alignment' => 'Neutral', |
||
| 299 | ]; |
||
| 300 | |||
| 301 | $this->assertEquals($expectedUser, $parser->getDatabase('fALSO')); |
||
| 302 | } |
||
| 304 |