Completed
Pull Request — master (#32)
by Sascha-Oliver
19:51
created

CurrencyType::convertToDatabaseValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
crap 6
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
    public function getName()
13
    {
14
        return self::NAME;
15
    }
16
17
    public function convertToDatabaseValue($value)
18
    {
19
        if ($value) {
20
            return (string) $value;
21
        }
22
23
        return null;
24
    }
25
26
    public function convertToPHPValue($value)
27
    {
28
        if ($value === null || $value instanceof Currency) {
29
            return $value;
30
        }
31
32
        return new Currency($value);
33
    }
34
35
    public function closureToPHP()
36
    {
37
        return '$return = new \Money\Currency($value);';
38
    }
39
}
40