TermStoreInstaller   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 59
ccs 34
cts 34
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A install() 0 4 1
A newLabelTable() 0 15 1
A newAliasesTable() 0 15 1
A uninstall() 0 4 1
1
<?php
2
3
namespace Queryr\TermStore;
4
5
use Doctrine\DBAL\DBALException;
6
use Doctrine\DBAL\Schema\AbstractSchemaManager;
7
use Doctrine\DBAL\Schema\Table;
8
use Doctrine\DBAL\Types\Type;
9
10
/**
11
 * Package public, except for the constructor
12
 * @since 0.2
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class TermStoreInstaller {
18
19
	private $schemaManager;
20
	private $config;
21
22 2
	public function __construct( AbstractSchemaManager $schemaManager, TermStoreConfig $config ) {
23 2
		$this->schemaManager = $schemaManager;
24 2
		$this->config = $config;
25 2
	}
26
27
	/**
28
	 * @throws DBALException
29
	 */
30 2
	public function install(): void {
31 2
		$this->schemaManager->createTable( $this->newLabelTable() );
32 2
		$this->schemaManager->createTable( $this->newAliasesTable() );
33 2
	}
34
35 2
	private function newLabelTable(): Table {
36 2
		$table = new Table( $this->config->getLabelTableName() );
37
38 2
		$table->addColumn( 'text', Type::STRING, array( 'length' => 255 ) );
39 2
		$table->addColumn( 'text_lowercase', Type::STRING, array( 'length' => 255 ) );
40 2
		$table->addColumn( 'language', Type::STRING, array( 'length' => 16 ) );
41 2
		$table->addColumn( 'entity_id', Type::STRING, array( 'length' => 32 ) );
42 2
		$table->addColumn( 'entity_type', Type::STRING, array( 'length' => 16 ) );
43
44 2
		$table->addIndex( array( 'text_lowercase', 'language' ) );
45 2
		$table->addIndex( array( 'entity_id', 'language' ) );
46 2
		$table->addIndex( array( 'entity_type' ) );
47
48 2
		return $table;
49
	}
50
51 2
	private function newAliasesTable(): Table {
52 2
		$table = new Table( $this->config->getAliasesTableName() );
53
54 2
		$table->addColumn( 'text', Type::STRING, array( 'length' => 255 ) );
55 2
		$table->addColumn( 'text_lowercase', Type::STRING, array( 'length' => 255 ) );
56 2
		$table->addColumn( 'language', Type::STRING, array( 'length' => 16 ) );
57 2
		$table->addColumn( 'entity_id', Type::STRING, array( 'length' => 32 ) );
58 2
		$table->addColumn( 'entity_type', Type::STRING, array( 'length' => 16 ) );
59
60 2
		$table->addIndex( array( 'text_lowercase', 'language' ) );
61 2
		$table->addIndex( array( 'entity_id', 'language' ) );
62 2
		$table->addIndex( array( 'entity_type' ) );
63
64 2
		return $table;
65
	}
66
67
	/**
68
	 * @throws DBALException
69
	 */
70 1
	public function uninstall(): void {
71 1
		$this->schemaManager->dropTable( $this->config->getLabelTableName() );
72 1
		$this->schemaManager->dropTable( $this->config->getAliasesTableName() );
73 1
	}
74
75
}