Passed
Push — master ( 1c2ae4...dc8a95 )
by Svaťa
04:54
created

PriceType::convertToDatabaseValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Simara\Cart\Infrastructure\DoctrineMapping;
6
7
use Doctrine\DBAL\Platforms\AbstractPlatform;
8
use Doctrine\DBAL\Types\Type;
9
use Simara\Cart\Domain\Price;
10
11
class PriceType extends Type
12
{
13
    const NAME = 'priceType';
14
15 9
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
16
    {
17 9
        return 'VARCHAR(255)';
18
    }
19 7
    public function convertToPHPValue($value, AbstractPlatform $platform)
20
    {
21 7
        return new Price((float) $value);
22
    }
23 7
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
24
    {
25 7
        if ($value instanceof Price) {
26 7
            return (string) $value->getWithVat();
27
        }
28
        return $value;
29
    }
30 9
    public function getName()
31
    {
32 9
        self::NAME;
33 9
    }
34
}
35