Passed
Push — master ( 6a2ed6...6afdcd )
by Hirofumi
02:31
created

NotificationIdType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 45
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A convertToDatabaseValue() 0 10 2
A convertToPHPValue() 0 4 1
A getName() 0 4 1
A getSQLDeclaration() 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\IntegerType;
8
use Doctrine\DBAL\Types\Type;
9
use Shippinno\Notification\Domain\Model\NotificationId;
10
11
class NotificationIdType extends Type
12
{
13
    /**
14
     * {@inheritdoc}
15
     */
16 2
    public function convertToDatabaseValue($value, AbstractPlatform $platform = null)
17
    {
18
        // For Doctrine 2.5
19 2
        if (is_int($value)) {
20
            return $value;
21
        }
22
23
        /** @var NotificationId $value */
24 2
        return $value->id();
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 4
    public function convertToPHPValue($value, AbstractPlatform $platform = null)
31
    {
32 4
        return new NotificationId((int) $value);
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 3
    public function getName()
39
    {
40 3
        return 'notification_id';
41
    }
42
43
    /**
44
     * Gets the SQL declaration snippet for a field of this type.
45
     *
46
     * @param array $fieldDeclaration The field declaration.
47
     * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform.
48
     *
49
     * @return string
50
     */
51 3
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
52
    {
53 3
        return $platform->getIntegerTypeDeclarationSQL($fieldDeclaration);
54
    }
55
}
56