IdentityType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 0
cbo 4
dl 0
loc 41
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSqlDeclaration() 0 4 1
A convertToPHPValue() 0 8 2
A convertToDatabaseValue() 0 12 3
A requiresSQLCommentHint() 0 4 1
A getName() 0 4 1
1
<?php
2
3
declare (strict_types = 1);
4
5
namespace HMLB\DDDBundle\Doctrine\ORM\DBAL\Types;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Types\ConversionException;
9
use Doctrine\DBAL\Types\Type;
10
use HMLB\DDD\Entity\Identity;
11
12
/**
13
 * IdentityType.
14
 *
15
 * @author Hugues Maignol <[email protected]>
16
 */
17
class IdentityType extends Type
18
{
19
    const NAME = 'ddd_identity';
20
21
    public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
22
    {
23
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
24
    }
25
26
    public function convertToPHPValue($value, AbstractPlatform $platform)
27
    {
28
        if (null === $value) {
29
            return;
30
        }
31
32
        return new Identity($value);
33
    }
34
35
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
36
    {
37
        if (empty($value)) {
38
            return;
39
        }
40
41
        if ($value instanceof Identity) {
42
            return (string) $value;
43
        }
44
45
        throw ConversionException::conversionFailed($value, self::NAME);
46
    }
47
48
    public function requiresSQLCommentHint(AbstractPlatform $platform)
49
    {
50
        return true;
51
    }
52
53
    public function getName()
54
    {
55
        return self::NAME;
56
    }
57
}
58