NativeValueObjectType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 43
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 4 2
A convertToPHPValue() 0 6 2
A closureToMongo() 0 4 1
A closureToPHP() 0 6 1
targetClass() 0 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