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