CliApplicationFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 42
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A newApplication() 0 8 1
A setApplicationInfo() 0 4 1
A registerCommands() 0 3 1
A newDumpCommand() 0 5 1
A getSchema() 0 6 1
1
<?php
2
3
namespace Wikibase\QueryEngine\Console;
4
5
use Doctrine\DBAL\Platforms\MySqlPlatform;
6
use Symfony\Component\Console\Application;
7
use Wikibase\QueryEngine\SQLStore\DataValueHandlersBuilder;
8
use Wikibase\QueryEngine\SQLStore\StoreSchema;
9
10
/**
11
 * Builds the QueryEngine CLI application.
12
 * It adds the QueryEngine CLI commands with some demo configuration.
13
 *
14
 * This class is package private. Applications that use QueryEngine
15
 * and that want to include QueryEngine commands in their own CLI
16
 * should use their own Application object.
17
 *
18
 * @licence GNU GPL v2+
19
 * @author Jeroen De Dauw < [email protected] >
20
 */
21
class CliApplicationFactory {
22
23
	/**
24
	 * @var Application
25
	 */
26
	private $app;
27
28
	/**
29
	 * @return Application
30
	 */
31
	public function newApplication() {
32
		$this->app = new Application();
33
34
		$this->setApplicationInfo();
35
		$this->registerCommands();
36
37
		return $this->app;
38
	}
39
40
	private function setApplicationInfo() {
41
		$this->app->setName( 'Wikibase QueryEngine CLI' );
42
		$this->app->setVersion( WIKIBASE_QUERYENGINE_VERSION );
43
	}
44
45
	private function registerCommands() {
46
		$this->app->add( $this->newDumpCommand() );
47
	}
48
49
	private function newDumpCommand() {
50
		$command = new DumpSqlCommand();
51
		$command->setDependencies( $this->getSchema(), new MySqlPlatform() );
52
		return $command;
53
	}
54
55
	private function getSchema() {
56
		$handlerBuilder = new DataValueHandlersBuilder();
57
		$handlers = $handlerBuilder->withSimpleHandlers()->getHandlers();
58
59
		return new StoreSchema( 'qr_', $handlers );
60
	}
61
62
}
63