Passed
Push — 677-feature/add-wp-cli-support ( 8a68ba...d28ac0 )
by Sudar
05:15
created

CLILoader::get_commands()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
ccs 0
cts 6
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\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
	/**
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 = [
44
			SystemInfoCommand::class,
45
			DeletePostsCommand::class,
46
		];
47
48
		/**
49
		 * Filters the CLI command map.
50
		 *
51
		 * @since 6.1.0
52
		 *
53
		 * @param \BulkWP\BulkDelete\Core\Base\BaseCommand[] List of commands.
54
		 */
55
		return apply_filters( 'bd_cli_commands', $commands );
56
	}
57
58
	/**
59
	 * Register a command.
60
	 *
61
	 * @param \BulkWP\BulkDelete\Core\Base\BaseCommand $command Command to register.
62
	 */
63
	protected function register_command( $command ) {
64
		\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...
65
	}
66
}
67