Conditions | 4 |
Paths | 8 |
Total Lines | 89 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
28 | function xmldb_bigbluebuttonbn_upgrade($oldversion = 0) { |
||
29 | global $DB; |
||
30 | |||
31 | $dbman = $DB->get_manager(); |
||
32 | |||
33 | if ($oldversion < 2015080605) { |
||
34 | // Drop field description. |
||
35 | xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'description'); |
||
36 | |||
37 | // Change welcome, allow null. |
||
38 | $fielddefinition = array('type' => XMLDB_TYPE_TEXT, |
||
39 | 'precision' => null, |
||
40 | 'unsigned' => null, |
||
41 | 'notnull' => XMLDB_NOTNULL, |
||
42 | 'sequence' => null, |
||
43 | 'default' => null, |
||
44 | 'previous' => 'type'); |
||
45 | xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'welcome', |
||
46 | $fielddefinition); |
||
47 | |||
48 | // Change userid definition in bigbluebuttonbn_log. |
||
49 | $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, |
||
50 | 'precision' => '10', |
||
51 | 'unsigned' => XMLDB_UNSIGNED, |
||
52 | 'notnull' => XMLDB_NOTNULL, |
||
53 | 'sequence' => null, |
||
54 | 'default' => null, |
||
55 | 'previous' => 'bigbluebuttonbnid'); |
||
56 | xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn_log', 'userid', |
||
57 | $fielddefinition); |
||
58 | |||
59 | upgrade_mod_savepoint(true, 2015080605, 'bigbluebuttonbn'); |
||
60 | } |
||
61 | |||
62 | if ($oldversion < 2016011305) { |
||
63 | // Define field type to be droped from bigbluebuttonbn. |
||
64 | xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'type'); |
||
65 | |||
66 | // Rename table bigbluebuttonbn_log to bigbluebuttonbn_logs. |
||
67 | xmldb_bigbluebuttonbn_rename_table($dbman, 'bigbluebuttonbn_log', 'bigbluebuttonbn_logs'); |
||
68 | |||
69 | // Rename field event to log in table bigbluebuttonbn_logs. |
||
70 | xmldb_bigbluebuttonbn_rename_field($dbman, 'bigbluebuttonbn_logs', 'event', 'log'); |
||
71 | |||
72 | upgrade_mod_savepoint(true, 2016011305, 'bigbluebuttonbn'); |
||
73 | } |
||
74 | |||
75 | if ($oldversion < 2016080106) { |
||
76 | // Drop field newwindow. |
||
77 | xmldb_bigbluebuttonbn_drop_field($dbman, 'bigbluebuttonbn', 'newwindow'); |
||
78 | |||
79 | // Add field type. |
||
80 | $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, |
||
81 | 'precision' => '2', |
||
82 | 'unsigned' => XMLDB_UNSIGNED, |
||
83 | 'notnull' => XMLDB_NOTNULL, |
||
84 | 'sequence' => null, |
||
85 | 'default' => 0, |
||
86 | 'previous' => 'id'); |
||
87 | xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'type', |
||
88 | $fielddefinition); |
||
89 | |||
90 | // Add field recordings_html. |
||
91 | $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, |
||
92 | 'precision' => '1', |
||
93 | 'unsigned' => XMLDB_UNSIGNED, |
||
94 | 'notnull' => XMLDB_NOTNULL, |
||
95 | 'sequence' => null, |
||
96 | 'default' => 0, |
||
97 | 'previous' => null); |
||
98 | xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_html', |
||
99 | $fielddefinition); |
||
100 | |||
101 | // Add field recordings_deleted_activities. |
||
102 | $fielddefinition = array('type' => XMLDB_TYPE_INTEGER, |
||
103 | 'precision' => '1', |
||
104 | 'unsigned' => XMLDB_UNSIGNED, |
||
105 | 'notnull' => XMLDB_NOTNULL, |
||
106 | 'sequence' => null, |
||
107 | 'default' => 1, |
||
108 | 'previous' => null); |
||
109 | xmldb_bigbluebuttonbn_add_change_field($dbman, 'bigbluebuttonbn', 'recordings_deleted_activities', |
||
110 | $fielddefinition); |
||
111 | |||
112 | upgrade_mod_savepoint(true, 2016080106, 'bigbluebuttonbn'); |
||
113 | } |
||
114 | |||
115 | return true; |
||
116 | } |
||
117 | |||
159 |
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.