AddressChangeContextFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 2
b 0
f 0
dl 0
loc 37
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A newEventSubscribers() 0 4 1
A registerCustomTypes() 0 2 1
A getDoctrineMappingPaths() 0 2 1
A registerDoctrinePaymentIntervalType() 0 8 2
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext;
6
7
use Doctrine\Common\EventSubscriber;
8
use Doctrine\DBAL\Connection;
9
use Doctrine\DBAL\Types\Type;
10
11
/**
12
 * @license GPL-2.0-or-later
13
 */
14
class AddressChangeContextFactory {
15
16
	/**
17
	 * Use this constant for MappingDriverChain::addDriver
18
	 */
19
	public const ENTITY_NAMESPACE = 'WMDE\Fundraising\AddressChangeContext\Domain\Model';
20
21
	private const DOCTRINE_CLASS_MAPPING_DIRECTORY = __DIR__ . '/../config/DoctrineClassMapping';
22
23
	/**
24
	 * @return string[]
25
	 */
26
	public function getDoctrineMappingPaths(): array {
27
		return [ self::DOCTRINE_CLASS_MAPPING_DIRECTORY ];
28
	}
29
30
	/**
31
	 * @return array<EventSubscriber>
32
	 */
33
	public function newEventSubscribers(): array {
34
		// Currently we don't have event subscribers, but this method helps to keep a consistent interface
35
		// with all the other context factories of the bounded contexts.
36
		return [];
37
	}
38
39
	public function registerCustomTypes( Connection $connection ): void {
40
		$this->registerDoctrinePaymentIntervalType( $connection );
41
	}
42
43
	public function registerDoctrinePaymentIntervalType( Connection $connection ): void {
44
		static $isRegistered = false;
45
		if ( $isRegistered ) {
46
			return;
47
		}
48
		Type::addType( 'AddressType', 'WMDE\Fundraising\AddressChangeContext\DataAccess\DoctrineTypes\AddressType' );
49
		$connection->getDatabasePlatform()->registerDoctrineTypeMapping( 'AddressType', 'AddressType' );
50
		$isRegistered = true;
51
	}
52
}
53