| Conditions | 8 |
| Paths | 64 |
| Total Lines | 53 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 50 | public function backup_database() { |
||
| 51 | |||
| 52 | if ( $this->status ) { |
||
| 53 | $this->status->set_status( __( 'Backing up database...', 'backupwordpress' ) ); |
||
| 54 | } |
||
| 55 | |||
| 56 | $database_backup_engines = apply_filters( 'hmbkp_database_backup_engines', array( |
||
| 57 | new Mysqldump_Database_Backup_Engine, |
||
| 58 | new IMysqldump_Database_Backup_Engine |
||
| 59 | ) ); |
||
| 60 | |||
| 61 | // Set the file backup engine settings |
||
| 62 | if ( $this->database_dump_filename ) { |
||
| 63 | foreach( $database_backup_engines as &$backup_engine ) { |
||
| 64 | $backup_engine->set_backup_filename( $this->database_dump_filename ); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | // Dump the database |
||
| 69 | $database_dump = $this->perform_backup( $database_backup_engines ); |
||
| 70 | |||
| 71 | if ( is_a( $database_dump, __NAMESPACE__ . '\\Backup_Engine' ) ) { |
||
| 72 | $this->database_dump_filepath = $database_dump->get_backup_filepath(); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Fire up the file backup engines |
||
| 76 | $file_backup_engines = apply_filters( 'hmbkp_file_backup_engines', array( |
||
| 77 | new Zip_File_Backup_Engine, |
||
| 78 | new Zip_Archive_File_Backup_Engine |
||
| 79 | ) ); |
||
| 80 | |||
| 81 | // Set the file backup engine settings |
||
| 82 | foreach( $file_backup_engines as &$backup_engine ) { |
||
| 83 | $backup_engine->set_backup_filename( $this->backup_filename ); |
||
| 84 | $backup_engine->set_excludes( new Excludes( array( '*.zip', 'index.html', '.htaccess', '.*-running' ) ) ); |
||
| 85 | } |
||
| 86 | |||
| 87 | // Zip up the database dump |
||
| 88 | $root = Path::get_root(); |
||
| 89 | Path::get_instance()->set_root( Path::get_path() ); |
||
| 90 | $file_backup = $this->perform_backup( $file_backup_engines ); |
||
| 91 | Path::get_instance()->set_root( $root ); |
||
| 92 | |||
| 93 | if ( is_a( $file_backup, __NAMESPACE__ . '\\Backup_Engine' ) ) { |
||
| 94 | $this->backup_filepath = $file_backup->get_backup_filepath(); |
||
| 95 | } |
||
| 96 | |||
| 97 | // Delete the Database Backup now that we've zipped it up |
||
| 98 | if ( file_exists( $this->database_dump_filepath ) ) { |
||
| 99 | unlink( $this->database_dump_filepath ); |
||
| 100 | } |
||
| 101 | |||
| 102 | } |
||
| 103 | |||
| 190 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.