DocumentType   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 64
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
factory() 0 1 ?
getLength() 0 1 ?
A isFixed() 0 4 1
A convertToDatabaseValue() 0 8 2
A convertToPHPValue() 0 8 2
A getSQLDeclaration() 0 6 1
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
    const CNPJ = 'cnpj';
11
    const CNH = 'cnh';
12
    const PISPASEP = 'pispasep';
13
    const CNS = 'cns';
14
    const RENAVAM = 'renavam';
15
16
    abstract public function factory($number);
17
18
    abstract public function getLength();
19
20 6
    public function isFixed()
21
    {
22 6
        return true;
23
    }
24
25
    /**
26
     * Converts a value from its PHP representation to its database representation
27
     * of this type.
28
     *
29
     * @param \Brazanation\Documents\Cnpj $value The value to convert.
30
     * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform.
31
     *
32
     * @return null|string The database representation of the value.
33
     */
34 12
    public function convertToDatabaseValue($value, DBAL\Platforms\AbstractPlatform $platform)
35
    {
36 12
        if (is_null($value)) {
37 6
            return null;
38
        }
39
40 6
        return (string)$value;
41
    }
42
43
    /**
44
     * Converts a value from its database representation to its PHP representation
45
     * of this type.
46
     *
47
     * @param string $value The value to convert.
48
     * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The currently used database platform.
49
     *
50
     * @return null|\Brazanation\Documents\Cnpj The PHP representation of the value.
51
     */
52 12
    public function convertToPHPValue($value, DBAL\Platforms\AbstractPlatform $platform)
53
    {
54 12
        if (is_null($value)) {
55 6
            return null;
56
        }
57
58 6
        return $this->factory($value);
59
    }
60
61
    /**
62
     * @inheritdoc
63
     */
64 6
    public function getSQLDeclaration(array $fieldDeclaration, DBAL\Platforms\AbstractPlatform $platform)
65
    {
66 6
        $fieldDeclaration['length'] = $this->getLength();
67 6
        $fieldDeclaration['fixed'] = $this->isFixed();
68 6
        return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration);
69
    }
70
}
71