EnumType   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 9 2
A closureToPHP() 0 8 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Infrastructure\System\Doctrine\ODM\MongoDB\Types;
12
13
use Cubiche\Infrastructure\Model\Doctrine\ODM\MongoDB\Types\NativeValueObjectType;
14
15
/**
16
 * EnumType Class.
17
 *
18
 * @author Ivannis Suárez Jerez <[email protected]>
19
 */
20
abstract class EnumType extends NativeValueObjectType
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function convertToDatabaseValue($value)
26
    {
27
        $class = $this->targetClass();
28
        if (!$value instanceof $class) {
29
            return $value;
30
        }
31
32
        return parent::convertToDatabaseValue($value);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function closureToPHP()
39
    {
40
        $class = $this->targetClass();
41
42
        return '
43
        $return = $value !== null && $value instanceof \\'.$class.' ? \\'.$class.'::fromNative($value) : $value;
44
        ';
45
    }
46
}
47