Conditions | 12 |
Paths | 264 |
Total Lines | 66 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
43 | public function backup( $args, $assoc_args ) { |
||
44 | |||
45 | if ( ! empty( $assoc_args['destination'] ) ) { |
||
46 | Path::get_instance()->set_path( $assoc_args['destination'] ); |
||
47 | } |
||
48 | |||
49 | Path::get_instance()->cleanup(); |
||
50 | |||
51 | if ( ! empty( $assoc_args['root'] ) ) { |
||
52 | Path::get_instance()->set_root( $assoc_args['root'] ); |
||
53 | } |
||
54 | |||
55 | if ( ( ! is_dir( Path::get_path() ) ) ) { |
||
56 | \WP_CLI::error( __( 'Invalid backup path', 'backupwordpress' ) ); |
||
57 | return false; |
||
58 | } |
||
59 | |||
60 | if ( ! is_dir( Path::get_root() ) || ! is_readable( Path::get_root() ) ) { |
||
61 | \WP_CLI::error( __( 'Invalid root path', 'backupwordpress' ) ); |
||
62 | return false; |
||
63 | } |
||
64 | |||
65 | $filename = 'backup.zip'; |
||
66 | |||
67 | if ( isset( $assoc_args['archive_filename'] ) ) { |
||
68 | $filename = $assoc_args['archive_filename']; |
||
69 | } |
||
70 | |||
71 | $status = new Backup_Status( 'backup' ); |
||
72 | $status->set_status_callback( function( $message ) { |
||
73 | \WP_CLI::line( $message ); |
||
74 | } ); |
||
75 | |||
76 | if ( $status->is_running() ) { |
||
77 | \WP_CLI::error( 'There\'s a backup already running' ); |
||
78 | } |
||
79 | |||
80 | $status->start( $filename, __( 'Starting backup...', 'backupwordpress' ) ); |
||
81 | |||
82 | $backup = new Backup( $filename ); |
||
83 | $backup->set_status( $status ); |
||
84 | |||
85 | |||
86 | if ( ! empty( $assoc_args['files_only'] ) ) { |
||
87 | $backup->set_type( 'file' ); |
||
88 | } |
||
89 | |||
90 | if ( ! empty( $assoc_args['database_only'] ) ) { |
||
91 | $backup->set_type( 'database' ); |
||
92 | } |
||
93 | |||
94 | if ( ! empty( $assoc_args['excludes'] ) ) { |
||
95 | $backup->set_excludes( new Excludes( $assoc_args['excludes'] ) ); |
||
96 | } |
||
97 | |||
98 | $backup->run(); |
||
99 | |||
100 | if ( file_exists( $backup->get_backup_filepath() ) ) { |
||
101 | \WP_CLI::success( __( 'Backup Complete: ', 'backupwordpress' ) . $backup->get_backup_filepath() ); |
||
102 | } else { |
||
103 | \WP_CLI::error( __( 'Backup Failed', 'backupwordpress' ) ); |
||
104 | } |
||
105 | |||
106 | $status->finish(); |
||
107 | |||
108 | } |
||
109 | } |
||
112 |