Conditions | 13 |
Paths | 520 |
Total Lines | 65 |
Code Lines | 34 |
Lines | 0 |
Ratio | 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 |
||
47 | public function backup( $args, $assoc_args ) { |
||
48 | |||
49 | add_action( 'hmbkp_mysqldump_started', function () { |
||
50 | WP_CLI::line( __( 'Backup: Dumping database...', 'backupwordpress' ) ); |
||
51 | } ); |
||
52 | |||
53 | add_action( 'hmbkp_archive_started', function () { |
||
54 | WP_CLI::line( __( 'Backup: Zipping everything up...', 'backupwordpress' ) ); |
||
55 | } ); |
||
56 | |||
57 | $hm_backup = new HM\BackUpWordPress\Backup(); |
||
58 | |||
59 | if ( ! empty( $assoc_args['destination'] ) ) { |
||
60 | HM\BackUpWordPress\Path::get_instance()->set_path( $assoc_args['destination'] ); |
||
61 | } |
||
62 | |||
63 | HM\BackUpWordPress\Path::get_instance()->cleanup(); |
||
64 | |||
65 | if ( ! empty( $assoc_args['root'] ) ) { |
||
66 | HM\BackUpWordPress\Path->set_root( $assoc_args['root'] ); |
||
67 | } |
||
68 | |||
69 | if ( ( ! is_dir( Path::get_path() ) ) ) { |
||
70 | WP_CLI::error( __( 'Invalid backup path', 'backupwordpress' ) ); |
||
71 | return false; |
||
72 | } |
||
73 | |||
74 | if ( ! is_dir( Path::get_root() ) || ! is_readable( Path::get_root() ) ) { |
||
75 | WP_CLI::error( __( 'Invalid root path', 'backupwordpress' ) ); |
||
76 | return false; |
||
77 | } |
||
78 | |||
79 | if ( isset( $assoc_args['archive_filename'] ) ) { |
||
80 | $hm_backup->set_archive_filename( $assoc_args['archive_filename'] ); |
||
81 | } |
||
82 | |||
83 | if ( ! empty( $assoc_args['files_only'] ) ) { |
||
84 | $hm_backup->set_type( 'file' ); |
||
85 | } |
||
86 | |||
87 | if ( ! empty( $assoc_args['database_only'] ) ) { |
||
88 | $hm_backup->set_type( 'database' ); |
||
89 | } |
||
90 | |||
91 | if ( isset( $assoc_args['mysqldump_command_path'] ) ) { |
||
92 | $hm_backup->set_mysqldump_command_path( $assoc_args['mysqldump_command_path'] ); |
||
93 | } |
||
94 | |||
95 | if ( isset( $assoc_args['zip_command_path'] ) ) { |
||
96 | $hm_backup->set_zip_command_path( $assoc_args['zip_command_path'] ); |
||
97 | } |
||
98 | |||
99 | if ( ! empty( $assoc_args['excludes'] ) ) { |
||
100 | $hm_backup->set_excludes( $assoc_args['excludes'] ); |
||
101 | } |
||
102 | |||
103 | $hm_backup->backup(); |
||
104 | |||
105 | if ( file_exists( $hm_backup->get_archive_filepath() ) ) { |
||
106 | WP_CLI::success( __( 'Backup Complete: ', 'backupwordpress' ) . $hm_backup->get_archive_filepath() ); |
||
107 | } else { |
||
108 | WP_CLI::error( __( 'Backup Failed', 'backupwordpress' ) ); |
||
109 | } |
||
110 | |||
111 | } |
||
112 | |||
116 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.