Completed
Pull Request — dev/6.1.0 (#678)
by
unknown
08:02 queued 05:13
created

CLILoader::get_commands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 16
ccs 0
cts 8
cp 0
crap 2
rs 10
1
<?php
2
3
namespace BulkWP\BulkDelete\Core\CLI;
4
5
use BulkWP\BulkDelete\Core\CLI\Commands\DeletePostsCommand;
6
use BulkWP\BulkDelete\Core\CLI\Commands\DeleteTermsCommand;
7
use BulkWP\BulkDelete\Core\CLI\Commands\DeleteUsersCommand;
8
use BulkWP\BulkDelete\Core\CLI\Commands\SystemInfoCommand;
9
10
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
11
12
/**
13
 * Loads all CLI command.
14
 *
15
 * @since 6.1.0
16
 */
17
class CLILoader {
18
	/**
19
	 * Base Command.
20
	 *
21
	 * @var string
22
	 */
23
	protected $base_command = 'bulk-delete';
24
25
	/**
26
	 * Load CLI command.
27
	 *
28
	 * This will be called after `bd_loaded` hook.
29
	 */
30
	public function load() {
31
		$commands = $this->get_commands();
32
33
		foreach ( $commands as $command ) {
34
			$this->register_command( $command );
35
		}
36
	}
37
38
	/**
39
	 * List of Bulk Delete WP CLI Commands.
40
	 *
41
	 * @return \BulkWP\BulkDelete\Core\Base\BaseCommand[]
42
	 */
43
	protected function get_commands() {
44
		$commands = array(
45
			SystemInfoCommand::class,
46
			DeletePostsCommand::class,
47
			DeleteTermsCommand::class,
48
			DeleteUsersCommand::class,
49
		);
50
51
		/**
52
		 * Filters the CLI command map.
53
		 *
54
		 * @since 6.1.0
55
		 *
56
		 * @param \BulkWP\BulkDelete\Core\Base\BaseCommand[] List of commands.
57
		 */
58
		return apply_filters( 'bd_cli_commands', $commands );
59
	}
60
61
	/**
62
	 * Register a command.
63
	 *
64
	 * @param \BulkWP\BulkDelete\Core\Base\BaseCommand $command Command to register.
65
	 */
66
	protected function register_command( $command ) {
67
		\WP_CLI::add_command( $this->base_command . ' ' . $command::get_command(), $command );
0 ignored issues
show
Bug introduced by
The type WP_CLI was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
68
	}
69
}
70