GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#936)
by Tom
02:28
created

BackUpWordPress_WP_CLI_Command::backup()   F

Complexity

Conditions 13
Paths 520

Size

Total Lines 65
Code Lines 34

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 65
rs 3.6987
cc 13
eloc 34
nc 520
nop 2

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
/**
4
 * Implement backup command
5
 *
6
 * @todo fix
7
 * @package wp-cli
8
 * @subpackage commands/third-party
9
 */
10
class BackUpWordPress_WP_CLI_Command extends WP_CLI_Command {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
12
	/**
13
	 * Perform a Backup.
14
	 *
15
	 * ## OPTIONS
16
	 *
17
	 * [--files_only]
18
	 * : Backup files only, default to off
19
	 *
20
	 * [--database_only]
21
	 * : Backup database only, defaults to off
22
	 *
23
	 * [--destination]
24
	 * : dir that the backup should be save in, defaults to your existing backups directory
25
	 *
26
	 * [--root]
27
	 * : dir that should be backed up, defaults to site root.
28
	 *
29
	 * [--zip_command_path]
30
	 * : path to your zip binary, standard locations are automatically used
31
	 *
32
	 * [--mysqldump_command_path]
33
	 * : path to your mysqldump binary, standard locations are automatically used
34
	 *
35
	 * [--archive_filename]
36
	 * : filename for the resulting zip file
37
	 *
38
	 * [--excludes]
39
	 * : list of paths you'd like to exclude
40
	 *
41
	 * ## Usage
42
	 *
43
	 *     wp backupwordpress backup [--files_only] [--database_only] [--path<dir>] [--root<dir>] [--zip_command_path=<path>] [--mysqldump_command_path=<path>]
44
	 *
45
	 * @todo errors should be bubbled from Backup, Scheduled_Backup and the like instead of being repeated.
46
	 */
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'] );
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_OBJECT_OPERATOR
Loading history...
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
113
}
114
115
WP_CLI::add_command( 'backupwordpress', 'BackUpWordPress_WP_CLI_Command' );
116