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

AddressType::convertToDatabaseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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