CurrencyType::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace ZFBrasil\DoctrineMoneyModule\ODM\MongoDB\Types;
4
5
use Doctrine\ODM\MongoDB\Types\Type;
6
use Money\Currency;
7
8
class CurrencyType extends Type
9
{
10
    const NAME = 'currency';
11
12
    /**
13
     * @return string
14
     */
15
    public function getName()
16
    {
17
        return self::NAME;
18
    }
19
20
    /**
21
     * @param mixed $value
22
     *
23
     * @return null|string
24
     */
25
    public function convertToDatabaseValue($value)
26
    {
27
        if ($value) {
28
            return (string) $value;
29
        }
30
31
        return null;
32
    }
33
34
    /**
35
     * @param string $value
36
     *
37
     * @return string|Currency
38
     */
39
    public function convertToPHPValue($value)
40
    {
41
        if ($value === null || $value instanceof Currency) {
42
            return $value;
43
        }
44
45
        return new Currency($value);
46
    }
47
48
    public function closureToPHP()
49
    {
50
        return '$return = new \Money\Currency($value);';
51
    }
52
}
53