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

CLILoader::get_commands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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