Passed
Pull Request — dev/6.1.0 (#678)
by
unknown
05:15
created

CLILoader::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

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