Passed
Push — master ( ac61c8...3f5524 )
by Antonio Oertel
01:50
created

DocumentType::convertToPHPValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
nc 2
cc 2
eloc 4
nop 2
crap 2
1
<?php
2
3
namespace Brazanation\Doctrine;
4
5
use Doctrine\DBAL;
6
7
abstract class DocumentType extends DBAL\Types\StringType
8
{
9
    const CPF = 'cpf';
10
11
    abstract public function factory($number);
12
13
    abstract public function getLength();
14
15
    abstract public function isFixed();
16
17
    /**
18
     * Converts a value from its PHP representation to its database representation
19
     * of this type.
20
     *
21
     * @param \Brazanation\Documents\Cnpj $value The value to convert.
22
     * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform.
23
     *
24
     * @return null|string The database representation of the value.
25
     */
26 2
    public function convertToDatabaseValue($value, DBAL\Platforms\AbstractPlatform $platform)
27
    {
28 2
        if (is_null($value)) {
29 1
            return null;
30
        }
31
32 1
        return (string)$value;
33
    }
34
35
    /**
36
     * Converts a value from its database representation to its PHP representation
37
     * of this type.
38
     *
39
     * @param string $value The value to convert.
40
     * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform.
41
     *
42
     * @return null|\Brazanation\Documents\Cnpj The PHP representation of the value.
43
     */
44 2
    public function convertToPHPValue($value, DBAL\Platforms\AbstractPlatform $platform)
45
    {
46 2
        if (is_null($value)) {
47 1
            return null;
48
        }
49
50 1
        return $this->factory($value);
51
    }
52
53
    /**
54
     * @inheritdoc
55
     */
56 1
    public function getSQLDeclaration(array $fieldDeclaration, DBAL\Platforms\AbstractPlatform $platform)
57
    {
58 1
        $fieldDeclaration['length'] = $this->getLength();
59 1
        $fieldDeclaration['fixed'] = $this->isFixed();
60 1
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
61
    }
62
}
63