Completed
Pull Request — master (#1)
by Tim
79:06 queued 13:58
created

AddressChangeContextFactory::newInstaller()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests;
6
7
use Doctrine\DBAL\Connection;
8
use Doctrine\DBAL\DriverManager;
9
use Doctrine\ORM\EntityManager;
10
use Doctrine\ORM\Mapping\Driver\XmlDriver;
11
use Doctrine\ORM\Tools\Setup;
12
13
/**
14
 * @licence GNU GPL v2+
15
 */
16
class AddressChangeContextFactory {
17
18
	private const DOCTRINE_CLASS_MAPPING_DIRECTORY = __DIR__ . '/../config/DoctrineClassMapping';
19
20
	private $config;
21
22
	private $connection;
23
24
	public function __construct( array $config ) {
25
		$this->config = $config;
26
	}
27
28
	public function getEntityManager(): EntityManager {
29
		$config = Setup::createConfiguration();
30
31
		$driver = new XmlDriver( self::DOCTRINE_CLASS_MAPPING_DIRECTORY );
32
		$config->setMetadataDriverImpl( $driver );
33
34
		return EntityManager::create( $this->getConnection(), $config );
35
	}
36
37
	private function getConnection(): Connection {
38
		if ( $this->connection === null ) {
39
			$this->connection = DriverManager::getConnection( $this->config['db'] );
40
		}
41
		return $this->connection;
42
	}
43
44
}
45