Conditions | 33 |
Paths | 32 |
Total Lines | 74 |
Code Lines | 69 |
Lines | 9 |
Ratio | 12.16 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
11 | function foreignKeys($table) { |
||
|
|||
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'))); |
|
15 | View Code Duplication | case 'db': return array(array('table' => 'user', 'source' => array('Host', 'User'), 'target' => array('Host', 'User'))); |
|
16 | View Code Duplication | case 'help_category': return array(array('table' => 'help_category', 'source' => array('parent_category_id'), 'target' => array('help_category_id'))); |
|
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'))); |
|
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'))); |
|
20 | View Code Duplication | case 'tables_priv': return array(array('table' => 'user', 'source' => array('Host', 'User'), 'target' => array('Host', 'User'))); |
|
21 | View Code Duplication | case 'time_zone_name': return array(array('table' => 'time_zone', 'source' => array('Time_zone_id'), 'target' => array('Time_zone_id'))); |
|
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( |
|
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'))); |
|
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 | |||
87 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.