| Conditions | 21 | 
| Paths | 136 | 
| Total Lines | 144 | 
| Code Lines | 67 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 4 | ||
| 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 declare(strict_types=1);  | 
            ||
| 65 | function xoops_module_update_contact(\XoopsModule $module, $previousVersion = null)  | 
            ||
| 66 | { | 
            ||
| 67 | $moduleDirName = \basename(\dirname(__DIR__));  | 
            ||
| 68 | $moduleDirNameUpper = \mb_strtoupper($moduleDirName);  | 
            ||
| 69 | |||
| 70 | /** @var Helper $helper */  | 
            ||
| 71 | /** @var Utility $utility */  | 
            ||
| 72 | /** @var Configurator $configurator */  | 
            ||
| 73 | $helper = Helper::getInstance();  | 
            ||
| 74 | $utility = new Utility();  | 
            ||
| 75 | $configurator = new Configurator();  | 
            ||
| 76 | |||
| 77 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection();  | 
            ||
| 78 | |||
| 79 |     if ($previousVersion < 180) { | 
            ||
| 80 |         $sql = 'CREATE TABLE ' . $xoopsDB->prefix('contact') . ' ( | 
            ||
| 81 | contact_id int(10) unsigned NOT NULL auto_increment,  | 
            ||
| 82 | contact_uid int(10) NOT NULL,  | 
            ||
| 83 | contact_cid int(10) NOT NULL,  | 
            ||
| 84 | contact_create int(10) NOT NULL,  | 
            ||
| 85 | contact_subject varchar(255) NOT NULL,  | 
            ||
| 86 | contact_name varchar(255) NOT NULL,  | 
            ||
| 87 | contact_mail varchar(255) NOT NULL,  | 
            ||
| 88 | contact_url varchar(255) NOT NULL,  | 
            ||
| 89 | contact_icq varchar(255) NOT NULL,  | 
            ||
| 90 | contact_company varchar(255) NOT NULL,  | 
            ||
| 91 | contact_location varchar(255) NOT NULL,  | 
            ||
| 92 | contact_department varchar(60) NOT NULL,  | 
            ||
| 93 | contact_ip varchar(20) NOT NULL,  | 
            ||
| 94 | contact_phone varchar(20) NOT NULL,  | 
            ||
| 95 | contact_message text NOT NULL,  | 
            ||
| 96 | contact_address text NOT NULL,  | 
            ||
| 97 | contact_reply tinyint(1) NOT NULL,  | 
            ||
| 98 | PRIMARY KEY (contact_id)  | 
            ||
| 99 | ) ENGINE=MyISAM;';  | 
            ||
| 100 | $xoopsDB->query($sql);  | 
            ||
| 101 | }  | 
            ||
| 102 | |||
| 103 |     if ($previousVersion < 181) { | 
            ||
| 104 | // Add contact_platform  | 
            ||
| 105 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . "` ADD `contact_platform` ENUM('Android','Ios','Web') NOT NULL DEFAULT 'Web'"; | 
            ||
| 106 | $xoopsDB->query($sql);  | 
            ||
| 107 | // Add contact_type  | 
            ||
| 108 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . "` ADD `contact_type` ENUM('Contact','Phone','Mail') NOT NULL DEFAULT 'Contact'"; | 
            ||
| 109 | $xoopsDB->query($sql);  | 
            ||
| 110 | // Add index contact_uid  | 
            ||
| 111 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_uid` ( `contact_uid` )'; | 
            ||
| 112 | $xoopsDB->query($sql);  | 
            ||
| 113 | // Add index contact_cid  | 
            ||
| 114 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_cid` ( `contact_cid` )'; | 
            ||
| 115 | $xoopsDB->query($sql);  | 
            ||
| 116 | // Add index contact_create  | 
            ||
| 117 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_create` ( `contact_create` )'; | 
            ||
| 118 | $xoopsDB->query($sql);  | 
            ||
| 119 | // Add index contact_mail  | 
            ||
| 120 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_mail` ( `contact_mail` )'; | 
            ||
| 121 | $xoopsDB->query($sql);  | 
            ||
| 122 | // Add index contact_phone  | 
            ||
| 123 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_phone` ( `contact_phone` )'; | 
            ||
| 124 | $xoopsDB->query($sql);  | 
            ||
| 125 | // Add index contact_platform  | 
            ||
| 126 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_platform` ( `contact_platform` )'; | 
            ||
| 127 | $xoopsDB->query($sql);  | 
            ||
| 128 | // Add index contact_type  | 
            ||
| 129 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD INDEX `contact_type` ( `contact_type` )'; | 
            ||
| 130 | $xoopsDB->query($sql);  | 
            ||
| 131 | }  | 
            ||
