Conditions | 8 |
Paths | 64 |
Total Lines | 53 |
Code Lines | 26 |
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 |
||
54 | public function backup_database() { |
||
55 | |||
56 | if ( $this->status ) { |
||
57 | $this->status->set_status( __( 'Backing up database...', 'backupwordpress' ) ); |
||
58 | } |
||
59 | |||
60 | $database_backup_engines = apply_filters( 'hmbkp_database_backup_engines', array( |
||
61 | new Mysqldump_Database_Backup_Engine, |
||
62 | new IMysqldump_Database_Backup_Engine |
||
63 | ) ); |
||
64 | |||
65 | // Set the file backup engine settings |
||
66 | if ( $this->database_dump_filename ) { |
||
67 | foreach( $database_backup_engines as &$backup_engine ) { |
||
68 | $backup_engine->set_backup_filename( $this->database_dump_filename ); |
||
69 | } |
||
70 | } |
||
71 | |||
72 | // Dump the database |
||
73 | $database_dump = $this->perform_backup( $database_backup_engines ); |
||
74 | |||
75 | if ( is_a( $database_dump, __NAMESPACE__ . '\\Backup_Engine' ) ) { |
||
76 | $this->database_dump_filepath = $database_dump->get_backup_filepath(); |
||
77 | } |
||
78 | |||
79 | // Fire up the file backup engines |
||
80 | $file_backup_engines = apply_filters( 'hmbkp_file_backup_engines', array( |
||
81 | new Zip_File_Backup_Engine, |
||
82 | new Zip_Archive_File_Backup_Engine |
||
83 | ) ); |
||
84 | |||
85 | // Set the file backup engine settings |
||
86 | foreach( $file_backup_engines as &$backup_engine ) { |
||
87 | $backup_engine->set_backup_filename( $this->backup_filename ); |
||
88 | $backup_engine->set_excludes( new Excludes( array( '*.zip', 'index.html', '.htaccess', '.*-running' ) ) ); |
||
89 | } |
||
90 | |||
91 | // Zip up the database dump |
||
92 | $root = Path::get_root(); |
||
93 | Path::get_instance()->set_root( Path::get_path() ); |
||
94 | $file_backup = $this->perform_backup( $file_backup_engines ); |
||
95 | Path::get_instance()->set_root( $root ); |
||
96 | |||
97 | if ( is_a( $file_backup, __NAMESPACE__ . '\\Backup_Engine' ) ) { |
||
98 | $this->backup_filepath = $file_backup->get_backup_filepath(); |
||
99 | } |
||
100 | |||
101 | // Delete the Database Backup now that we've zipped it up |
||
102 | if ( file_exists( $this->database_dump_filepath ) ) { |
||
103 | unlink( $this->database_dump_filepath ); |
||
104 | } |
||
105 | |||
106 | } |
||
107 | |||
215 |
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
@return
annotation as described here.