LockFileSchemaManager   F
last analyzed

Complexity

Total Complexity 66

Size/Duplication

Total Lines 340
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 66
eloc 70
c 1
b 0
f 0
dl 0
loc 340
rs 3.12

66 Methods

Rating   Name   Duplication   Size   Complexity  
A listTableDetails() 0 3 1
A dropAndCreateSequence() 0 3 1
A listSequences() 0 3 1
A dropView() 0 3 1
A listViews() 0 3 1
A getPortableNamespacesList() 0 3 1
A dropIndex() 0 3 1
A _getPortableSequencesList() 0 3 1
A tablesExist() 0 3 1
A dropForeignKey() 0 3 1
A _getPortableTableForeignKeysList() 0 3 1
A getFilterSchemaAssetsExpression() 0 3 1
A removeDoctrineTypeFromComment() 0 3 1
A dropConstraint() 0 3 1
A _getPortableUserDefinition() 0 3 1
A _getPortableTableIndexesList() 0 3 1
A _getPortableViewsList() 0 3 1
A listTableIndexes() 0 3 1
A _getPortableTableColumnDefinition() 0 3 1
A dropTable() 0 3 1
A dropSequence() 0 3 1
A listTableColumns() 0 3 1
A createView() 0 3 1
A listTableForeignKeys() 0 3 1
A renameTable() 0 3 1
A extractDoctrineTypeFromComment() 0 3 1
A _getPortableTableForeignKeyDefinition() 0 3 1
A __construct() 0 4 1
A _getPortableTableDefinition() 0 3 1
A listTables() 0 3 1
A listDatabases() 0 3 1
A dropAndCreateConstraint() 0 3 1
A dropAndCreateForeignKey() 0 3 1
A dropAndCreateTable() 0 3 1
A _getPortableViewDefinition() 0 3 1
A _getPortableTriggersList() 0 3 1
A createSchema() 0 3 1
A _getPortableTableColumnList() 0 3 1
A createTable() 0 3 1
A dropAndCreateIndex() 0 3 1
A _execSql() 0 3 1
A createSequence() 0 3 1
A listNamespaceNames() 0 3 1
A createConstraint() 0 3 1
A createForeignKey() 0 3 1
A _getPortableDatabaseDefinition() 0 3 1
A createSchemaConfig() 0 3 1
A getPortableNamespaceDefinition() 0 3 1
A alterTable() 0 3 1
A _getPortableFunctionDefinition() 0 3 1
A dropAndCreateDatabase() 0 3 1
A tryMethod() 0 3 1
A createDatabase() 0 3 1
A createIndex() 0 3 1
A _getPortableTablesList() 0 3 1
A getSchemaSearchPaths() 0 3 1
A _getPortableTriggerDefinition() 0 3 1
A dropDatabase() 0 3 1
A listTableNames() 0 3 1
A _getPortableFunctionsList() 0 3 1
A dropAndCreateView() 0 3 1
A _getPortableDatabasesList() 0 3 1
A filterAssetNames() 0 3 1
A _getPortableUsersList() 0 3 1
A getDatabasePlatform() 0 3 1
A _getPortableSequenceDefinition() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like LockFileSchemaManager often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LockFileSchemaManager, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace TheCodingMachine\TDBM\Schema;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Platforms\AbstractPlatform;
7
use Doctrine\DBAL\Schema\AbstractSchemaManager;
8
use Doctrine\DBAL\Schema\Column;
9
use Doctrine\DBAL\Schema\Constraint;
10
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
11
use Doctrine\DBAL\Schema\Index;
12
use Doctrine\DBAL\Schema\Sequence;
13
use Doctrine\DBAL\Schema\Table;
14
use Doctrine\DBAL\Schema\TableDiff;
15
use Doctrine\DBAL\Schema\View;
16
use TheCodingMachine\TDBM\SchemaLockFileDumper;
17
18
/**
19
 * A DBAL SchemaManager that reads the schema from the lock file instead of reading it from the database.
20
 * Useful to avoid costly introspection queries at runtime.
21
 *
22
 * Acts as an adapter on top of an existing schema manager.
23
 */
