TermStoreFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Queryr\TermStore;
4
5
use Doctrine\DBAL\Connection;
6
7
/**
8
 * Package public
9
 * @since 0.2
10
 *
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 */
14
class TermStoreFactory {
15
16
	private $connection;
17
	private $config;
18
19
	public function __construct( Connection $connection, TermStoreConfig $config ) {
20
		$this->connection = $connection;
21
		$this->config = $config;
22
	}
23
24
	public function newTermStoreInstaller(): TermStoreInstaller {
25
		return new TermStoreInstaller(
26
			$this->connection->getSchemaManager(),
27
			$this->config
28
		);
29
	}
30
31
	public function newEntityIdLookup(): EntityIdLookup {
32
		$labelTable = new TableQueryExecutor( $this->connection, $this->config->getLabelTableName() );
33
		$aliasesTable = new TableQueryExecutor( $this->connection, $this->config->getAliasesTableName() );
34
35
		return new IdLookup( $labelTable, $aliasesTable );
36
	}
37
38
	public function newTermStoreWriter(): TermStoreWriter {
39
		return new TermStoreWriter( $this->connection, $this->config );
40
	}
41
42
	public function newLabelLookup(): LabelLookup {
43
		return $this->newTermStore();
44
	}
45
46
	/**
47
	 * Work with a more segregated interface (TermStoreWriter, EntityIdLookup, LabelLookup) if you can.
48
	 */
49
	public function newTermStore(): TermStore {
50
		return new TermStore( $this->connection, $this->config );
51
	}
52
53
}