Passed
Push — master ( f13f78...5c1b24 )
by Ismayil
04:22
created

Cli::bootstrap()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 5
nc 3
nop 0
dl 0
loc 8
ccs 0
cts 6
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace Elgg;
4
5
use Elgg\Cli\Command;
6
use Symfony\Component\Console\Application as ConsoleApplication;
7
8
/**
9
 * CLI bootstrap
10
 */
11
class Cli {
12
13
	/**
14
	 * @var ConsoleApplication
15
	 */
16
	protected $console;
17
18
	/**
19
	 * @var HooksRegistrationService
20
	 */
21
	protected $hooks;
22
23
	/**
24
	 * Constructor
25
	 *
26
	 * @param ConsoleApplication       $console Console application instance
27
	 * @param HooksRegistrationService $hooks   Hooks registration service
28
	 */
29 1
	public function __construct(ConsoleApplication $console, HooksRegistrationService $hooks) {
30 1
		$this->console = $console;
31 1
		$this->hooks = $hooks;
32 1
	}
33
34
	/**
35
	 * Add CLI tools to the console application
36
	 * @return void
37
	 */
38
	protected function bootstrap() {
39
		$commands = $this->hooks->trigger('commands', 'cli', null, []);
40
		foreach ($commands as $command) {
41
			if (class_exists($command) && is_subclass_of($command, Command::class)) {
0 ignored issues
show
Bug introduced by
Due to PHP Bug #53727, is_subclass_of might return inconsistent results on some PHP versions if \Elgg\Cli\Command::class can be an interface. If so, you could instead use ReflectionClass::implementsInterface.
Loading history...
42
				$this->console->add(new $command());
43
			}
44
		}
45
	}
46
47
	/**
48
	 * Bootstrap and run console application
49
	 * @return void
50
	 */
51
	public function run() {
52
		$this->bootstrap();
53
		$this->console->run();
54
	}
55
56
}
57