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

engine/classes/Elgg/Cli.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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