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