Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like DBStaticMessages often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DBStaticMessages, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 3 | class DBStaticMessages { |
||
| 4 | public static $snMessageClassList = array( |
||
| 5 | MSG_TYPE_NEW => array( |
||
| 6 | 'name' => 'new_message', |
||
| 7 | 'switchable' => false, |
||
| 8 | 'email' => false, |
||
| 9 | ), |
||
| 10 | MSG_TYPE_ADMIN => array( |
||
| 11 | 'name' => 'msg_admin', |
||
| 12 | 'switchable' => false, |
||
| 13 | 'email' => true, |
||
| 14 | ), |
||
| 15 | MSG_TYPE_PLAYER => array( |
||
| 16 | 'name' => 'mnl_joueur', |
||
| 17 | 'switchable' => false, |
||
| 18 | 'email' => true, |
||
| 19 | ), |
||
| 20 | MSG_TYPE_ALLIANCE => array( |
||
| 21 | 'name' => 'mnl_alliance', |
||
| 22 | 'switchable' => false, |
||
| 23 | 'email' => true, |
||
| 24 | ), |
||
| 25 | MSG_TYPE_SPY => array( |
||
| 26 | 'name' => 'mnl_spy', |
||
| 27 | 'switchable' => true, |
||
| 28 | 'email' => true, |
||
| 29 | ), |
||
| 30 | MSG_TYPE_COMBAT => array( |
||
| 31 | 'name' => 'mnl_attaque', |
||
| 32 | 'switchable' => true, |
||
| 33 | 'email' => true, |
||
| 34 | ), |
||
| 35 | MSG_TYPE_TRANSPORT => array( |
||
| 36 | 'name' => 'mnl_transport', |
||
| 37 | 'switchable' => true, |
||
| 38 | 'email' => true, |
||
| 39 | ), |
||
| 40 | MSG_TYPE_RECYCLE => array( |
||
| 41 | 'name' => 'mnl_exploit', |
||
| 42 | 'switchable' => true, |
||
| 43 | 'email' => true, |
||
| 44 | ), |
||
| 45 | MSG_TYPE_EXPLORE => array( |
||
| 46 | 'name' => 'mnl_expedition', |
||
| 47 | 'switchable' => true, |
||
| 48 | 'email' => true, |
||
| 49 | ), |
||
| 50 | // 97 => 'mnl_general', |
||
|
|
|||
| 51 | MSG_TYPE_QUE => array( |
||
| 52 | 'name' => 'mnl_buildlist', |
||
| 53 | 'switchable' => true, |
||
| 54 | 'email' => true, |
||
| 55 | ), |
||
| 56 | MSG_TYPE_OUTBOX => array( |
||
| 57 | 'name' => 'mnl_outbox', |
||
| 58 | 'switchable' => false, |
||
| 59 | 'email' => false, |
||
| 60 | ), |
||
| 61 | ); |
||
| 62 | public static $snMessageGroup = array( |
||
| 63 | 'switchable' => array(MSG_TYPE_SPY, MSG_TYPE_COMBAT, MSG_TYPE_RECYCLE, MSG_TYPE_TRANSPORT, MSG_TYPE_EXPLORE, MSG_TYPE_QUE), |
||
| 64 | 'email' => array(MSG_TYPE_SPY, MSG_TYPE_PLAYER, MSG_TYPE_ALLIANCE, MSG_TYPE_COMBAT, MSG_TYPE_RECYCLE, MSG_TYPE_TRANSPORT, |
||
| 65 | MSG_TYPE_ADMIN, MSG_TYPE_EXPLORE, MSG_TYPE_QUE), |
||
| 66 | ); |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @param mixed|array $owners |
||
| 70 | * @param integer $sender |
||
| 71 | * @param integer $timestamp |
||
| 72 | * @param integer $message_type |
||
| 73 | * @param string $from_unsafe |
||
| 74 | * @param string $subject_unsafe |
||
| 75 | * @param string $text_unsafe |
||
| 76 | * @param bool $force |
||
| 77 | */ |
||
| 78 | public static function msg_send_simple_message($owners, $sender, $timestamp, $message_type, $from_unsafe, $subject_unsafe, $text_unsafe, $force = false) { |
||
| 79 | global $user; |
||
| 80 | |||
| 81 | if (!$owners) { |
||
| 82 | return; |
||
| 83 | } |
||
| 84 | |||
| 85 | $timestamp = $timestamp ? $timestamp : SN_TIME_NOW; |
||
| 86 | $sender = intval($sender); |
||
| 87 | if (!is_array($owners)) { |
||
| 88 | $owners = array($owners); |
||
| 89 | } |
||
| 90 | |||
| 91 | // TODO - check for valid message_type ? |
||
| 92 | $message_class = static::$snMessageClassList[$message_type]; |
||
| 93 | $message_class_name = $message_class['name']; |
||
| 94 | |||
| 95 | $text_safe = db_escape($text_unsafe); |
||
| 96 | |||
| 97 | $message_class_name_total = static::$snMessageClassList[MSG_TYPE_NEW]['name']; |
||
| 98 | |||
| 99 | if ($owners[0] == '*') { |
||
| 100 | if ($user['authlevel'] < 3) { |
||
| 101 | return false; |
||
| 102 | } |
||
| 103 | // TODO Добавить $timestamp - рассылка может быть и отсроченной |
||
| 104 | // TODO Добавить $sender - рассылка может быть и от кого-то |
||
| 105 | static::db_message_insert_all($message_type, $from_unsafe, $subject_unsafe, $text_unsafe); |
||
| 106 | $owners = array(); |
||
| 107 | } else { |
||
| 108 | $insert_values = array(); |
||
| 109 | foreach ($owners as $owner) { |
||
| 110 | if ($user['id'] != $owner) { |
||
| 111 | $owner_row = DBStaticUser::db_user_by_id($owner); |
||
| 112 | } else { |
||
| 113 | $owner_row = $user; |
||
| 114 | } |
||
| 115 | sys_user_options_unpack($owner_row); |
||
| 116 | |||
| 117 | if ($force || !$message_class['switchable'] || $owner_row["opt_{$message_class_name}"]) { |
||
| 118 | $insert_values[] = "('" . idval($owner) . "', '{$sender}', '{$timestamp}', '{$message_type}', '" . db_escape($from_unsafe) . "', '" . db_escape($subject_unsafe) . "', '" . db_escape($text_unsafe) . "')"; |
||
| 119 | } |
||
| 120 | |||
| 121 | // TODO - allow sending HTML email only from admin |
||
| 122 | if ($message_class['email'] && classSupernova::$config->game_email_pm && $owner_row["opt_email_{$message_class_name}"]) { |
||
| 123 | $text_unescaped = str_replace(array('\\r\\n', '\\n', "\r\n", "\n"), "<br />", $text_unsafe); |
||
| 124 | @$result = mymail($owner_row['email'], $subject_unsafe, $text_unescaped, '', true); |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | if (empty($insert_values)) { |
||
| 129 | return; |
||
| 130 | } |
||
| 131 | |||
| 132 | classSupernova::$db->doInsertValuesDeprecated( |
||
| 133 | TABLE_MESSAGES, |
||
| 134 | array( |
||
| 135 | 'message_owner', |
||
| 136 | 'message_sender', |
||
| 137 | 'message_time', |
||
| 138 | 'message_type', |
||
| 139 | 'message_from', |
||
| 140 | 'message_subject', |
||
| 141 | 'message_text', |
||
| 142 | ), |
||
| 143 | $insert_values |
||
| 144 | ); |
||
| 145 | } |
||
| 146 | DBStaticUser::db_user_list_set_mass_mail( |
||
| 147 | $owners, |
||
| 148 | array( |
||
| 149 | $message_class_name => +1, |
||
| 150 | $message_class_name_total => +1, |
||
| 151 | ) |
||
| 152 | ); |
||
| 153 | |||
| 154 | if (in_array($user['id'], $owners) || $owners[0] == '*') { |
||
| 155 | $user[$message_class_name]++; |
||
| 156 | $user[$message_class_name_total]++; |
||
| 157 | } |
||
| 158 | } |
||
| 159 | |||
| 160 | public static function msg_ali_send($message, $subject, $ally_rank_id = 0, $ally_id = 0) { |
||
| 161 | global $user; |
||
| 162 | |||
| 163 | $ally_id = $ally_id ? $ally_id : $user['ally_id']; |
||
| 164 | |||
| 165 | $sendList = array(); |
||
| 166 | $list = ''; |
||
| 167 | $query = DBStaticUser::db_user_list( |
||
| 168 | "ally_id = '{$ally_id}'" . ($ally_rank_id >= 0 ? " AND ally_rank_id = {$ally_rank_id}" : ''), |
||
| 169 | false, 'id, username'); |
||
| 170 | foreach ($query as $u) { |
||
| 171 | $sendList[] = $u['id']; |
||
| 172 | $list .= "<br>{$u['username']} "; |
||
| 173 | } |
||
| 174 | |||
| 175 | static::msg_send_simple_message($sendList, $user['id'], SN_TIME_NOW, MSG_TYPE_ALLIANCE, $user['username'], $subject, $message); |
||
| 176 | |||
| 177 | return $list; |
||
| 178 | } |
||
| 179 | |||
| 180 | |||
| 181 | /** |
||
| 182 | * @param mixed|array $owners |
||
| 183 | * @param string $subject |
||
| 184 | * @param string $text |
||
| 185 | * @param bool $force |
||
| 186 | */ |
||
| 187 | public static function msgSendFromAdmin($owners, $subject, $text, $force = false) { |
||
| 188 | static::msg_send_simple_message($owners, 0, SN_TIME_NOW, MSG_TYPE_ADMIN, classLocale::$lang['sys_administration'], $subject, $text, $force); |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param $senderPlayerId |
||
| 193 | * @param $senderPlayerNameAndCoordinates |
||
| 194 | * @param mixed $recipientId |
||
| 195 | * @param string $subject |
||
| 196 | * @param string $text |
||
| 197 | */ |
||
| 198 | public static function msgSendFromPlayer($senderPlayerId, $senderPlayerNameAndCoordinates, $recipientId, $subject, $text) { |
||
| 199 | static::msg_send_simple_message( |
||
| 200 | $recipientId, $senderPlayerId, SN_TIME_NOW, MSG_TYPE_PLAYER, $senderPlayerNameAndCoordinates, $subject, $text |
||
| 201 | ); |
||
| 202 | } |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param \Buddy\BuddyRoutingParams $cBuddy |
||
| 206 | * @param string $localeSubjectId |
||
| 207 | * @param string $localeTextId |
||
| 208 | */ |
||
| 209 | public static function msgSendFromPlayerBuddy($cBuddy, $localeSubjectId, $localeTextId) { |
||
| 210 | static::msgSendFromPlayer( |
||
| 211 | $cBuddy->playerId, |
||
| 212 | $cBuddy->playerNameAndCoordinates, |
||
| 213 | $cBuddy->newFriendIdSafe, |
||
| 214 | classLocale::$lang[$localeSubjectId], |
||
| 215 | sprintf(classLocale::$lang[$localeTextId], $cBuddy->playerName) |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | |||
| 219 | |||
| 220 | /** |
||
| 221 | * @param array $player |
||
| 222 | * |
||
| 223 | * @return template |
||
| 224 | */ |
||
| 225 | public static function messageWrite($player) { |
||
| 297 | |||
| 298 | |||
| 299 | /** |
||
| 300 | * @param array $player |
||
| 301 | * @param string $current_class |
||
| 302 | */ |
||
| 303 | public static function messageDelete($player, $current_class) { |
||
| 304 | $message_range = sys_get_param_str('message_range'); |
||
| 305 | $marked_message_list = sys_get_param('mark', array()); |
||
| 306 | |||
| 307 | $deleteAll = false; |
||
| 308 | $where = array(); |
||
| 309 | $not = ''; |
||
| 310 | switch ($message_range) { |
||
| 311 | case 'unchecked': |
||
| 312 | $not = 'NOT'; |
||
| 313 | case 'checked': |
||
| 314 | if ($message_range == 'checked' && empty($marked_message_list)) { |
||
| 315 | break; |
||
| 316 | } |
||
| 317 | |||
| 318 | foreach ($marked_message_list as &$messageId) { |
||
| 319 | $messageId = idval($messageId); |
||
| 320 | } |
||
| 321 | |||
| 322 | if ($query_add = implode(',', $marked_message_list)) { |
||
| 323 | $where[] = "`message_id` {$not} IN ({$query_add})"; |
||
| 324 | } |
||
| 325 | |||
| 326 | case 'class': |
||
| 327 | if ($current_class != MSG_TYPE_OUTBOX && $current_class != MSG_TYPE_NEW) { |
||
| 328 | $where['message_type'] = $current_class; |
||
| 329 | } |
||
| 330 | case 'all': |
||
| 331 | $deleteAll = true; |
||
| 332 | break; |
||
| 333 | } |
||
| 334 | |||
| 335 | if ($deleteAll || !empty($where)) { |
||
| 336 | $where['message_owner'] = $player['id']; |
||
| 337 | // Mallformed $where |
||
| 338 | classSupernova::$gc->db->doDeleteDeprecated(TABLE_MESSAGES, $where); |
||
| 339 | } |
||
| 340 | } |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @param array $player |
||
| 344 | * @param int $current_class |
||
| 345 | * |
||
| 346 | * @return template |
||
| 347 | */ |
||
| 348 | public static function messageShow(&$player, $current_class) { |
||
| 349 | if ($current_class == MSG_TYPE_OUTBOX) { |
||
| 350 | $message_query = static::db_message_list_outbox_by_user_id($player['id']); |
||
| 351 | } else { |
||
| 352 | if ($current_class == MSG_TYPE_NEW) { |
||
| 353 | $SubUpdateQry = array(); |
||
| 354 | foreach (static::$snMessageClassList as $message_class_id => $message_class) { |
||
| 355 | if ($message_class_id != MSG_TYPE_OUTBOX) { |
||
| 356 | $SubUpdateQry[] = "`{$message_class['name']}` = '0'"; |
||
| 357 | $player[$message_class['name']] = 0; |
||
| 358 | } |
||
| 359 | } |
||
| 360 | $SubUpdateQry = implode(',', $SubUpdateQry); |
||
| 361 | } else { |
||
| 362 | $classFieldNameCurrent = static::$snMessageClassList[$current_class]['name']; |
||
| 363 | $classFieldNameNew = static::$snMessageClassList[MSG_TYPE_NEW]['name']; |
||
| 364 | $SubUpdateQry = "`{$classFieldNameCurrent}` = '0', `{$classFieldNameNew}` = `{$classFieldNameNew}` - '{$player[$classFieldNameCurrent]}'"; |
||
| 365 | $SubSelectQry = "AND `message_type` = '{$current_class}'"; |
||
| 366 | |||
| 367 | $player[static::$snMessageClassList[MSG_TYPE_NEW]['name']] -= $player[static::$snMessageClassList[$current_class]['name']]; |
||
| 368 | $player[static::$snMessageClassList[$current_class]['name']] = 0; |
||
| 369 | } |
||
| 370 | |||
| 371 | DBStaticUser::db_user_set_by_id_DEPRECATED($player['id'], $SubUpdateQry); |
||
| 372 | $message_query = static::db_message_list_by_owner_and_string($player, $SubSelectQry); |
||
| 373 | } |
||
| 374 | |||
| 375 | if (sys_get_param_int('return')) { |
||
| 376 | header('Location: messages.php'); |
||
| 377 | die(); |
||
| 378 | } |
||
| 379 | |||
| 380 | $template = gettemplate('msg_message_list', true); |
||
| 381 | static::messageRenderList($current_class, $template, $message_query); |
||
| 382 | |||
| 383 | $current_class_text = classLocale::$lang['msg_class'][$current_class]; |
||
| 384 | |||
| 385 | $template->assign_vars(array( |
||
| 386 | "MESSAGE_CLASS" => $current_class, |
||
| 387 | "MESSAGE_CLASS_TEXT" => $current_class_text, |
||
| 388 | )); |
||
| 389 | |||
| 390 | return $template; |
||
| 391 | } |
||
| 392 | |||
| 393 | |||
| 394 | /** |
||
| 395 | * @param int $current_class |
||
| 396 | * @param template $template |
||
| 397 | * @param $message_query |
||
| 398 | */ |
||
| 399 | public function messageRenderList($current_class, $template, $message_query) { |
||
| 400 | while ($message_row = db_fetch($message_query)) { |
||
| 401 | $template->assign_block_vars('messages', array( |
||
| 402 | 'ID' => $message_row['message_id'], |
||
| 403 | 'DATE' => date(FMT_DATE_TIME, $message_row['message_time'] + SN_CLIENT_TIME_DIFF), |
||
| 404 | 'FROM' => htmlspecialchars($message_row['message_from']), |
||
| 405 | 'SUBJ' => htmlspecialchars($message_row['message_subject']), |
||
| 406 | 'TEXT' => in_array($message_row['message_type'], array(MSG_TYPE_PLAYER, MSG_TYPE_ALLIANCE)) && $message_row['message_sender'] |
||
| 407 | ? nl2br(htmlspecialchars($message_row['message_text'])) |
||
| 408 | : nl2br($message_row['message_text']), |
||
| 409 | |||
| 410 | 'FROM_ID' => $message_row['message_sender'], |
||
| 411 | 'SUBJ_SANITIZED' => htmlspecialchars($message_row['message_subject']), |
||
| 412 | 'STYLE' => $current_class == MSG_TYPE_OUTBOX |
||
| 413 | ? static::$snMessageClassList[MSG_TYPE_OUTBOX]['name'] |
||
| 414 | : static::$snMessageClassList[$message_row['message_type']]['name'], |
||
| 415 | )); |
||
| 416 | } |
||
| 417 | } |
||
| 418 | |||
| 419 | |||
| 420 | // Messages ************************************************************************************************************* |
||
| 421 | public static function db_message_list_get_last_20($user, $recipient_id) { |
||
| 422 | return classSupernova::$db->doSelect( |
||
| 423 | "SELECT * FROM {{messages}} |
||
| 424 | WHERE |
||
| 425 | `message_type` = '" . MSG_TYPE_PLAYER . "' AND |
||
| 426 | ((`message_owner` = '{$user['id']}' AND `message_sender` = '{$recipient_id}') |
||
| 427 | OR |
||
| 428 | (`message_sender` = '{$user['id']}' AND `message_owner` = '{$recipient_id}')) ORDER BY `message_time` DESC LIMIT 20;"); |
||
| 429 | } |
||
| 430 | |||
| 431 | public static function db_message_list_outbox_by_user_id($user_id) { |
||
| 432 | $user_id = idval($user_id); |
||
| 433 | if (empty($user_id)) { |
||
| 434 | return false; |
||
| 435 | } |
||
| 436 | |||
| 437 | return classSupernova::$db->doSelect("SELECT {{messages}}.message_id, {{messages}}.message_owner, {{users}}.id AS message_sender, {{messages}}.message_time, |
||
| 438 | {{messages}}.message_type, {{users}}.username AS message_from, {{messages}}.message_subject, {{messages}}.message_text |
||
| 439 | FROM |
||
| 440 | {{messages}} LEFT JOIN {{users}} ON {{users}}.id = {{messages}}.message_owner WHERE `message_sender` = '{$user_id}' AND `message_type` = 1 |
||
| 441 | ORDER BY `message_time` DESC;"); |
||
| 442 | } |
||
| 443 | |||
| 444 | public static function db_message_list_by_owner_and_string($user, $SubSelectQry) { |
||
| 445 | return classSupernova::$db->doSelect("SELECT * FROM {{messages}} WHERE `message_owner` = '{$user['id']}' {$SubSelectQry} ORDER BY `message_time` DESC;"); |
||
| 446 | } |
||
| 447 | |||
| 448 | public static function db_message_count_by_owner_and_type($user) { |
||
| 449 | return classSupernova::$db->doSelect("SELECT message_owner, message_type, COUNT(message_owner) AS message_count FROM {{messages}} WHERE `message_owner` = {$user['id']} GROUP BY message_owner, message_type ORDER BY message_owner ASC, message_type;"); |
||
| 450 | } |
||
| 451 | |||
| 452 | public static function db_message_count_outbox($user) { |
||
| 453 | $row = classSupernova::$db->doSelectFetch("SELECT COUNT(message_sender) AS message_count FROM {{messages}} WHERE `message_sender` = '{$user['id']}' AND message_type = 1 GROUP BY message_sender;"); |
||
| 454 | |||
| 455 | return intval($row['message_count']); |
||
| 456 | } |
||
| 457 | |||
| 458 | public static function db_message_list_admin_by_type($int_type_selected, $StartRec) { |
||
| 459 | return classSupernova::$db->doSelect("SELECT |
||
| 460 | message_id as `ID`, |
||
| 461 | message_from as `FROM`, |
||
| 462 | message_owner as `OWNER_ID`, |
||
| 463 | u.username as `OWNER_NAME`, |
||
| 464 | message_text as `TEXT`, |
||
| 465 | FROM_UNIXTIME(message_time) as `TIME` |
||
| 466 | FROM |
||
| 467 | {{messages}} AS m |
||
| 468 | LEFT JOIN {{users}} AS u ON u.id = m.message_owner " . |
||
| 469 | ($int_type_selected >= 0 ? "WHERE `message_type` = {$int_type_selected} " : '') . |
||
| 470 | "ORDER BY |
||
| 471 | `message_id` DESC |
||
| 472 | LIMIT |
||
| 473 | {$StartRec}, 25;"); |
||
| 474 | } |
||
| 475 | |||
| 476 | public static function db_message_insert_all($message_type, $from_unsafe, $subject_unsafe, $text_unsafe) { |
||
| 477 | $message_type_safe = intval($message_type); |
||
| 478 | $from_safe = db_escape($from_unsafe); |
||
| 479 | $subject_safe = db_escape($subject_unsafe); |
||
| 480 | $text_safe = db_escape($text_unsafe); |
||
| 481 | |||
| 482 | return classSupernova::$db->doInsertComplex('INSERT INTO {{messages}} (`message_owner`, `message_sender`, `message_time`, `message_type`, `message_from`, `message_subject`, `message_text`) ' . |
||
| 483 | "SELECT `id`, 0, unix_timestamp(now()), {$message_type_safe}, '{$from_safe}', '{$subject_safe}', '{$text_safe}' FROM {{users}}"); |
||
| 484 | } |
||
| 485 | |||
| 486 | /** |
||
| 487 | * @param $int_type_selected |
||
| 488 | * |
||
| 489 | * @return array|bool|mysqli_result|null |
||
| 490 | */ |
||
| 491 | public static function db_message_count_by_type($int_type_selected) { |
||
| 496 | |||
| 497 | /** |
||
| 498 | * @param string $message_delete |
||
| 499 | */ |
||
| 500 | public static function db_message_list_delete_set($message_delete) { |
||
| 503 | |||
| 504 | public static function db_message_delete_by_id($messageId) { |
||
| 505 | classSupernova::$gc->db->doDeleteRowWhere(TABLE_MESSAGES, array('message_id' => $messageId)); |
||
| 506 | } |
||
| 507 | |||
| 508 | |||
| 509 | |||
| 510 | /** |
||
| 511 | * @param $delete_date |
||
| 512 | * @param $int_type_selected |
||
| 513 | */ |
||
| 514 | public static function db_message_list_delete_by_date($delete_date, $int_type_selected) { |
||
| 515 | $where[] = "message_time <= UNIX_TIMESTAMP('{$delete_date}')"; |
||
| 516 | if($int_type_selected >= 0) { |
||
| 517 | $where['message_type'] = $int_type_selected; |
||
| 518 | } |
||
| 519 | classSupernova::$db->doDeleteDeprecated(TABLE_MESSAGES, $where); |
||
| 521 | |||
| 522 | } |
||
| 523 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.