| Conditions | 9 |
| Paths | 9 |
| Total Lines | 56 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 155 | public function action( $action, Backup $backup ) { |
||
| 156 | |||
| 157 | if ( 'hmbkp_backup_complete' === $action && $this->get_email_address_array() ) { |
||
| 158 | |||
| 159 | $file = $backup->get_backup_filepath(); |
||
| 160 | |||
| 161 | $sent = false; |
||
| 162 | |||
| 163 | $download = add_query_arg( 'hmbkp_download', base64_encode( $file ), HMBKP_ADMIN_URL ); |
||
| 164 | $domain = parse_url( home_url(), PHP_URL_HOST ) . parse_url( home_url(), PHP_URL_PATH ); |
||
| 165 | |||
| 166 | $headers = 'From: BackUpWordPress <' . apply_filters( 'hmbkp_from_email', get_bloginfo( 'admin_email' ) ) . '>' . "\r\n"; |
||
| 167 | |||
| 168 | // The backup failed, send a message saying as much |
||
| 169 | if ( ! file_exists( $file ) && ( $errors = array_merge( $backup->get_errors(), $backup->get_warnings() ) ) ) { |
||
| 170 | |||
| 171 | $error_message = ''; |
||
| 172 | |||
| 173 | foreach ( $errors as $error_set ) { |
||
| 174 | $error_message .= implode( "\n - ", $error_set ); |
||
| 175 | } |
||
| 176 | |||
| 177 | if ( $error_message ) { |
||
| 178 | $error_message = ' - ' . $error_message; |
||
| 179 | } |
||
| 180 | |||
| 181 | $subject = sprintf( __( 'Backup of %s Failed', 'backupwordpress' ), $domain ); |
||
| 182 | |||
| 183 | $message = sprintf( __( 'BackUpWordPress was unable to backup your site %1$s.', 'backupwordpress' ) . "\n\n" . __( 'Here are the errors that we\'ve encountered:', 'backupwordpress' ) . "\n\n" . '%2$s' . "\n\n" . __( 'If the errors above look like Martian, forward this email to %3$s and we\'ll take a look', 'backupwordpress' ) . "\n\n" . __( "Kind Regards,\nThe Apologetic BackUpWordPress Backup Emailing Robot", 'backupwordpress' ), home_url(), $error_message, '[email protected]' ); |
||
| 184 | |||
| 185 | wp_mail( $this->get_email_address_array(), $subject, $message, $headers ); |
||
| 186 | |||
| 187 | return; |
||
| 188 | |||
| 189 | } |
||
| 190 | |||
| 191 | $subject = sprintf( __( 'Backup of %s', 'backupwordpress' ), $domain ); |
||
| 192 | |||
| 193 | // If it's larger than the max attachment size limit assume it's not going to be able to send the backup |
||
| 194 | if ( @filesize( $file ) < get_max_attachment_size() ) { |
||
| 195 | |||
| 196 | $message = sprintf( __( 'BackUpWordPress has completed a backup of your site %1$s.', 'backupwordpress' ) . "\n\n" . __( 'The backup file should be attached to this email.', 'backupwordpress' ) . "\n\n" . __( 'You can download the backup file by clicking the link below:', 'backupwordpress' ) . "\n\n" . '%2$s' . "\n\n" . __( "Kind Regards,\nThe Happy BackUpWordPress Backup Emailing Robot", 'backupwordpress' ), home_url(), $download ); |
||
| 197 | |||
| 198 | $sent = wp_mail( $this->get_email_address_array(), $subject, $message, $headers, $file ); |
||
| 199 | |||
| 200 | } |
||
| 201 | |||
| 202 | // If we didn't send the email above then send just the notification |
||
| 203 | if ( ! $sent ) { |
||
| 204 | |||
| 205 | $message = sprintf( __( 'BackUpWordPress has completed a backup of your site %1$s.', 'backupwordpress' ) . "\n\n" . __( 'Unfortunately, the backup file was too large to attach to this email.', 'backupwordpress' ) . "\n\n" . __( 'You can download the backup file by clicking the link below:', 'backupwordpress' ) . "\n\n" . '%2$s' . "\n\n" . __( "Kind Regards,\nThe Happy BackUpWordPress Backup Emailing Robot", 'backupwordpress' ), home_url(), $download ); |
||
| 206 | wp_mail( $this->get_email_address_array(), $subject, $message, $headers ); |
||
| 207 | |||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 221 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.