| Conditions | 18 |
| Paths | 1301 |
| Total Lines | 70 |
| Code Lines | 41 |
| 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 |
||
| 62 | function xoops_module_update_xoopspoll(\XoopsModule $module, $prev_version) |
||
| 63 | { |
||
| 64 | // referer check |
||
| 65 | $success = false; |
||
| 66 | $ref = xoops_getenv('HTTP_REFERER'); |
||
| 67 | $helper = Helper::getInstance(); |
||
| 68 | if (('' === $ref) || 0 === mb_strpos($ref, $GLOBALS['xoops']->url('modules/system/admin.php'))) { |
||
| 69 | /* module specific part */ |
||
| 70 | require_once $helper->path('include/oninstall.php'); |
||
| 71 | |||
| 72 | $installedVersion = (int)$prev_version; |
||
| 73 | xoops_loadLanguage('admin', 'xoopspoll'); |
||
| 74 | $db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 75 | $success = true; |
||
| 76 | if ($installedVersion < 140) { |
||
| 77 | /* add column for poll anonymous which was created in versions prior |
||
| 78 | * to 1.40 of xoopspoll but not automatically created |
||
| 79 | */ |
||
| 80 | $result = $db->queryF('SHOW COLUMNS FROM ' . $db->prefix('xoopspoll_desc') . " LIKE 'anonymous'"); |
||
| 81 | $foundAnon = $db->getRowsNum($result); |
||
| 82 | if (empty($foundAnon)) { |
||
| 83 | // column doesn't exist, so try and add it |
||
| 84 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . ' ADD anonymous TINYINT( 1 ) DEFAULT 0 NOT NULL AFTER multiple'); |
||
| 85 | if (false === $success) { |
||
| 86 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'anonymous'); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | /* change description to TINYTEXT */ |
||
| 90 | if ($success) { |
||
| 91 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . ' MODIFY description TINYTEXT NOT NULL'); |
||
| 92 | if (false === $success) { |
||
| 93 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'description'); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($success) { |
||
| 98 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . " ADD multilimit TINYINT( 63 ) UNSIGNED DEFAULT '0' NOT NULL AFTER multiple"); |
||
| 99 | if (false === $success) { |
||
| 100 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'multilimit'); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | if ($success) { |
||
| 104 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . " ADD mail_voter TINYINT( 1 ) UNSIGNED DEFAULT '0' NOT NULL AFTER mail_status"); |
||
| 105 | if (false === $success) { |
||
| 106 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'mail_voter'); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | if ($success) { |
||
| 110 | $result = $db->queryF('SHOW COLUMNS FROM ' . $db->prefix('xoopspoll_desc') . " LIKE 'visibility'"); |
||
| 111 | $foundCol = $db->getRowsNum($result); |
||
| 112 | if (empty($foundCol)) { |
||
| 113 | // column doesn't exist, so try and add it |
||
| 114 | $success = $db->queryF('ALTER TABLE ' . $db->prefix('xoopspoll_desc') . " ADD visibility INT( 3 ) DEFAULT '0' NOT NULL AFTER display"); |
||
| 115 | if (false === $success) { |
||
| 116 | $module->setErrors(_AM_XOOPSPOLL_ERROR_COLUMN . 'visibility'); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | if ($success) { |
||
| 123 | /* now reverse table names changes from 1.40 Beta */ |
||
| 124 | $s1 = xoopspollChangeTableName($db, 'mod_xoopspoll_option', 'xoopspoll_option'); |
||
| 125 | $s2 = xoopspollChangeTableName($db, 'mod_xoopspoll_desc', 'xoopspoll_desc'); |
||
| 126 | $s3 = xoopspollChangeTableName($db, 'mod_xoopspoll_log', 'xoopspoll_log'); |
||
| 127 | $success = ($s1 && $s2 && $s3); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | return $success; |
||
| 132 | } |
||
| 133 |