| Conditions | 2 |
| Paths | 2 |
| Total Lines | 82 |
| Code Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 14 | ||
| 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 namespace EmailLog\Core; |
||
| 33 | public function log_email( $original_mail_info ) { |
||
| 34 | /** |
||
| 35 | * Hook to modify wp_mail contents before Email Log plugin logs. |
||
| 36 | * |
||
| 37 | * @param array $original_mail_info { |
||
| 38 | * @type string|array $to |
||
| 39 | * @type string $subject |
||
| 40 | * @type string $message |
||
| 41 | * @type string|array $headers |
||
| 42 | * @type string|array $attachment |
||
| 43 | * } |
||
| 44 | * |
||
| 45 | * @since 2.0.0 |
||
| 46 | */ |
||
| 47 | $original_mail_info = apply_filters( 'el_wp_mail_log', $original_mail_info ); |
||
| 48 | |||
| 49 | // Sometimes the array passed to the `wp_mail` filter may not contain all the required keys. |
||
| 50 | // See https://wordpress.org/support/topic/illegal-string-offset-attachments/. |
||
| 51 | $mail_info = wp_parse_args( |
||
| 52 | $original_mail_info, |
||
| 53 | array( |
||
| 54 | 'to' => '', |
||
| 55 | 'subject' => '', |
||
| 56 | 'message' => '', |
||
| 57 | 'headers' => '', |
||
| 58 | 'attachments' => array(), |
||
| 59 | ) |
||
| 60 | ); |
||
| 61 | |||
| 62 | $log = array( |
||
| 63 | 'to_email' => \EmailLog\Util\stringify( $mail_info['to'] ), |
||
| 64 | 'subject' => $mail_info['subject'], |
||
| 65 | 'message' => $mail_info['message'], |
||
| 66 | 'headers' => \EmailLog\Util\stringify( $mail_info['headers'], "\n" ), |
||
| 67 | 'attachment_name' => \EmailLog\Util\stringify( $mail_info['attachments'] ), |
||
| 68 | 'sent_date' => current_time( 'mysql' ), |
||
| 69 | 'ip_address' => $_SERVER['REMOTE_ADDR'], |
||
| 70 | 'result' => 1, |
||
| 71 | ); |
||
| 72 | |||
| 73 | if ( empty( $log['attachment_name'] ) ) { |
||
| 74 | $log['attachments'] = 'false'; |
||
| 75 | } else { |
||
| 76 | $log['attachments'] = 'true'; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Filters the mail info right before inserting on the table. |
||
| 81 | * |
||
| 82 | * Masked fields would use this filter to avoid modifying the original data sent to |
||
| 83 | * `wp_mail() function` |
||
| 84 | * |
||
| 85 | * @param array $log Email Log that is about to be inserted into db. |
||
| 86 | * @param array $original_mail_info Original mail info that was passed to `wp_mail` filter. |
||
| 87 | * |
||
| 88 | * @since 2.3.2 |
||
| 89 | */ |
||
| 90 | $log = apply_filters( 'el_email_log_before_insert', $log, $original_mail_info ); |
||
| 91 | |||
| 92 | $email_log = email_log(); |
||
| 93 | $email_log->table_manager->insert_log( $log ); |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Fires the `el_email_log_inserted` action right after the log is inserted in to DB. |
||
| 97 | * |
||
| 98 | * @since 2.3.0 |
||
| 99 | * |
||
| 100 | * @param array $log { |
||
| 101 | * @type string $to |
||
| 102 | * @type string $subject |
||
| 103 | * @type string $message |
||
| 104 | * @type string $headers |
||
| 105 | * @type string $attachments |
||
| 106 | * @type string $attachment_name |
||
| 107 | * @type string $sent_date |
||
| 108 | * @type string $ip_address |
||
| 109 | * @type bool $result |
||
| 110 | * } |
||
| 111 | */ |
||
| 112 | do_action( 'el_email_log_inserted', $log ); |
||
| 113 | |||
| 114 | return $original_mail_info; |
||
| 115 | } |
||
| 193 |