EnumType::closureToPHP()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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