IdentityType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 31
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 11 3
A convertToPHPValue() 0 4 2
A closureToMongo() 0 4 1
A closureToPHP() 0 4 1
1
<?php
2
3
namespace HMLB\DDDBundle\Doctrine\ODM\MongoDB\Types;
4
5
use Doctrine\ODM\MongoDB\Types\Type;
6
use MongoId;
7
use HMLB\DDD\Entity\Identity;
8
9
/**
10
 * IdentityType.
11
 *
12
 * @author Hugues Maignol <[email protected]>
13
 */
14
class IdentityType extends Type
15
{
16
    const NAME = 'ddd_identity';
17
18
    public function convertToDatabaseValue($value)
19
    {
20
        if ($value === null) {
21
            return $value;
22
        }
23
        if (!$value instanceof Identity) {
24
            $value = new Identity((string) $value);
25
        }
26
27
        return new MongoId((string) $value);
28
    }
29
30
    public function convertToPHPValue($value)
31
    {
32
        return $value === null ?: new Identity((string) $value);
33
    }
34
35
    public function closureToMongo()
36
    {
37
        return '$return = new \HMLB\DDD\Entity\Identity($value);';
38
    }
39
40
    public function closureToPHP()
41
    {
42
        return '$return = (string) $value;';
43
    }
44
}
45