| Conditions | 5 |
| Paths | 3 |
| Total Lines | 53 |
| Code Lines | 35 |
| 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 |
||
| 109 | function sendEmailsNotSent( |
||
| 110 | array $SETTINGS |
||
| 111 | ) |
||
| 112 | { |
||
| 113 | if ((int) $SETTINGS['enable_send_email_on_user_login'] === 1) { |
||
| 114 | $row = DB::queryFirstRow( |
||
| 115 | 'SELECT valeur FROM ' . prefixTable('misc') . ' WHERE type = %s AND intitule = %s', |
||
| 116 | 'cron', |
||
| 117 | 'sending_emails' |
||
| 118 | ); |
||
| 119 | |||
| 120 | if ((int) (time() - $row['valeur']) >= 300 || (int) $row['valeur'] === 0) { |
||
| 121 | $rows = DB::query( |
||
| 122 | 'SELECT * |
||
| 123 | FROM ' . prefixTable('emails') . |
||
| 124 | ' WHERE status != %s', |
||
| 125 | 'sent' |
||
| 126 | ); |
||
| 127 | foreach ($rows as $record) { |
||
| 128 | // Send email |
||
| 129 | $ret = json_decode( |
||
|
|
|||
| 130 | sendEmail( |
||
| 131 | $record['subject'], |
||
| 132 | $record['body'], |
||
| 133 | $record['receivers'], |
||
| 134 | $SETTINGS, |
||
| 135 | null, |
||
| 136 | true, |
||
| 137 | true |
||
| 138 | ), |
||
| 139 | true |
||
| 140 | ); |
||
| 141 | |||
| 142 | // update item_id in files table |
||
| 143 | DB::update( |
||
| 144 | prefixTable('emails'), |
||
| 145 | array( |
||
| 146 | 'status' => 'sent', |
||
| 147 | ), |
||
| 148 | 'increment_id = %i', |
||
| 149 | $record['increment_id'] |
||
| 150 | ); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | // update cron time |
||
| 154 | DB::update( |
||
| 155 | prefixTable('misc'), |
||
| 156 | array( |
||
| 157 | 'valeur' => time(), |
||
| 158 | ), |
||
| 159 | 'intitule = %s AND type = %s', |
||
| 160 | 'sending_emails', |
||
| 161 | 'cron' |
||
| 162 | ); |
||
| 164 | } |