Failed Conditions
Push — master ( 5e6761...398dce )
by Adrien
04:14 queued 01:57
created

CHFType::convertToPHPValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
cc 2
rs 10
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\DBAL\Types;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Types\IntegerType;
9
use Money\Money;
10
11
class CHFType extends IntegerType
12
{
13
    public function getName()
14
    {
15
        return 'CHF';
16
    }
17
18 2
    public function convertToPHPValue($value, AbstractPlatform $platform)
19
    {
20 2
        if ($value === null) {
21 1
            return $value;
22
        }
23
24 2
        $val = Money::CHF($value);
25
26 1
        return $val;
27
    }
28
29 2
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
30
    {
31 2
        if ($value instanceof Money) {
32
            return $value->getAmount();
33
        }
34
35 2
        if ($value === null) {
36 1
            return $value;
37
        }
38
39 1
        throw new \InvalidArgumentException('Cannot convert to dababase value: ' . var_export($value, true));
40
    }
41
42 1
    public function requiresSQLCommentHint(AbstractPlatform $platform)
43
    {
44 1
        return true;
45
    }
46
}
47