| Conditions | 12 |
| Paths | 42 |
| Total Lines | 42 |
| Code Lines | 35 |
| 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 | #!/usr/bin/env php |
||
| 61 | function send_notify_emails() { |
||
| 62 | $db = BoincDb::get(); |
||
| 63 | |||
| 64 | $t = time() - (86400 + 3600); // 1-hour slop factor |
||
| 65 | $query = "select notify.* from ".$db->db_name.".notify, ".$db->db_name.".forum_preferences where forum_preferences.pm_notification=2 and notify.userid = forum_preferences.userid and notify.create_time > $t"; |
||
| 66 | |||
| 67 | $notifies = BoincNotify::enum_general($query); |
||
| 68 | $userid = 0; |
||
| 69 | $message = ""; |
||
| 70 | $i = 1; |
||
| 71 | foreach ($notifies as $notify) { |
||
| 72 | if ($userid && $notify->userid != $userid && strlen($message)) { |
||
| 73 | send_notify_email($userid, $message); |
||
| 74 | $message = ""; |
||
| 75 | $found = false; |
||
| 76 | $i = 1; |
||
| 77 | } |
||
| 78 | $userid = $notify->userid; |
||
| 79 | $x = null; |
||
| 80 | switch ($notify->type) { |
||
| 81 | case NOTIFY_FRIEND_REQ: |
||
| 82 | $x = friend_notify_req_email_line($notify); |
||
| 83 | break; |
||
| 84 | case NOTIFY_FRIEND_ACCEPT: |
||
| 85 | $x = friend_notify_accept_email_line($notify); |
||
| 86 | break; |
||
| 87 | case NOTIFY_PM: |
||
| 88 | $x = pm_email_line($notify); |
||
| 89 | break; |
||
| 90 | case NOTIFY_SUBSCRIBED_THREAD: |
||
| 91 | $x = subscribed_thread_email_line($notify); |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | if ($x) { |
||
| 95 | $message .= "$i) $x\n"; |
||
| 96 | $i++; |
||
| 97 | } else { |
||
| 98 | $notify->delete(); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | if ($userid && strlen($message)) { |
||
| 102 | send_notify_email($userid, $message); |
||
| 103 | } |
||
| 116 |