| Conditions | 13 |
| Paths | 2 |
| Total Lines | 84 |
| Code Lines | 49 |
| Lines | 20 |
| Ratio | 23.81 % |
| Changes | 2 | ||
| 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 |
||
| 23 | function xoops_module_update_publisher(XoopsModule $module, $oldversion = null) |
||
| 24 | { |
||
| 25 | global $xoopsDB; |
||
| 26 | if ($oldversion < 102) { |
||
| 27 | // delete old html template files |
||
| 28 | $templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/'); |
||
| 29 | $templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
||
| 30 | View Code Duplication | foreach ($templateList as $k => $v) { |
|
| 31 | $fileInfo = new SplFileInfo($templateDirectory . $v); |
||
| 32 | if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
||
| 33 | if (file_exists($templateDirectory . $v)) { |
||
| 34 | unlink($templateDirectory . $v); |
||
| 35 | } |
||
| 36 | } |
||
| 37 | } |
||
| 38 | // delete old block html template files |
||
| 39 | $templateDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/blocks/'); |
||
| 40 | $templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
||
| 41 | View Code Duplication | foreach ($templateList as $k => $v) { |
|
| 42 | $fileInfo = new SplFileInfo($templateDirectory . $v); |
||
| 43 | if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
||
| 44 | if (file_exists($templateDirectory . $v)) { |
||
| 45 | unlink($templateDirectory . $v); |
||
| 46 | } |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | //delete old files: |
||
| 51 | $oldFiles = array( |
||
| 52 | '/class/request.php', |
||
| 53 | '/class/registry.php', |
||
| 54 | '/include/constants.php', |
||
| 55 | '/ajaxrating.txt'); |
||
| 56 | |||
| 57 | foreach (array_keys($oldFiles) as $i) { |
||
| 58 | unlink($GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . $oldFiles[$i])); |
||
| 59 | } |
||
| 60 | |||
| 61 | //delete .html entries from the tpl table |
||
| 62 | $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
||
| 63 | $xoopsDB->queryF($sql); |
||
| 64 | |||
| 65 | // Load class XoopsFile |
||
| 66 | xoops_load('XoopsFile'); |
||
| 67 | //delete /images directory |
||
| 68 | $imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
||
| 69 | $folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
||
| 70 | $folderHandler->delete($imagesDirectory); |
||
| 71 | //delete /css directory |
||
| 72 | $cssDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/css/'); |
||
| 73 | $folderHandler = XoopsFile::getHandler('folder', $cssDirectory); |
||
| 74 | $folderHandler->delete($cssDirectory); |
||
| 75 | //delete /js directory |
||
| 76 | $jsDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/js/'); |
||
| 77 | $folderHandler = XoopsFile::getHandler('folder', $jsDirectory); |
||
| 78 | $folderHandler->delete($jsDirectory); |
||
| 79 | //delete /tcpdf directory |
||
| 80 | $tcpdfDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/tcpdf/'); |
||
| 81 | $folderHandler = XoopsFile::getHandler('folder', $tcpdfDirectory); |
||
| 82 | $folderHandler->delete($tcpdfDirectory); |
||
| 83 | //delete /templates/style.css file |
||
| 84 | // $cssFile = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/style.css'); |
||
| 85 | // $folderHandler = XoopsFile::getHandler('file', $cssFile); |
||
| 86 | // $folderHandler->delete($cssFile); |
||
| 87 | |||
| 88 | //create upload directories, if needed |
||
| 89 | $moduleDirName = $module->getVar('dirname'); |
||
| 90 | include $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/config.php'); |
||
| 91 | |||
| 92 | foreach (array_keys($uploadFolders) as $i) { |
||
| 93 | PublisherUtilities::createFolder($uploadFolders[$i]); |
||
| 94 | } |
||
| 95 | //copy blank.png files, if needed |
||
| 96 | $file = PUBLISHER_ROOT_PATH . '/assets/images/blank.png'; |
||
| 97 | View Code Duplication | foreach (array_keys($copyFiles) as $i) { |
|
| 98 | $dest = $copyFiles[$i] . '/blank.png'; |
||
| 99 | PublisherUtilities::copyFile($file, $dest); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 104 | |||
| 105 | return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
| 106 | } |
||
| 107 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@returnannotation as described here.