| Conditions | 11 |
| Paths | 136 |
| Total Lines | 59 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 43 | public function backup( $args, $assoc_args ) { |
||
| 44 | |||
| 45 | add_action( 'hmbkp_mysqldump_started', function () { |
||
| 46 | \WP_CLI::line( __( 'Backup: Dumping database...', 'backupwordpress' ) ); |
||
| 47 | } ); |
||
| 48 | |||
| 49 | add_action( 'hmbkp_archive_started', function () { |
||
| 50 | \WP_CLI::line( __( 'Backup: Zipping everything up...', 'backupwordpress' ) ); |
||
| 51 | } ); |
||
| 52 | |||
| 53 | if ( ! empty( $assoc_args['destination'] ) ) { |
||
| 54 | Path::get_instance()->set_path( $assoc_args['destination'] ); |
||
| 55 | } |
||
| 56 | |||
| 57 | Path::get_instance()->cleanup(); |
||
| 58 | |||
| 59 | if ( ! empty( $assoc_args['root'] ) ) { |
||
| 60 | Path::get_instance()->set_root( $assoc_args['root'] ); |
||
| 61 | } |
||
| 62 | |||
| 63 | if ( ( ! is_dir( Path::get_path() ) ) ) { |
||
| 64 | \WP_CLI::error( __( 'Invalid backup path', 'backupwordpress' ) ); |
||
| 65 | return false; |
||
| 66 | } |
||
| 67 | |||
| 68 | if ( ! is_dir( Path::get_root() ) || ! is_readable( Path::get_root() ) ) { |
||
| 69 | \WP_CLI::error( __( 'Invalid root path', 'backupwordpress' ) ); |
||
| 70 | return false; |
||
| 71 | } |
||
| 72 | |||
| 73 | $filename = 'backup.zip'; |
||
| 74 | |||
| 75 | if ( isset( $assoc_args['archive_filename'] ) ) { |
||
| 76 | $filename = $assoc_args['archive_filename']; |
||
| 77 | } |
||
| 78 | |||
| 79 | $hm_backup = new Backup( $filename ); |
||
| 80 | |||
| 81 | if ( ! empty( $assoc_args['files_only'] ) ) { |
||
| 82 | $hm_backup->set_type( 'file' ); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ( ! empty( $assoc_args['database_only'] ) ) { |
||
| 86 | $hm_backup->set_type( 'database' ); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ( ! empty( $assoc_args['excludes'] ) ) { |
||
| 90 | $hm_backup->set_excludes( new Excludes( $assoc_args['excludes'] ) ); |
||
| 91 | } |
||
| 92 | |||
| 93 | $hm_backup->run(); |
||
| 94 | |||
| 95 | if ( file_exists( $hm_backup->get_backup_filepath() ) ) { |
||
| 96 | \WP_CLI::success( __( 'Backup Complete: ', 'backupwordpress' ) . $hm_backup->get_backup_filepath() ); |
||
| 97 | } else { |
||
| 98 | \WP_CLI::error( __( 'Backup Failed', 'backupwordpress' ) ); |
||
| 99 | } |
||
| 100 | |||
| 101 | } |
||
| 102 | } |
||
| 105 |