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