Type   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
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 63
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\Column;
4
5
use Soluble\Datatype\Exception;
6
use Soluble\Datatype\Column\Definition\AbstractColumnDefinition;
7
8
class Type
9
{
10
    const TYPE_INTEGER = 'integer';
11
    const TYPE_DECIMAL = 'decimal';
12
    const TYPE_STRING = 'string';
13
    const TYPE_BOOLEAN = 'boolean';
14
    const TYPE_DATETIME = 'datetime';
15
    const TYPE_BLOB = 'blob';
16
    const TYPE_DATE = 'date';
17
    const TYPE_TIME = 'time';
18
    const TYPE_FLOAT = 'float';
19
    const TYPE_BIT = 'bit';
20
    const TYPE_SPATIAL_GEOMETRY = 'geometry';
21
    const TYPE_NULL = 'null';
22
23
    /**
24
     * @var array
25
     */
26
    protected static $typesMap = [
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
        self::TYPE_NULL => 'Definition\NullColumn'
39
    ];
40
41
    /**
42
     * @param string $datatype
43
     * @param string $name
44
     * @param string $tableName
45
     * @param string $schemaName
46
     *
47
     * @throws Exception\UnsupportedDatatypeException
48
     *
49
     * @return AbstractColumnDefinition
50 2
     */
51
    public static function createColumnDefinition($datatype, $name, $tableName = null, $schemaName = null)
52 2
    {
53 1
        if (!array_key_exists($datatype, self::$typesMap)) {
54
            throw new Exception\UnsupportedTypeException(__METHOD__ . " Type '$datatype' is not supported.");
55 1
        }
56
        $class = __NAMESPACE__ . '\\' . self::$typesMap[$datatype];
57 1
58
        return new $class($name, $tableName, $schemaName);
59
    }
60
61
    /**
62
     * Return all supported types.
63
     *
64
     * @return array
65 1
     */
66
    public static function getSupportedTypes()
67 1
    {
68
        return array_keys(self::$typesMap);
69
    }
70
}
71