Passed
Push — dev ( ed3e65...b2f89b )
by 世昌
02:33
created

TableCreator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 23
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 10 2
1
<?php
2
3
4
namespace suda\application\database;
5
6
7
use suda\database\struct\TableStruct;
8
use suda\database\connection\Connection;
9
use suda\database\exception\SQLException;
10
use suda\application\database\creator\MySQLTableCreator;
11
12
abstract class TableCreator
13
{
14
    protected static $map = [
15
      'mysql' => MySQLTableCreator::class,
16
    ];
17
18
    abstract function create(Connection $connection, TableStruct $fields);
19
20
    /**
21
     * @param Table $table
22
     * @return bool
23
     * @throws SQLException
24
     */
25
    public static function make(Table $table):bool {
26
        $type = $table->getSource()->write()->getType();
27
28
        if (array_key_exists($type, static::$map)) {
29
            $className = static::$map[$type];
30
            /** @var TableCreator $creator */
31
            $creator = new $className();
32
            return $creator->create($table->getSource()->write(), $table->getStruct());
33
        }
34
        return false;
35
    }
36
}