| 132 | |||
| 133 |     if ($previousVersion < 227) { | 
            ||
| 134 | $configurator = new Configurator();  | 
            ||
| 135 | $utility = new Utility();  | 
            ||
| 136 | |||
| 137 | //delete old HTML templates  | 
            ||
| 138 |         if (count($configurator->templateFolders) > 0) { | 
            ||
| 139 |             foreach ($configurator->templateFolders as $folder) { | 
            ||
| 140 |                 $templateFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $folder); | 
            ||
| 141 |                 if (is_dir($templateFolder)) { | 
            ||
| 142 | $templateList = array_diff(scandir($templateFolder, SCANDIR_SORT_NONE), ['..', '.']);  | 
            ||
| 143 |                     foreach ($templateList as $k => $v) { | 
            ||
| 144 | $fileInfo = new \SplFileInfo($templateFolder . $v);  | 
            ||
| 145 |                         if ('html' === $fileInfo->getExtension() && 'index.html' !== $fileInfo->getFilename()) { | 
            ||
| 146 |                             if (is_file($templateFolder . $v)) { | 
            ||
| 147 | unlink($templateFolder . $v);  | 
            ||
| 148 | }  | 
            ||
| 149 | }  | 
            ||
| 150 | }  | 
            ||
| 151 | }  | 
            ||
| 152 | }  | 
            ||
| 153 | }  | 
            ||
| 154 | |||
| 155 | // --- DELETE OLD FILES ---------------  | 
            ||
| 156 |         if (count($configurator->oldFiles) > 0) { | 
            ||
| 157 |             //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) { | 
            ||
| 158 |             foreach (array_keys($configurator->oldFiles) as $i) { | 
            ||
| 159 |                 $tempFile = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFiles[$i]); | 
            ||
| 160 |                 if (is_file($tempFile)) { | 
            ||
| 161 | unlink($tempFile);  | 
            ||
| 162 | }  | 
            ||
| 163 | }  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 166 | // --- DELETE OLD FOLDERS ---------------  | 
            ||
| 167 |         xoops_load('XoopsFile'); | 
            ||
| 168 |         if (count($configurator->oldFolders) > 0) { | 
            ||
| 169 |             //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) { | 
            ||
| 170 |             foreach (array_keys($configurator->oldFolders) as $i) { | 
            ||
| 171 |                 $tempFolder = $GLOBALS['xoops']->path('modules/' . $moduleDirName . $configurator->oldFolders[$i]); | 
            ||
| 172 | /** @var XoopsObjectHandler $folderHandler */  | 
            ||
| 173 |                 $folderHandler = XoopsFile::getHandler('folder', $tempFolder); | 
            ||
| 174 | $folderHandler->delete($tempFolder);  | 
            ||
| 175 | }  | 
            ||
| 176 | }  | 
            ||
| 177 | |||
| 178 | // --- CREATE FOLDERS ---------------  | 
            ||
| 179 |         if (count($configurator->uploadFolders) > 0) { | 
            ||
| 180 |             //    foreach (array_keys($GLOBALS['uploadFolders']) as $i) { | 
            ||
| 181 |             foreach (array_keys($configurator->uploadFolders) as $i) { | 
            ||
| 182 | $utility::createFolder($configurator->uploadFolders[$i]);  | 
            ||
| 183 | }  | 
            ||
| 184 | }  | 
            ||
| 185 | |||
| 186 | // --- COPY blank.png FILES ---------------  | 
            ||
| 187 |         if (count($configurator->copyBlankFiles) > 0) { | 
            ||
| 188 | $file = \dirname(__DIR__) . '/assets/images/blank.png';  | 
            ||
| 189 |             foreach (array_keys($configurator->copyBlankFiles) as $i) { | 
            ||
| 190 | $dest = $configurator->copyBlankFiles[$i] . '/blank.png';  | 
            ||
| 191 | $utility::copyFile($file, $dest);  | 
            ||
| 192 | }  | 
            ||
| 193 | }  | 
            ||
| 194 | |||
| 195 | //delete .html entries from the tpl table  | 
            ||
| 196 |         $sql = 'DELETE FROM ' . $GLOBALS['xoopsDB']->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . '\' AND `tpl_file` LIKE \'%.html%\''; | 
            ||
| 197 | $GLOBALS['xoopsDB']->queryF($sql);  | 
            ||
| 198 | |||
| 199 | /** @var \XoopsGroupPermHandler $grouppermHandler */  | 
            ||
| 200 |         $grouppermHandler = xoops_getHandler('groupperm'); | 
            ||
| 201 | |||
| 202 |         return $grouppermHandler->deleteByModule($module->getVar('mid'), 'item_read'); | 
            ||
| 203 | }  | 
            ||
| 204 | |||
| 205 |     if ($previousVersion < 227) { | 
            ||
| 206 | // Add contact_skype  | 
            ||
| 207 |         $sql = 'ALTER TABLE `' . $xoopsDB->prefix('contact') . '` ADD `contact_skype` VARCHAR(255) NULL AFTER `contact_icq`'; | 
            ||
| 208 | $xoopsDB->query($sql);  | 
            ||
| 209 | }  | 
            ||
| 211 |