Completed
Pull Request — master (#561)
by Richard
13:57
created

RemovePrefixes   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
dl 0
loc 112
ccs 19
cts 22
cp 0.8636
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getNewSchema() 0 4 1
A acceptSchema() 0 4 1
A acceptTable() 0 4 1
A acceptColumn() 0 4 1
A acceptForeignKey() 0 4 1
A acceptIndex() 0 4 1
A acceptSequence() 0 4 1
A setTableFilter() 0 4 1
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
namespace Xoops\Core\Database\Schema;
13
14
use Doctrine\DBAL\Schema\Table;
15
use Doctrine\DBAL\Schema\Schema;
16
use Doctrine\DBAL\Schema\Column;
17
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
18
use Doctrine\DBAL\Schema\Sequence;
19
use Doctrine\DBAL\Schema\Index;
20
use Doctrine\DBAL\Schema\Visitor\Visitor;
21
22
/**
23
 * RemovePrefixes is a Schema Visitor that builds an new Schema object
24
 * without the XOOPS_DB_PREFIX. A table list can be optionally applied to
25
 * filter the Schema.
26
 * 
27
 * This depends on PrefixStripper to do a lot of the grunt work.
28
 * 
29
 * @category  Xoops\Core\Database\Schema\RemovePrefixes
30
 * @package   Xoops\Core
31
 * @author    Richard Griffith <[email protected]>
32
 * @copyright 2013 XOOPS Project (http://xoops.org)
33
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
34
 * @version   Release: 2.6
35
 * @link      http://xoops.org
36
 * @since     2.6.0
37
 */
38
class RemovePrefixes implements Visitor
39
{
40
41
    protected $newSchema;
42
43
    /**
44
     * Constructor
45
     */
46 8
    public function __construct()
47
    {
48 8
        $this->newSchema = new PrefixStripper;
49 8
    }
50
51
    /**
52
     * return the generated Schema
53
     * 
54
     * @return Schema the generated schema object
55
     */
56 2
    public function getNewSchema()
57
    {
58 2
        return $this->newSchema;
59
    }
60
61
    /**
62
     * set list of tables to limit schema
63
     * 
64
     * If no list is specified, all tables will be included
65
     * 
66
     * @param array $tableList list of tables to allow
67
     * 
68
     * @return void
69
     */
70
    public function setTableFilter(array $tableList)
71
    {
72
        $this->newSchema->setTableFilter($tableList);
73
    }
74
75
    /**
76
     * Accept schema - not used in this context
77
     * 
78
     * @param Schema $schema a schema object
79
     * 
80
     * @return void
81
     */
82 1
    public function acceptSchema(Schema $schema)
83
    {
84
85 1
    }
86
87
    /**
88
     * Accept a table with all its dependencies.
89
     *
90
     * @param Table $table a table object
91
     * 
92
     * @return void
93
     */
94 1
    public function acceptTable(Table $table)
95
    {
96 1
        $this->newSchema->addTable($table);
97 1
    }
98
99
    /**
100
     * accept a column in the schema - not used in this context
101
     *
102
     * @param Table  $table  a table object to accept a column into
103
     * @param Column $column a column object to be accepted
104
     * 
105
     * @return void
106
     */
107 1
    public function acceptColumn(Table $table, Column $column)
108
    {
109
110 1
    }
111
112
    /**
113
     * Accept a foreign key in the schema - not used in this context
114
     * 
115
     * @param Table                $localTable   local table to have foreign key
116
     * @param ForeignKeyConstraint $fkConstraint foreign key constraint
117
     * 
118
     * @return void
119
     */
120 1
    public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
121
    {
122
123 1
    }
124
125
    /**
126
     * Accept an Index - not used in this context
127
     * 
128
     * @param Table $table indexed table
129
     * @param Index $index index to accept
130
     * 
131
     * @return void
132
     */
133 1
    public function acceptIndex(Table $table, Index $index)
134
    {
135
136 1
    }
137
138
    /**
139
     * Accept a sequence
140
     * 
141
     * @param Sequence $sequence sequence to accept
142
     * 
143
     * @return void
144
     */
145 1
    public function acceptSequence(Sequence $sequence)
146
    {
147 1
        $this->newSchema->addSequence($sequence);
148 1
    }
149
}
150