Completed
Push — 677-feature/add-wp-cli-support ( edf7f9...2f7e8f )
by
unknown
05:50 queued 05:47
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\SystemInfoCommand;
7
8
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
9
10
/**
11
 * Loads all CLI command.
12
 *
13
 * @since 6.1.0
14
 */
15
class CLILoader {
16
	/**
17
	 * Base Command.
18
	 *
19
	 * @var string
20
	 */
21
	protected $base_command = 'bulk-delete';
22
23
	/**
24
	 * Load CLI command.
25
	 *
26
	 * This will be called after `bd_loaded` hook.
27
	 */
28
	public function load() {
29
		$commands = $this->get_commands();
30
31
		foreach ( $commands as $command ) {
32
			$this->register_command( $command );
33
		}
34
	}
35
36
	/**
37
	 * List of Bulk Delete WP CLI Commands.
38
	 *
39
	 * @return \BulkWP\BulkDelete\Core\Base\BaseCommand[]
40
	 */
41
	protected function get_commands() {
42
		$commands = array(
43
			SystemInfoCommand::class,
44
			DeletePostsCommand::class,
45
		);
46
47
		/**
48
		 * Filters the CLI command map.
49
		 *
50
		 * @since 6.1.0
51
		 *
52
		 * @param \BulkWP\BulkDelete\Core\Base\BaseCommand[] List of commands.
53
		 */
54
		return apply_filters( 'bd_cli_commands', $commands );
55
	}
56
57
	/**
58
	 * Register a command.
59
	 *
60
	 * @param \BulkWP\BulkDelete\Core\Base\BaseCommand $command Command to register.
61
	 */
62
	protected function register_command( $command ) {
63
		\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...
64
	}
65
}
66