| Conditions | 13 |
| Paths | 2 |
| Total Lines | 85 |
| Code Lines | 49 |
| Lines | 20 |
| Ratio | 23.53 % |
| 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 | |||
| 58 | foreach (array_keys($oldFiles) as $i) { |
||
| 59 | unlink($GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . $oldFiles[$i])); |
||
| 60 | } |
||
| 61 | |||
| 62 | //delete .html entries from the tpl table |
||
| 63 | $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $module->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
||
| 64 | $xoopsDB->queryF($sql); |
||
| 65 | |||
| 66 | // Load class XoopsFile |
||
| 67 | xoops_load('XoopsFile'); |
||
| 68 | //delete /images directory |
||
| 69 | $imagesDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/images/'); |
||
| 70 | $folderHandler = XoopsFile::getHandler('folder', $imagesDirectory); |
||
| 71 | $folderHandler->delete($imagesDirectory); |
||
| 72 | //delete /css directory |
||
| 73 | $cssDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/css/'); |
||
| 74 | $folderHandler = XoopsFile::getHandler('folder', $cssDirectory); |
||
| 75 | $folderHandler->delete($cssDirectory); |
||
| 76 | //delete /js directory |
||
| 77 | $jsDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/js/'); |
||
| 78 | $folderHandler = XoopsFile::getHandler('folder', $jsDirectory); |
||
| 79 | $folderHandler->delete($jsDirectory); |
||
| 80 | //delete /tcpdf directory |
||
| 81 | $tcpdfDirectory = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/tcpdf/'); |
||
| 82 | $folderHandler = XoopsFile::getHandler('folder', $tcpdfDirectory); |
||
| 83 | $folderHandler->delete($tcpdfDirectory); |
||
| 84 | //delete /templates/style.css file |
||
| 85 | // $cssFile = $GLOBALS['xoops']->path('modules/' . $module->getVar('dirname', 'n') . '/templates/style.css'); |
||
| 86 | // $folderHandler = XoopsFile::getHandler('file', $cssFile); |
||
| 87 | // $folderHandler->delete($cssFile); |
||
| 88 | |||
| 89 | //create upload directories, if needed |
||
| 90 | $moduleDirName = $module->getVar('dirname'); |
||
| 91 | include $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/include/config.php'); |
||
| 92 | |||
| 93 | foreach (array_keys($uploadFolders) as $i) { |
||
| 94 | PublisherUtilities::createFolder($uploadFolders[$i]); |
||
| 95 | } |
||
| 96 | //copy blank.png files, if needed |
||
| 97 | $file = PUBLISHER_ROOT_PATH . '/assets/images/blank.png'; |
||
| 98 | View Code Duplication | foreach (array_keys($copyFiles) as $i) { |
|
| 99 | $dest = $copyFiles[$i] . '/blank.png'; |
||
| 100 | PublisherUtilities::copyFile($file, $dest); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 105 | |||
| 106 | return $gpermHandler->deleteByModule($module->getVar('mid'), 'item_read'); |
||
| 107 | } |
||
| 108 |
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.