CurrencyType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 0
cbo 2
dl 0
loc 45
ccs 0
cts 12
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A convertToDatabaseValue() 0 8 2
A convertToPHPValue() 0 8 3
A closureToPHP() 0 4 1
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