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

NotificationDestinationType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 5 1
A convertToPHPValue() 0 7 1
A getName() 0 4 1
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
}