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

PriceType::convertToPHPValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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