| Conditions | 30 |
| Paths | > 20000 |
| Total Lines | 265 |
| Code Lines | 82 |
| Lines | 45 |
| Ratio | 16.98 % |
| Changes | 2 | ||
| Bugs | 1 | 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 |
||
| 36 | function xoops_module_update_smartobject($module) |
||
| 37 | { |
||
| 38 | ob_start(); |
||
| 39 | |||
| 40 | $dbVersion = smart_GetMeta('version', 'smartobject'); |
||
|
|
|||
| 41 | if (!$dbVersion) { |
||
| 42 | $dbVersion = 0; |
||
| 43 | } |
||
| 44 | |||
| 45 | $dbupdater = new SmartobjectDbupdater(); |
||
| 46 | |||
| 47 | echo '<code>' . _SDU_UPDATE_UPDATING_DATABASE . '<br>'; |
||
| 48 | |||
| 49 | // db migrate version = 1 |
||
| 50 | $newDbVersion = 1; |
||
| 51 | if ($dbVersion < $newDbVersion) { |
||
| 52 | echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
||
| 53 | |||
| 54 | // Create table smartobject_link |
||
| 55 | $table = new SmartDbTable('smartobject_link'); |
||
| 56 | if (!$table->exists()) { |
||
| 57 | $table->setStructure("CREATE TABLE %s ( |
||
| 58 | `linkid` int(11) NOT NULL auto_increment, |
||
| 59 | `from_uid` int(11) NOT NULL default '0', |
||
| 60 | `from_email` varchar(255) NOT NULL default '', |
||
| 61 | `from_name` varchar(255) NOT NULL default '', |
||
| 62 | `to_uid` int(11) NOT NULL default '0', |
||
| 63 | `to_email` varchar(255) NOT NULL default '', |
||
| 64 | `to_name` varchar(255) NOT NULL default '', |
||
| 65 | `link` varchar(255) NOT NULL default '', |
||
| 66 | `subject` varchar(255) NOT NULL default '', |
||
| 67 | `body` TEXT NOT NULL, |
||
| 68 | `mid` int(11) NOT NULL default '0', |
||
| 69 | `mid_name` varchar(255) NOT NULL default '', |
||
| 70 | |||
| 71 | PRIMARY KEY (`linkid`) |
||
| 72 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
||
| 73 | |||
| 74 | if (!$dbupdater->updateTable($table)) { |
||
| 75 | /** |
||
| 76 | * @todo trap the errors |
||
| 77 | */ |
||
| 78 | } |
||
| 79 | } |
||
| 80 | unset($table); |
||
| 81 | // Create table smartobject_link |
||
| 82 | $table = new SmartDbTable('smartobject_link'); |
||
| 83 | if (!$table->fieldExists('date')) { |
||
| 84 | $table->addNewField('date', "int(11) NOT NULL default '0'"); |
||
| 85 | if (!$dbupdater->updateTable($table)) { |
||
| 86 | /** |
||
| 87 | * @todo trap the errors |
||
| 88 | */ |
||
| 89 | } |
||
| 90 | } |
||
| 91 | unset($table); |
||
| 92 | |||
| 93 | // Create table smartobject_tag |
||
| 94 | $table = new SmartDbTable('smartobject_tag'); |
||
| 95 | if (!$table->exists()) { |
||
| 96 | $table->setStructure("CREATE TABLE %s ( |
||
| 97 | `tagid` int(11) NOT NULL auto_increment, |
||
| 98 | `name` varchar(255) NOT NULL default '', |
||
| 99 | `description` TEXT NOT NULL, |
||
| 100 | PRIMARY KEY (`id`) |
||
| 101 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
||
| 102 | |||
| 103 | if (!$dbupdater->updateTable($table)) { |
||
| 104 | /** |
||
| 105 | * @todo trap the errors |
||
| 106 | */ |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | // Create table smartobject_tag_text |
||
| 111 | $table = new SmartDbTable('smartobject_tag_text'); |
||
| 112 | if (!$table->exists()) { |
||
| 113 | $table->setStructure("CREATE TABLE %s ( |
||
| 114 | `tagid` int(11) NOT NULL default 0, |
||
| 115 | `language` varchar(255) NOT NULL default '', |
||
| 116 | `value` TEXT NOT NULL, |
||
| 117 | PRIMARY KEY (`id`, `language`) |
||
| 118 | ) ENGINE=MyISAM COMMENT='SmartObject by The SmartFactory <www.smartfactory.ca>' AUTO_INCREMENT=1 ;"); |
||
| 119 | |||
| 120 | if (!$dbupdater->updateTable($table)) { |
||
| 121 | /** |
||
| 122 | * @todo trap the errors |
||
| 123 | */ |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | // Create table smartobject_adsense |
||
| 128 | $table = new SmartDbTable('smartobject_adsense'); |
||
| 129 | if (!$table->exists()) { |
||
| 130 | $table->setStructure(" |
||
| 131 | `adsenseid` int(11) NOT NULL auto_increment, |
||
| 132 | `format` VARCHAR(100) NOT NULL, |
||
| 133 | `description` TEXT NOT NULL, |
||
| 134 | `style` TEXT NOT NULL, |
||
| 135 | `border_color` varchar(6) NOT NULL default '', |
||
| 136 | `background_color` varchar(6) NOT NULL default '', |
||
| 137 | `link_color` varchar(6) NOT NULL default '', |
||
| 138 | `url_color` varchar(6) NOT NULL default '', |
||
| 139 | `text_color` varchar(6) NOT NULL default '', |
||
| 140 | `client_id` varchar(100) NOT NULL default '', |
||
| 141 | `tag` varchar(50) NOT NULL default '', |
||
| 142 | PRIMARY KEY (`adsenseid`) |
||
| 143 | "); |
||
| 144 | } |
||
| 145 | |||
| 146 | if (!$dbupdater->updateTable($table)) { |
||
| 147 | /** |
||
| 148 | * @todo trap the errors |
||
| 149 | */ |
||
| 150 | } |
||
| 151 | } |
||
| 152 | // db migrate version = 2 |
||
| 153 | $newDbVersion = 2; |
||
| 154 | if ($dbVersion < $newDbVersion) { |
||
| 155 | echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
||
| 156 | |||
| 157 | // Create table smartobject_rating |
||
| 158 | $table = new SmartDbTable('smartobject_rating'); |
||
| 159 | if (!$table->exists()) { |
||
| 160 | $table->setStructure(' |
||
| 161 | `ratingid` int(11) NOT NULL auto_increment, |
||
| 162 | `dirname` VARCHAR(255) NOT NULL, |
||
| 163 | `item` VARCHAR(255) NOT NULL, |
||
| 164 | `itemid` int(11) NOT NULL, |
||
| 165 | `uid` int(11) NOT NULL, |
||
| 166 | `rate` int(1) NOT NULL, |
||
| 167 | `date` int(11) NOT NULL, |
||
| 168 | PRIMARY KEY (`ratingid`), |
||
| 169 | UNIQUE (`dirname`, `item`, `itemid`, `uid`) |
||
| 170 | '); |
||
| 171 | } |
||
| 172 | |||
| 173 | if (!$dbupdater->updateTable($table)) { |
||
| 174 | /** |
||
| 175 | * @todo trap the errors |
||
| 176 | */ |
||
| 177 | } |
||
| 178 | |||
| 179 | // Create table smartobject_currency |
||
| 180 | $table = new SmartDbTable('smartobject_currency'); |
||
| 181 | $table->setData("2, 'EUR', 'Euro', '�', 0.65, 0"); |
||
| 182 | $table->setData("3, 'USD', 'American dollar', '$', 0.9, 0"); |
||
| 183 | $table->setData("1, 'CAD', 'Canadian dollar', '$', 1, 1"); |
||
| 184 | |||
| 185 | if (!$dbupdater->updateTable($table)) { |
||
| 186 | /** |
||
| 187 | * @todo trap the errors |
||
| 188 | */ |
||
| 189 | } |
||
| 190 | } |
||
| 191 | |||
| 192 | // db migrate version = 3 |
||
| 193 | $newDbVersion = 3; |
||
| 194 | View Code Duplication | if ($dbVersion < $newDbVersion) { |
|
| 195 | echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
||
| 196 | |||
| 197 | // Create table smartobject_customtag |
||
| 198 | $table = new SmartDbTable('smartobject_customtag'); |
||
| 199 | if (!$table->exists()) { |
||
| 200 | $table->setStructure(' |
||
| 201 | `customtagid` int(11) NOT NULL auto_increment, |
||
| 202 | `name` VARCHAR(255) NOT NULL, |
||
| 203 | `description` TEXT NOT NULL, |
||
| 204 | `content` TEXT NOT NULL, |
||
| 205 | `language` TEXT NOT NULL, |
||
| 206 | PRIMARY KEY (`customtagid`) |
||
| 207 | '); |
||
| 208 | } |
||
| 209 | |||
| 210 | if (!$dbupdater->updateTable($table)) { |
||
| 211 | /** |
||
| 212 | * @todo trap the errors |
||
| 213 | */ |
||
| 214 | } |
||
| 215 | } |
||
| 216 | |||
| 217 | // db migrate version = 4 |
||
| 218 | $newDbVersion = 4; |
||
| 219 | View Code Duplication | if ($dbVersion < $newDbVersion) { |
|
| 220 | echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
||
| 221 | |||
| 222 | // Create table smartobject_currency |
||
| 223 | $table = new SmartDbTable('smartobject_currency'); |
||
| 224 | if (!$table->exists()) { |
||
| 225 | $table->setStructure(' |
||
| 226 | `currencyid` int(11) NOT NULL auto_increment, |
||
| 227 | `iso4217` VARCHAR(5) NOT NULL, |
||
| 228 | `name` VARCHAR(255) NOT NULL, |
||
| 229 | `symbol` VARCHAR(1) NOT NULL, |
||
| 230 | `rate` float NOT NULL, |
||
| 231 | `default_currency` int(1) NOT NULL, |
||
| 232 | PRIMARY KEY (`currencyid`) |
||
| 233 | '); |
||
| 234 | } |
||
| 235 | |||
| 236 | if (!$dbupdater->updateTable($table)) { |
||
| 237 | /** |
||
| 238 | * @todo trap the errors |
||
| 239 | */ |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | // db migrate version = 6 |
||
| 244 | $newDbVersion = 6; |
||
| 245 | if ($dbVersion < $newDbVersion) { |
||
| 246 | echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
||
| 247 | } |
||
| 248 | |||
| 249 | $newDbVersion = 7; |
||
| 250 | if ($dbVersion < $newDbVersion) { |
||
| 251 | echo 'Database migrate to version ' . $newDbVersion . '<br>'; |
||
| 252 | |||
| 253 | // Create table smartobject_file |
||
| 254 | $table = new SmartDbTable('smartobject_file'); |
||
| 255 | if (!$table->exists()) { |
||
| 256 | $table->setStructure(' |
||
| 257 | `fileid` int(11) NOT NULL auto_increment, |
||
| 258 | `caption` varchar(255) collate latin1_general_ci NOT NULL, |
||
| 259 | `url` varchar(255) collate latin1_general_ci NOT NULL, |
||
| 260 | `description` text collate latin1_general_ci NOT NULL, |
||
| 261 | PRIMARY KEY (`fileid`) |
||
| 262 | '); |
||
| 263 | if (!$dbupdater->updateTable($table)) { |
||
| 264 | /** |
||
| 265 | * @todo trap the errors |
||
| 266 | */ |
||
| 267 | } |
||
| 268 | } |
||
| 269 | unset($table); |
||
| 270 | // Create table smartobject_urllink |
||
| 271 | $table = new SmartDbTable('smartobject_urllink'); |
||
| 272 | if (!$table->exists()) { |
||
| 273 | $table->setStructure(' |
||
| 274 | `urllinkid` int(11) NOT NULL auto_increment, |
||
| 275 | `caption` varchar(255) collate latin1_general_ci NOT NULL, |
||
| 276 | `url` varchar(255) collate latin1_general_ci NOT NULL, |
||
| 277 | `description` text collate latin1_general_ci NOT NULL, |
||
| 278 | `target` varchar(10) collate latin1_general_ci NOT NULL, |
||
| 279 | PRIMARY KEY (`urllinkid`) |
||
| 280 | '); |
||
| 281 | if (!$dbupdater->updateTable($table)) { |
||
| 282 | /** |
||
| 283 | * @todo trap the errors |
||
| 284 | */ |
||
| 285 | } |
||
| 286 | } |
||
| 287 | unset($table); |
||
| 288 | } |
||
| 289 | echo '</code>'; |
||
| 290 | |||
| 291 | $feedback = ob_get_clean(); |
||
| 292 | if (method_exists($module, 'setMessage')) { |
||
| 293 | $module->setMessage($feedback); |
||
| 294 | } else { |
||
| 295 | echo $feedback; |
||
| 296 | } |
||
| 297 | smart_SetMeta('version', $newDbVersion, 'smartobject'); //Set meta version to current |
||
| 298 | |||
| 299 | return true; |
||
| 300 | } |
||
| 301 | |||
| 315 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: