Column::__construct()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 32
Code Lines 24

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 32
rs 8.8571
cc 3
eloc 24
nc 3
nop 1
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Migration\Schema;
4
5
use Doctrine\DBAL\Schema\Column as BaseColumn;
6
7
/**
8
 * The aim of this class is to provide a way extend doctrine Column class which can be used in migrations
9
 */
10
class Column extends BaseColumn
11
{
12
    /**
13
     * Constructor
14
     *
15
     * @param array $args
16
     */
17
    public function __construct(array $args)
18
    {
19
        /** @var BaseColumn $baseColumn */
20
        $baseColumn = $args['column'];
21
22
        $optionNames = [
23
            'Length',
24
            'Precision',
25
            'Scale',
26
            'Unsigned',
27
            'Fixed',
28
            'Notnull',
29
            'Default',
30
            'Autoincrement',
31
            'Comment'
32
        ];
33
34
        $options = [];
35
        foreach ($optionNames as $name) {
36
            $method = "get" . $name;
37
            $val    = $baseColumn->$method();
38
            if ($this->$method() !== $val) {
39
                $options[$name] = $val;
40
            }
41
        }
42
        $this->_setName($baseColumn->getName());
43
        $this->_type = $baseColumn->getType();
44
        $this->setOptions($options);
45
        $this->setColumnDefinition($baseColumn->getColumnDefinition());
46
        $this->setPlatformOptions($baseColumn->getPlatformOptions());
47
        $this->setCustomSchemaOptions($baseColumn->getCustomSchemaOptions());
48
    }
49
50
    /**
51
     * Change a name of this column
52
     *
53
     * @param string $newName
54
     */
55
    public function changeName($newName)
56
    {
57
        $this->_setName($newName);
58
    }
59
}
60