Test Failed
Push — master ( 8dd30c...47d367 )
by Hirofumi
49:56
created

convertToDatabaseValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Infrastructure\Persistence\Doctrine\Type;
5
6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
use Doctrine\DBAL\Types\JsonType;
8
use Shippinno\Notification\Domain\Model\Destination;
9
10
class NotificationDestinationType extends JsonType
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function convertToDatabaseValue($value, AbstractPlatform $platform = null)
16
    {
17
        /** @var Destination $value */
18
        return $value->typedJsonRepresentation();
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function convertToPHPValue($value, AbstractPlatform $platform = null)
25
    {
26
        $type = json_decode($value, true)['type'];
27
        $class = 'Shippinno\\Notification\\Domain\\Model\\' . $type;
28
29
        return $class::fromJsonRepresentation($value);
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function getName()
36
    {
37
        return 'notification_destination';
38
    }
39
}