24
class LockFileSchemaManager extends AbstractSchemaManager
25
{
26
    /**
27
     * @var AbstractSchemaManager
28
     */
29
    private $schemaManager;
30
    /**
31
     * @var SchemaLockFileDumper
32
     */
33
    private $schemaLockFileDumper;
34
35
    public function __construct(AbstractSchemaManager $schemaManager, SchemaLockFileDumper $schemaLockFileDumper)
36
    {
37
        $this->schemaManager = $schemaManager;
38
        $this->schemaLockFileDumper = $schemaLockFileDumper;
39
    }
40
41
    public function getDatabasePlatform()
42
    {
43
        return $this->schemaManager->getDatabasePlatform();
44
    }
45
46
    public function tryMethod()
47
    {
48
        return $this->schemaManager->tryMethod();
49
    }
50
51
    public function listDatabases()
52
    {
53
        return $this->schemaManager->listDatabases();
54
    }
55
56
    public function listNamespaceNames()
57
    {
58
        return $this->schemaManager->listNamespaceNames();
59
    }
60
61
    public function listSequences($database = null)
62
    {
63
        return $this->schemaManager->listSequences($database);
64
    }
65
66
    public function listTableColumns($table, $database = null)
67
    {
68
        return $this->schemaManager->listTableColumns($table, $database);
69
    }
70
71
    public function listTableIndexes($table)
72
    {
73
        return $this->schemaManager->listTableIndexes($table);
74
    }
75
76
    public function tablesExist($tableNames)
77
    {
78
        return $this->schemaManager->tablesExist($tableNames);
79
    }
80
81
    public function listTableNames()
82
    {
83
        return $this->schemaManager->listTableNames();
84
    }
85
86
    protected function filterAssetNames($assetNames)
87
    {
88
        return $this->schemaManager->filterAssetNames($assetNames);
89
    }
90
91
    protected function getFilterSchemaAssetsExpression()
92
    {
93
        return $this->schemaManager->getFilterSchemaAssetsExpression();
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Abs...chemaAssetsExpression() has been deprecated: Use Configuration::getSchemaAssetsFilter() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

93
        return /** @scrutinizer ignore-deprecated */ $this->schemaManager->getFilterSchemaAssetsExpression();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
94
    }
95
96
    public function listTables()
97
    {
98
        return $this->schemaManager->listTables();
99
    }
100
101
    public function listTableDetails($tableName)
102
    {
103
        return $this->schemaManager->listTableDetails($tableName);
104
    }
105
106
    public function listViews()
107
    {
108
        return $this->schemaManager->listViews();
109
    }
110
111
    public function listTableForeignKeys($table, $database = null)
112
    {
113
        return $this->schemaManager->listTableForeignKeys($table, $database);
114
    }
115
116
    public function dropDatabase($database)
117
    {
118
        $this->schemaManager->dropDatabase($database);
119
    }
120
121
    public function dropTable($tableName)
122
    {
123
        $this->schemaManager->dropTable($tableName);
124
    }
125
126
    public function dropIndex($index, $table)
127
    {
128
        $this->schemaManager->dropIndex($index, $table);
129
    }
130
131
    public function dropConstraint(Constraint $constraint, $table)
132
    {
133
        $this->schemaManager->dropConstraint($constraint, $table);
134
    }
135
136
    public function dropForeignKey($foreignKey, $table)
137
    {
138
        $this->schemaManager->dropForeignKey($foreignKey, $table);
139
    }
140
141
    public function dropSequence($name)
142
    {
143
        $this->schemaManager->dropSequence($name);
144
    }
145
146
    public function dropView($name)
147
    {
148
        $this->schemaManager->dropView($name);
149
    }
150
151
    public function createDatabase($database)
152
    {
153
        $this->schemaManager->createDatabase($database);
154
    }
155
156
    public function createTable(Table $table)
157
    {
158
        $this->schemaManager->createTable($table);
159
    }
160
161
    public function createSequence($sequence)
162
    {
163
        $this->schemaManager->createSequence($sequence);
164
    }
165
166
    public function createConstraint(Constraint $constraint, $table)
167
    {
168
        $this->schemaManager->createConstraint($constraint, $table);
169
    }
170
171
    public function createIndex(Index $index, $table)
172
    {
173
        $this->schemaManager->createIndex($index, $table);
174
    }
175
176
    public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
177
    {
178
        $this->schemaManager->createForeignKey($foreignKey, $table);
179
    }
180
181
    public function createView(View $view)
182
    {
183
        $this->schemaManager->createView($view);
184
    }
185
186
    public function dropAndCreateConstraint(Constraint $constraint, $table)
187
    {
188
        $this->schemaManager->dropAndCreateConstraint($constraint, $table);
189
    }
190
191
    public function dropAndCreateIndex(Index $index, $table)
192
    {
193
        $this->schemaManager->dropAndCreateIndex($index, $table);
194
    }
195
196
    public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
197
    {
198
        $this->schemaManager->dropAndCreateForeignKey($foreignKey, $table);
199
    }
200
201
    public function dropAndCreateSequence(Sequence $sequence)
202
    {
203
        $this->schemaManager->dropAndCreateSequence($sequence);
204
    }
205
206
    public function dropAndCreateTable(Table $table)
207
    {
208
        $this->schemaManager->dropAndCreateTable($table);
209
    }
210
211
    public function dropAndCreateDatabase($database)
212
    {
213
        $this->schemaManager->dropAndCreateDatabase($database);
214
    }
215
216
    public function dropAndCreateView(View $view)
217
    {
218
        $this->schemaManager->dropAndCreateView($view);
219
    }
220
221
    public function alterTable(TableDiff $tableDiff)
222
    {
223
        $this->schemaManager->alterTable($tableDiff);
224
    }
225
226
    public function renameTable($name, $newName)
227
    {
228
        $this->schemaManager->renameTable($name, $newName);
229
    }
230
231
    protected function _getPortableDatabasesList($databases)
232
    {
233
        return $this->schemaManager->_getPortableDatabasesList($databases);
234
    }
235
236
    protected function getPortableNamespacesList(array $namespaces)
237
    {
238
        return $this->schemaManager->getPortableNamespacesList($namespaces);
239
    }
240
241
    protected function _getPortableDatabaseDefinition($database)
242
    {
243
        return $this->schemaManager->_getPortableDatabaseDefinition($database);
244
    }
245
246
    protected function getPortableNamespaceDefinition(array $namespace)
247
    {
248
        return $this->schemaManager->getPortableNamespaceDefinition($namespace);
249
    }
250
251
    protected function _getPortableFunctionsList($functions)
252
    {
253
        return $this->schemaManager->_getPortableFunctionsList($functions);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Abs...PortableFunctionsList() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

253
        return /** @scrutinizer ignore-deprecated */ $this->schemaManager->_getPortableFunctionsList($functions);
Loading history...
254
    }
255
256
    protected function _getPortableFunctionDefinition($function)
257
    {
258
        return $this->schemaManager->_getPortableFunctionDefinition($function);
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\DBAL\Schema\Abs...bleFunctionDefinition() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

258
        return /** @scrutinizer ignore-deprecated */ $this->schemaManager->_getPortableFunctionDefinition($function);
Loading history...
259
    }
260
261
    protected function _getPortableTriggersList($triggers)
262
    {
263
        return $this->schemaManager->_getPortableTriggersList($triggers);
264
    }
265
266
    protected function _getPortableTriggerDefinition($trigger)
267
    {
268
        return $this->schemaManager->_getPortableTriggerDefinition($trigger);
269
    }
270
271
    protected function _getPortableSequencesList($sequences)
272
    {
273
        return $this->schemaManager->_getPortableSequencesList($sequences);
274
    }
275
276
    protected function _getPortableSequenceDefinition($sequence)
277
    {
278
        return $this->schemaManager->_getPortableSequenceDefinition($sequence);
279
    }
280
281
    protected function _getPortableTableColumnList($table, $database, $tableColumns)
282
    {
283
        return $this->schemaManager->_getPortableTableColumnList($table, $database, $tableColumns);
284
    }
285
286
    protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null)
