JsonType   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 44
rs 10

5 Methods

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