Conditions | 13 |
Paths | 6 |
Total Lines | 54 |
Lines | 16 |
Ratio | 29.63 % |
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 |
||
25 | function xoops_module_update_mylinks_base(XoopsModule $xoopsModule, $prev_version) |
||
26 | { |
||
27 | $minUpgradeFrom = '0.0.0'; //minimum version of module supported for upgrade |
||
28 | $success = false; |
||
29 | |||
30 | $ref = xoops_getenv('HTTP_REFERER'); //referer check |
||
31 | if ($ref == '' || strpos($ref, XOOPS_URL . '/modules/system/admin.php') === 0) { |
||
32 | /* module specific part */ |
||
33 | $minValueArray = explode('.', $minUpgradeFrom); |
||
34 | $installedVersion = (int)$prev_version; |
||
35 | $minSupportedVersion = ($minValueArray[0] * 100) + ($minValueArray[1] * 10) + $minValueArray[2]; |
||
36 | $modErrMsg = "<span style='color: red; font-weight: bold;'>This module cannot be upgraded from version {$installedVersion}.</span>"; |
||
37 | |||
38 | if ($installedVersion < $minSupportedVersion) { |
||
39 | $success = false; |
||
40 | $xoopsModule->setErrors($modErrMsg); |
||
41 | } else { |
||
42 | require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/include/oninstall.inc.php'; |
||
43 | $success = xoops_module_pre_install_mylinks($xoopsModule); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | global $xoopsDB; |
||
48 | if ($prev_version < 312) { |
||
49 | // delete old html template files |
||
50 | $templateDirectory = $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/templates/'); |
||
51 | $templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
||
52 | View Code Duplication | foreach ($templateList as $k => $v) { |
|
|
|||
53 | $fileInfo = new SplFileInfo($templateDirectory . $v); |
||
54 | if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
||
55 | if (file_exists($templateDirectory . $v)) { |
||
56 | unlink($templateDirectory . $v); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | // delete old block html template files |
||
61 | $templateDirectory = $GLOBALS['xoops']->path('modules/' . $xoopsModule->getVar('dirname', 'n') . '/templates/blocks/'); |
||
62 | $templateList = array_diff(scandir($templateDirectory), array('..', '.')); |
||
63 | View Code Duplication | foreach ($templateList as $k => $v) { |
|
64 | $fileInfo = new SplFileInfo($templateDirectory . $v); |
||
65 | if ($fileInfo->getExtension() === 'html' && $fileInfo->getFilename() !== 'index.html') { |
||
66 | if (file_exists($templateDirectory . $v)) { |
||
67 | unlink($templateDirectory . $v); |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | //delete .html entries from the tpl table |
||
73 | $sql = 'DELETE FROM ' . $xoopsDB->prefix('tplfile') . " WHERE `tpl_module` = '" . $xoopsModule->getVar('dirname', 'n') . "' AND `tpl_file` LIKE '%.html%'"; |
||
74 | $xoopsDB->queryF($sql); |
||
75 | } |
||
76 | |||
77 | return $success; |
||
78 | } |
||
79 | |||
88 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.