Passed
Push — main ( c73e00...0a00da )
by
unknown
15:13 queued 14s
created

AddressType   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 1
b 0
f 0
dl 0
loc 31
ccs 0
cts 18
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 2 1
A getSQLDeclaration() 0 2 1
A convertToPHPValue() 0 6 1
A convertToDatabaseValue() 0 6 1
1
<?php
2
3
namespace WMDE\Fundraising\AddressChangeContext\DataAccess\DoctrineTypes;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Types\Type;
7
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressType as DomainAddressType;
8
9
class AddressType extends Type {
10
	public function getSQLDeclaration( array $column, AbstractPlatform $platform ): string {
11
		return 'VARCHAR(10)';
12
	}
13
14
	public function convertToPHPValue( mixed $value, AbstractPlatform $platform ): DomainAddressType {
15
		return match ( $value ) {
16
			'person' => DomainAddressType::Person,
17
			'company' => DomainAddressType::Company,
18
			default => throw new \InvalidArgumentException(
19
				"Could not convert address type string ({$value}) to enum"
20
			),
21
		};
22
	}
23
24
	public function convertToDatabaseValue( mixed $value, AbstractPlatform $platform ): string {
25
		return match ( $value ) {
26
			DomainAddressType::Person => 'person',
27
			DomainAddressType::Company => 'company',
28
			default => throw new \InvalidArgumentException(
29
				"Could not convert address type enum ({$value}) to string"
30
			),
31
		};
32
	}
33
34
	/**
35
	 * @codeCoverageIgnore
36
	 * @return string
37
	 */
38
	public function getName(): string {
39
		return 'AddressType';
40
	}
41
42
}
43