Type   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 3 Features 2
Metric Value
wmc 3
c 7
b 3
f 2
lcom 1
cbo 1
dl 0
loc 63
rs 10

2 Methods

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