NativeValueObjectType::convertToDatabaseValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 2
eloc 2
nc 2
nop 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
12
namespace Cubiche\Infrastructure\Model\Doctrine\ODM\MongoDB\Types;
13
14
/**
15
 * Abstract Native Value Object Type Class.
16
 *
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
abstract class NativeValueObjectType extends ValueObjectType
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function convertToDatabaseValue($value)
25
    {
26
        return $value !== null ? $value->toNative() : null;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function convertToPHPValue($value)
33
    {
34
        $class = $this->targetClass();
35
36
        return $value !== null ? $class::fromNative($value) : null;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function closureToMongo()
43
    {
44
        return '$return = $value !== null ? $value->toNative() : null;';
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function closureToPHP()
51
    {
52
        $class = $this->targetClass();
53
54
        return '$return = $value !== null ? \\'.$class.'::fromNative($value) : null;';
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    abstract public function targetClass();
61
}
62