Column   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 41
ccs 0
cts 21
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 14 3
A create() 0 11 2
1
<?php
2
3
namespace CodexShaper\DBM\Database\Schema;
4
5
use Doctrine\DBAL\Schema\Column as DoctrineColumn;
6
use Doctrine\DBAL\Types\Type as DoctrineType;
7
8
class Column
9
{
10
    /**
11
     * Create new column.
12
     *
13
     * @param array $column
14
     *
15
     * @return \Doctrine\DBAL\Schema\Column
16
     */
17
    public static function create($column)
18
    {
19
        $name = $column['name'];
20
        $type = $column['type'];
21
        $type = ($type instanceof DoctrineType) ? $type : DoctrineType::getType(trim($type['name']));
22
23
        $options = array_diff_key($column, ['name' => $name, 'type' => $type]);
24
25
        $DoctrineColumn = new DoctrineColumn($name, $type, $options);
26
27
        return $DoctrineColumn;
28
    }
29
30
    /**
31
     * Get all columns as an array.
32
     *
33
     * @return array
34
     */
35
    public static function toArray(DoctrineColumn $column)
36
    {
37
        $type = $column->getType();
38
39
        $newColumn = $column->toArray();
40
        $newColumn['oldName'] = $column->getName();
41
        $newColumn['type'] = [
42
            'name' => $type->getName(),
43
        ];
44
        $newColumn['null'] = $column->getNotnull() ? 'NO' : 'YES';
45
        $newColumn['extra'] = $column->getAutoincrement() ? 'auto_increment' : '';
46
        $newColumn['composite'] = false;
47
48
        return $newColumn;
49
    }
50
}
51