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

DocumentType   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 56
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
factory() 0 1 ?
getLength() 0 1 ?
isFixed() 0 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
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