AdminerForeignSystem::foreignKeys()   C
last analyzed

Complexity

Conditions 33
Paths 32

Size

Total Lines 74
Code Lines 69

Duplication

Lines 9
Ratio 12.16 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 33
eloc 69
c 2
b 0
f 0
nc 32
nop 1
dl 9
loc 74
rs 5.2093

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/** Link system tables (in mysql and information_schema databases) by foreign keys
4
* @link https://www.adminer.org/plugins/#use
5
* @author Jakub Vrana, http://www.vrana.cz/
6
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
7
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
8
*/
9
class AdminerForeignSystem {
10
	
11
	function foreignKeys($table) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
12
		if (DRIVER == 'server' && DB == 'mysql') {
13
			switch ($table) {
14 View Code Duplication
				case 'columns_priv': return array(array('table' => 'user', 'source' => array('Host', 'User'), 'target' => array('Host', 'User')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15 View Code Duplication
				case 'db': return array(array('table' => 'user', 'source' => array('Host', 'User'), 'target' => array('Host', 'User')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
16 View Code Duplication
				case 'help_category': return array(array('table' => 'help_category', 'source' => array('parent_category_id'), 'target' => array('help_category_id')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
				case 'help_relation': return array(array('table' => 'help_topic', 'source' => array('help_topic_id'), 'target' => array('help_topic_id')), array('table' => 'help_keyword', 'source' => array('help_keyword_id'), 'target' => array('help_keyword_id')));
18 View Code Duplication
				case 'help_topic': return array(array('table' => 'help_category', 'source' => array('help_category_id'), 'target' => array('help_category_id')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19 View Code Duplication
				case 'procs_priv': return array(array('table' => 'user', 'source' => array('Host', 'User'), 'target' => array('Host', 'User')), array('table' => 'proc', 'source' => array('Db', 'Routine_name'), 'target' => array('db', 'name')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20 View Code Duplication
				case 'tables_priv': return array(array('table' => 'user', 'source' => array('Host', 'User'), 'target' => array('Host', 'User')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21 View Code Duplication
				case 'time_zone_name': return array(array('table' => 'time_zone', 'source' => array('Time_zone_id'), 'target' => array('Time_zone_id')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22 View Code Duplication
				case 'time_zone_transition': return array(array('table' => 'time_zone', 'source' => array('Time_zone_id'), 'target' => array('Time_zone_id')), array(
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
                    'table' => 'time_zone_transition_type', 'source' => array('Time_zone_id', 'Transition_type_id'), 'target' => array(
24
                    'Time_zone_id',
25
                    'Transition_type_id'
26
                )));
27 View Code Duplication
				case 'time_zone_transition_type': return array(array('table' => 'time_zone', 'source' => array('Time_zone_id'), 'target' => array('Time_zone_id')));
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
			}
29
		} elseif (DB == 'information_schema') {
30
			$schemata = array('table' => 'SCHEMATA', 'source' => array('TABLE_CATALOG', 'TABLE_SCHEMA'), 'target' => array('CATALOG_NAME', 'SCHEMA_NAME'));
31
			$tables = array('table' => 'TABLES', 'source' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME'), 'target' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME'));
32
			$columns = array('table' => 'COLUMNS', 'source' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'COLUMN_NAME'), 'target' => array('TABLE_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME', 'COLUMN_NAME'));
33
			$character_sets = array('table' => 'CHARACTER_SETS', 'source' => array('CHARACTER_SET_NAME'), 'target' => array('CHARACTER_SET_NAME'));
34
			$collations = array('table' => 'COLLATIONS', 'source' => array('COLLATION_NAME'), 'target' => array('COLLATION_NAME'));
35
			$routine_charsets = array(array('source' => array('CHARACTER_SET_CLIENT')) + $character_sets, array('source' => array('COLLATION_CONNECTION')) + $collations, array('source' => array('DATABASE_COLLATION')) + $collations);
36
			switch ($table) {
37
				case 'CHARACTER_SETS': return array(array('source' => array('DEFAULT_COLLATE_NAME')) + $collations);
38
				case 'COLLATIONS': return array($character_sets);
39
				case 'COLLATION_CHARACTER_SET_APPLICABILITY': return array($collations, $character_sets);
40
				case 'COLUMNS': return array($schemata, $tables, $character_sets, $collations);
41
				case 'COLUMN_PRIVILEGES': return array($schemata, $tables, $columns);
42
				case 'TABLES': return array($schemata, array('source' => array('TABLE_COLLATION')) + $collations);
43
				case 'SCHEMATA': return array(array('source' => array('DEFAULT_CHARACTER_SET_NAME')) + $character_sets, array('source' => array('DEFAULT_COLLATION_NAME')) + $collations);
44
				case 'EVENTS': return array_merge(array(array('source' => array('EVENT_CATALOG', 'EVENT_SCHEMA')) + $schemata), $routine_charsets);
45
				case 'FILES': return array($schemata, $tables);
46
				case 'KEY_COLUMN_USAGE': return array(array('source' => array('CONSTRAINT_CATALOG', 'CONSTRAINT_SCHEMA')) + $schemata, $schemata, $tables, $columns, array('source' => array('TABLE_CATALOG', 'REFERENCED_TABLE_SCHEMA')) + $schemata, array(
47
                                                                                                                                                                                                                                                           'source' => array(
48
                                                         'TABLE_CATALOG',
49
                                                         'REFERENCED_TABLE_SCHEMA',
50
                                                         'REFERENCED_TABLE_NAME'
51
                                                     )) + $tables, array(
52
                                                                                                                                                                                                                                                                                                                                                                    'source' => array(
53
                                                         'TABLE_CATALOG',
54
                                                         'REFERENCED_TABLE_SCHEMA',
55
                                                         'REFERENCED_TABLE_NAME',
56
                                                         'REFERENCED_COLUMN_NAME'
57
                                                     )) + $columns);
58
				case 'PARTITIONS': return array($schemata, $tables);
59
				case 'REFERENTIAL_CONSTRAINTS': return array(array('source' => array('CONSTRAINT_CATALOG', 'CONSTRAINT_SCHEMA')) + $schemata, array('source' => array('UNIQUE_CONSTRAINT_CATALOG', 'UNIQUE_CONSTRAINT_SCHEMA')) + $schemata, array(
60
                                                                                                                                                                                                                                                 'source' => array(
61
                                                                'CONSTRAINT_CATALOG',
62
                                                                'CONSTRAINT_SCHEMA',
63
                                                                'TABLE_NAME'
64
                                                            )) + $tables, array(
65
                                                                                                                                                                                                                                                                                                                                              'source' => array(
66
                                                                'CONSTRAINT_CATALOG',
67
                                                                'CONSTRAINT_SCHEMA',
68
                                                                'REFERENCED_TABLE_NAME'
69
                                                            )) + $tables);
70
				case 'ROUTINES': return array_merge(array(array('source' => array('ROUTINE_CATALOG', 'ROUTINE_SCHEMA')) + $schemata), $routine_charsets);
71
				case 'SCHEMA_PRIVILEGES': return array($schemata);
72
				case 'STATISTICS': return array($schemata, $tables, $columns, array('source' => array('TABLE_CATALOG', 'INDEX_SCHEMA')) + $schemata);
73
				case 'TABLE_CONSTRAINTS': return array(array('source' => array('CONSTRAINT_CATALOG', 'CONSTRAINT_SCHEMA')) + $schemata, array('source' => array('CONSTRAINT_CATALOG', 'TABLE_SCHEMA')) + $schemata, array('source' => array('CONSTRAINT_CATALOG', 'TABLE_SCHEMA', 'TABLE_NAME')) + $tables);
74
				case 'TABLE_PRIVILEGES': return array($schemata, $tables);
75
				case 'TRIGGERS': return array_merge(array(array('source' => array('TRIGGER_CATALOG', 'TRIGGER_SCHEMA')) + $schemata, array('source' => array('EVENT_OBJECT_CATALOG', 'EVENT_OBJECT_SCHEMA')) + $schemata, array(
76
                                                                                                                                                                                                                              'source' => array(
77
                                                             'EVENT_OBJECT_CATALOG',
78
                                                             'EVENT_OBJECT_SCHEMA',
79
                                                             'EVENT_OBJECT_TABLE'
80
                                                         )) + $tables), $routine_charsets);
81
				case 'VIEWS': return array($schemata);
82
			}
83
		}
84
	}
85
	
86
}
87