Version::convertToDatabaseValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 2
1
<?php
2
3
namespace kujaff\VersionsBundle\Type;
4
5
use Doctrine\DBAL\Platforms\AbstractPlatform;
6
use Doctrine\DBAL\Types\Type;
7
use \kujaff\VersionsBundle\Entity\Version as VersionEntity;
8
9
/**
10
 * Field base64 encoded value
11
 */
12
class Version extends Type
13
{
14
    const VERSION = 'version';
15
16
    /**
17
     * Return type name
18
     *
19
     * @return type
20
     */
21
    public function getName()
22
    {
23
        return self::VERSION;
24
    }
25
26
    /**
27
     * {@inherited}
28
     */
29
    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
30
    {
31
        if (!array_key_exists('length', $fieldDeclaration)) {
32
            $fieldDeclaration['length'] = 10;
33
        }
34
        return 'VARCHAR(' . intval($fieldDeclaration['length']) . ')';
35
    }
36
37
    /**
38
     * {@inherited}
39
     */
40
    public function convertToDatabaseValue($value, AbstractPlatform $platform)
41
    {
42
        return ($value === null) ? null : $value->asString();
43
    }
44
45
    /**
46
     * {@inherited}
47
     */
48
    public function convertToPHPValue($value, AbstractPlatform $platform)
49
    {
50
        return ($value === null) ? null : new VersionEntity($value);
51
    }
52
}
53