Completed
Push — master ( 9aaed4...af3d52 )
by
unknown
04:30
created

_getPortableTableColumnDefinition()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 9
cts 10
cp 0.9
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 18
nc 2
nop 1
crap 2.004
1
<?php
2
/**
3
 * Licensed to CRATE Technology GmbH("Crate") under one or more contributor
4
 * license agreements.  See the NOTICE file distributed with this work for
5
 * additional information regarding copyright ownership.  Crate licenses
6
 * this file to you under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.  You may
8
 * obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15
 * License for the specific language governing permissions and limitations
16
 * under the License.
17
 *
18
 * However, if you have executed another commercial license agreement
19
 * with Crate these terms will supersede the license and you may use the
20
 * software solely pursuant to the terms of the relevant commercial agreement.
21
 */
22
namespace Crate\DBAL\Schema;
23
24
use Doctrine\DBAL\DBALException;
25
use Doctrine\DBAL\Schema\AbstractSchemaManager;
26
use Doctrine\DBAL\Schema\Column;
27
use Doctrine\DBAL\Schema\Table;
28
29
class CrateSchemaManager extends AbstractSchemaManager
30
{
31
32
    /**
33
     * {@inheritDoc}
34
     */
35 2
    public function listTableDetails($tableName)
36
    {
37 2
        $columns = $this->listTableColumns($tableName);
38 2
        $foreignKeys = array();
39 2
        $indexes = array();
40
41 2
        return new Table($tableName, $columns, $indexes, $foreignKeys);
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47
    public function listTableIndexes($table)
48
    {
49
        throw DBALException::notSupported(__METHOD__);
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55 3
    public function listTableColumns($table, $database = null)
56
    {
57 3
        $tableColumns = $this->_conn->fetchAll($this->_platform->getListTableColumnsSQL($table));
58 3
        $tableConstraints = $this->_conn->fetchAll($this->_platform->getListTableConstraintsSQL($table));
59
60 3
        $columns = array();
61 3
        foreach ($tableColumns as $tableColumn) {
62 3
            $tableColumn['primary'] = in_array($tableColumn['column_name'], $tableConstraints[0]['constraint_name']);
63 3
            $columns[] = $tableColumn;
64
        }
65
66 3
        return $this->_getPortableTableColumnList($table, $database, $columns);
67
    }
68
69
    /**
70
     * {@inheritDoc}
71
     */
72 3
    protected function _getPortableTableColumnDefinition($tableColumn)
73
    {
74 3
        $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
75
76 3
        if (!isset($tableColumn['column_name'])) {
77
            $tableColumn['column_name'] = '';
78
        }
79
80 3
        $dbType = strtolower($tableColumn['data_type']);
81 3
        $type = $this->_platform->getDoctrineTypeMapping($dbType);
82
83
        $options = array(
84 3
            'length'        => null,
85
            'notnull'       => false,
86
            'default'       => null,
87 3
            'primary'       => $tableColumn['primary'],
88
            'precision'     => null,
89
            'scale'         => null,
90
            'fixed'         => null,
91
            'unsigned'      => false,
92
            'autoincrement' => false,
93 3
            'comment'       => '',
94
        );
95
96 3
        return new Column($tableColumn['column_name'], \Doctrine\DBAL\Types\Type::getType($type), $options);
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     */
102 12
    protected function _getPortableTablesList($tables)
103
    {
104 12
        $tableNames = array();
105 12
        foreach ($tables as $tableRow) {
106 11
            $tableRow = array_change_key_case($tableRow, \CASE_LOWER);
107 11
            $tableNames[] = $tableRow['table_name']; // ignore schema for now
108
        }
109
110 12
        return $tableNames;
111
    }
112
}
113