| Conditions | 11 |
| Paths | 20 |
| Total Lines | 78 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 28 | function xoops_module_update_extcal(\XoopsModule $xoopsModule, $previousVersion = null) |
||
| 29 | { |
||
| 30 | $helper = Helper::getInstance(); |
||
| 31 | $newVersion = $helper->getModule()->getVar('version') * 100; |
||
| 32 | if ($newVersion == $previousVersion) { |
||
| 33 | return true; |
||
| 34 | } |
||
| 35 | |||
| 36 | //---------------------------------------------------------- |
||
| 37 | // Create eXtCal upload directory |
||
| 38 | $indexFile = __DIR__ . '/index.html'; |
||
| 39 | |||
| 40 | $dir = XOOPS_ROOT_PATH . '/uploads/extcal'; |
||
| 41 | if (!is_dir($dir)) { |
||
| 42 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 43 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 44 | } |
||
| 45 | copy($indexFile, $dir . '/index.html'); |
||
| 46 | } |
||
| 47 | |||
| 48 | $dir = XOOPS_ROOT_PATH . '/uploads/extcal/location'; |
||
| 49 | if (!is_dir($dir)) { |
||
| 50 | if (!mkdir($dir, 0777) && !is_dir($dir)) { |
||
| 51 | throw new \RuntimeException(sprintf('Directory "%s" was not created', $dir)); |
||
| 52 | } |
||
| 53 | copy($indexFile, $dir . '/index.html'); |
||
| 54 | } |
||
| 55 | //------------------------------------------------------------ |
||
| 56 | |||
| 57 | $fld = XOOPS_ROOT_PATH . '/modules/' . $helper->getModule()->getVar('dirname') . '/versions/'; |
||
| 58 | $cls = 'extcal_%1$s'; |
||
| 59 | |||
| 60 | $version = [ |
||
| 61 | '2_04' => 204, |
||
| 62 | '2_15' => 215, |
||
| 63 | '2_21' => 221, |
||
| 64 | '2_28' => 228, |
||
| 65 | '2_29' => 229, |
||
| 66 | '2_33' => 233, |
||
| 67 | '2_34' => 234, |
||
| 68 | '2_35' => 235, |
||
| 69 | '2_37' => 237, |
||
| 70 | ]; |
||
| 71 | |||
| 72 | // while (list($key, $val) = each($version)) { |
||
| 73 | foreach ($version as $key => $val) { |
||
| 74 | if ($previousVersion < $val) { |
||
| 75 | $name = sprintf($cls, $key); |
||
| 76 | $f = $fld . $name . '.php'; |
||
| 77 | //ext_echo ("<hr>{$f}<hr>"); |
||
| 78 | if (is_readable($f)) { |
||
| 79 | echo "_AM_EXTCAL_UPDATE_VERSION {$key} = {$val}<br>"; |
||
| 80 | require_once $f; |
||
| 81 | $cl = new $name($xoopsModule, ['previousVersion' => $previousVersion]); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | /* |
||
| 87 | //$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 88 | $xoopsDB = \XoopsDatabaseFactory::getDatabaseConnection(); |
||
| 89 | |||
| 90 | $sql = "ALTER TABLE `".$db->prefix('extcal_event')."` ADD `event_organisateur` varchar( 255 ) NOT NULL AFTER `event_desc` ;"; |
||
| 91 | $db->query($sql); |
||
| 92 | /////////// |
||
| 93 | // Create eXtcal upload directory |
||
| 94 | $dir = XOOPS_ROOT_PATH."/uploads/extcal/location"; |
||
| 95 | if(!is_dir($dir)) |
||
| 96 | mkdir($dir, 0777); |
||
| 97 | chmod($dir, 0777); |
||
| 98 | |||
| 99 | // Copy index.html files on uploads folders |
||
| 100 | $indexFile = XOOPS_ROOT_PATH."/modules/extcal/include/index.html"; |
||
| 101 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/extcal/location/index.html"); |
||
| 102 | |||
| 103 | */ |
||
| 104 | |||
| 105 | return true; |
||
| 106 | } |
||
| 107 |