JsonType::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace DoS\ResourceBundle\Doctrine\Types;
4
5
use Doctrine\DBAL\Types\Type;
6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
8
/**
9
 * convert a value into a json string to be stored into the persistency layer.
10
 */
11
class JsonType extends Type
12
{
13
    const JSON = 'json'; // modify to match your type name
14
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function convertToPHPValue($value, AbstractPlatform $platform)
19
    {
20
        return json_decode($value, true);
21
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
27
    {
28
        return json_encode($value);
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getName()
35
    {
36
        return self::JSON;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
43
    {
44
        return $platform->getClobTypeDeclarationSQL($fieldDeclaration);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function requiresSQLCommentHint(AbstractPlatform $platform)
51
    {
52
        return true;
53
    }
54
}
55