287
    {
288
        return $this->schemaManager->_getPortableTableIndexesList($tableIndexRows, $tableName);
289
    }
290
291
    protected function _getPortableTablesList($tables)
292
    {
293
        return $this->schemaManager->_getPortableTablesList($tables);
294
    }
295
296
    protected function _getPortableTableDefinition($table)
297
    {
298
        return $this->schemaManager->_getPortableTableDefinition($table);
299
    }
300
301
    protected function _getPortableUsersList($users)
302
    {
303
        return $this->schemaManager->_getPortableUsersList($users);
304
    }
305
306
    protected function _getPortableUserDefinition($user)
307
    {
308
        return $this->schemaManager->_getPortableUserDefinition($user);
309
    }
310
311
    protected function _getPortableViewsList($views)
312
    {
313
        return $this->schemaManager->_getPortableViewsList($views);
314
    }
315
316
    protected function _getPortableViewDefinition($view)
317
    {
318
        return $this->schemaManager->_getPortableViewDefinition($view);
319
    }
320
321
    protected function _getPortableTableForeignKeysList($tableForeignKeys)
322
    {
323
        return $this->schemaManager->_getPortableTableForeignKeysList($tableForeignKeys);
324
    }
325
326
    protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
327
    {
328
        return $this->schemaManager->_getPortableTableForeignKeyDefinition($tableForeignKey);
329
    }
330
331
    protected function _execSql($sql)
332
    {
333
        $this->schemaManager->_execSql($sql);
334
    }
335
336
    public function createSchema()
337
    {
338
        return $this->schemaLockFileDumper->getSchema();
339
    }
340
341
    public function createSchemaConfig()
342
    {
343
        return $this->schemaManager->createSchemaConfig();
344
    }
345
346
    public function getSchemaSearchPaths()
347
    {
348
        return $this->schemaManager->getSchemaSearchPaths();
349
    }
350
351
    public function extractDoctrineTypeFromComment($comment, $currentType)
352
    {
353
        return $this->schemaManager->extractDoctrineTypeFromComment($comment, $currentType);
354
    }
355
356
    public function removeDoctrineTypeFromComment($comment, $type)
357
    {
358
        return $this->schemaManager->removeDoctrineTypeFromComment($comment, $type);
359
    }
360
361
    protected function _getPortableTableColumnDefinition($tableColumn)
362
    {
363
        return $this->schemaManager->_getPortableTableColumnDefinition($tableColumn);
364
    }
365
}
366