| Conditions | 5 |
| Paths | 5 |
| Total Lines | 54 |
| Code Lines | 29 |
| 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 |
||
| 58 | function chess_notify_item_info($category, $item_id) |
||
| 59 | { |
||
| 60 | if ('global' == $category) { |
||
| 61 | $item['name'] = 'Chess'; |
||
|
|
|||
| 62 | |||
| 63 | $item['url'] = XOOPS_URL . '/modules/chess/'; |
||
| 64 | |||
| 65 | return $item; |
||
| 66 | } elseif ('game' == $category) { |
||
| 67 | global $xoopsDB; |
||
| 68 | |||
| 69 | $table = $xoopsDB->prefix('chess_games'); |
||
| 70 | |||
| 71 | $result = $xoopsDB->query( |
||
| 72 | trim( |
||
| 73 | " |
||
| 74 | SELECT white_uid, black_uid, UNIX_TIMESTAMP(start_date) AS start_date |
||
| 75 | FROM $table |
||
| 76 | WHERE game_id = '$item_id' |
||
| 77 | " |
||
| 78 | ) |
||
| 79 | ); |
||
| 80 | |||
| 81 | $gamedata = $xoopsDB->fetchArray($result); |
||
| 82 | |||
| 83 | $xoopsDB->freeRecordSet($result); |
||
| 84 | |||
| 85 | if (false !== $gamedata) { |
||
| 86 | // get mapping of user IDs to usernames |
||
| 87 | |||
| 88 | $criteria = new \Criteria('uid', "({$gamedata['white_uid']}, {$gamedata['black_uid']})", 'IN'); |
||
| 89 | |||
| 90 | $memberHandler = xoops_getHandler('member'); |
||
| 91 | |||
| 92 | $usernames = $memberHandler->getUserList($criteria); |
||
| 93 | |||
| 94 | $username_white = $usernames[$gamedata['white_uid']] ?? _MD_CHESS_NA; |
||
| 95 | |||
| 96 | $username_black = $usernames[$gamedata['black_uid']] ?? _MD_CHESS_NA; |
||
| 97 | |||
| 98 | $date = $gamedata['start_date'] ? date('Y.m.d', $gamedata['start_date']) : _MD_CHESS_NA; |
||
| 99 | } else { |
||
| 100 | $username_white = _MD_CHESS_NA; |
||
| 101 | |||
| 102 | $username_black = _MD_CHESS_NA; |
||
| 103 | |||
| 104 | $date = _MD_CHESS_NA; |
||
| 105 | } |
||
| 106 | |||
| 107 | $item['name'] = "$username_white " . _MD_CHESS_LABEL_VS . " $username_black ($date)"; |
||
| 108 | |||
| 109 | $item['url'] = XOOPS_URL . '/modules/chess/game.php?game_id=' . $item_id; |
||
| 110 | |||
| 111 | return $item; |
||
| 112 | } |
||
| 114 |