Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

Cli::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 3
cts 3
cp 1
crap 1
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, []);
0 ignored issues
show
Bug introduced by Ismayil Khayredinov
The method trigger() does not exist on Elgg\HooksRegistrationService. Since it exists in all sub-types, consider adding an abstract or default implementation to Elgg\HooksRegistrationService. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
		/** @scrutinizer ignore-call */ 
40
  $commands = $this->hooks->trigger('commands', 'cli', null, []);
Loading history...
40
		foreach ($commands as $command) {
41
			if (class_exists($command) && is_subclass_of($command, Command::class)) {
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