Column   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 65
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createColumnDefinition() 0 9 2
A getSupportedTypes() 0 4 1
1
<?php
2
3
namespace Soluble\Datatype;
4
5
use Soluble\Datatype\Column\Definition;
6
7
class Column
8
{
9
    const TYPE_INTEGER = 'integer';
10
    const TYPE_DECIMAL = 'decimal';
11
    const TYPE_STRING = 'string';
12
    const TYPE_BOOLEAN = 'boolean';
13
    const TYPE_DATETIME = 'datetime';
14
    const TYPE_BLOB = 'blob';
15
    const TYPE_DATE = 'date';
16
    const TYPE_TIME = 'time';
17
    const TYPE_FLOAT = 'float';
18
    const TYPE_BIT = 'bit';
19
    const TYPE_SPATIAL_GEOMETRY = 'geometry';
20
    const TYPE_NULL = 'null';
21
22
    /**
23
     * @var array
24
     */
25
    protected static $typesMap = [
26
        self::TYPE_INTEGER => 'Definition\IntegerColumn',
27
        self::TYPE_DECIMAL => 'Definition\DecimalColumn',
28
        self::TYPE_STRING => 'Definition\StringColumn',
29
        self::TYPE_BOOLEAN => 'Definition\BooleanColumn',
30
        self::TYPE_DATETIME => 'Definition\DatetimeColumn',
31
        self::TYPE_BLOB => 'Definition\BlobColumn',
32
        self::TYPE_DATE => 'Definition\DateColumn',
33
        self::TYPE_TIME => 'Definition\TimeColumn',
34
        self::TYPE_FLOAT => 'Definition\FloatColumn',
35
        self::TYPE_BIT => 'Definition\BitColumn',
36
        self::TYPE_SPATIAL_GEOMETRY => 'Definition\GeometryColumn',
37
        self::TYPE_NULL => 'Definition\NullColumn',
38
    ];
39
40
    /**
41
     * Create a data column definition.
42
     *
43
     * @param string $datatype
44
     * @param string $name
45
     * @param string $tableName
46
     * @param string $schemaName
47
     *
48
     * @throws Exception\UnsupportedTypeException
49
     *
50
     * @return Definition\AbstractColumnDefinition
51
     */
52 3
    public static function createColumnDefinition($datatype, $name, $tableName = null, $schemaName = null)
53
    {
54 3
        if (!array_key_exists($datatype, self::$typesMap)) {
55 1
            throw new Exception\UnsupportedTypeException(__METHOD__ . " Type '$datatype' is not supported.");
56
        }
57 2
        $class = __NAMESPACE__ . '\\Column\\' . self::$typesMap[$datatype];
58
59 2
        return new $class($name, $tableName, $schemaName);
60
    }
61
62
    /**
63
     * Return all supported types.
64
     *
65
     * @return array
66
     */
67 1
    public static function getSupportedTypes()
68
    {
69 1
        return array_keys(self::$typesMap);
70
    }
71
}
72