Schema   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createTableObject() 0 6 1
A createTable() 0 6 1
A _addTable() 0 7 3
1
<?php
2
3
namespace RDV\Bundle\MigrationBundle\Migration\Schema;
4
5
use Doctrine\DBAL\Schema\Schema as BaseSchema;
6
use Doctrine\DBAL\Schema\Table as BaseTable;
7
8
/**
9
 * The aim of this class is to provide a way extend doctrine Table class
10
 * To do this just define your table class name in TABLE_CLASS constant in an extended class
11
 * and override createTableObject if your table class constructor need an additional arguments
12
 */
13
class Schema extends BaseSchema
14
{
15
    /**
16
     * Used table class, define TABLE_CLASS constant in an extended class to extend the table class
17
     * Important: your class must extend RDV\Bundle\MigrationBundle\Migration\Schema\Table class
18
     *            or extend Doctrine\DBAL\Schema\Table class and must have __construct(array $args) method
19
     */
20
    const TABLE_CLASS = 'Doctrine\DBAL\Schema\Table';
21
22
    /**
23
     * Creates an instance of TABLE_CLASS class
24
     *
25
     * @param array $args An arguments for TABLE_CLASS class constructor
26
     *                    An instance of a base table is in 'table' element
27
     * @return BaseTable
28
     */
29
    protected function createTableObject(array $args)
30
    {
31
        $tableClass = static::TABLE_CLASS;
32
33
        return new $tableClass($args);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function createTable($tableName)
40
    {
41
        parent::createTable($tableName);
42
43
        return $this->getTable($tableName);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    // @codingStandardsIgnoreStart
50
    protected function _addTable(BaseTable $table)
51
    {
52
        if (get_class($table) !== static::TABLE_CLASS && static::TABLE_CLASS !== 'Doctrine\DBAL\Schema\Table') {
53
            $table = $this->createTableObject(['table' => $table]);
54
        }
55
        parent::_addTable($table);
56
    }
57
    // @codingStandardsIgnoreEnd
58
}
59