Completed
Push — master ( 63709e...41e5b0 )
by Sébastien
02:24
created

Type::createColumnDefinition()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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