Conditions | 7 |
Paths | 17 |
Total Lines | 73 |
Code Lines | 34 |
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 |
||
9 | function xoops_module_update_extcal(XoopsModule $xoopsModule, $oldVersion = null) |
||
|
|||
10 | { |
||
11 | $newVersion = $xoopsModule->getVar('version') * 100; |
||
12 | if ($newVersion == $oldVersion) { |
||
13 | return true; |
||
14 | } |
||
15 | |||
16 | //---------------------------------------------------------- |
||
17 | // Create eXtCal upload directory |
||
18 | $indexFile = __DIR__.'/index.html'; |
||
19 | |||
20 | $dir = XOOPS_ROOT_PATH.'/uploads/extcal'; |
||
21 | if (!is_dir($dir)) { |
||
22 | mkdir($dir, 0777); |
||
23 | copy($indexFile, $dir.'/index.html'); |
||
24 | } |
||
25 | |||
26 | $dir = XOOPS_ROOT_PATH.'/uploads/extcal/etablissement'; |
||
27 | if (!is_dir($dir)) { |
||
28 | mkdir($dir, 0777); |
||
29 | copy($indexFile, $dir.'/index.html'); |
||
30 | } |
||
31 | //------------------------------------------------------------ |
||
32 | |||
33 | $fld = XOOPS_ROOT_PATH.'/modules/'.$xoopsModule->getVar('dirname').'/versions/'; |
||
34 | $cls = 'extcal_%1$s'; |
||
35 | |||
36 | $version = array( |
||
37 | '2_04' => 204, |
||
38 | '2_15' => 215, |
||
39 | '2_21' => 221, |
||
40 | '2_28' => 228, |
||
41 | '2_29' => 229, |
||
42 | '2_33' => 233, |
||
43 | '2_34' => 234, |
||
44 | '2_35' => 235, |
||
45 | '2_37' => 237, |
||
46 | ); |
||
47 | |||
48 | View Code Duplication | while (list($key, $val) = each($version)) { |
|
49 | if ($oldVersion < $val) { |
||
50 | $name = sprintf($cls, $key); |
||
51 | $f = $fld.$name.'.php'; |
||
52 | //ext_echo ("<hr>{$f}<hr>"); |
||
53 | if (is_readable($f)) { |
||
54 | echo "mise à jour version : {$key} = {$val}<br>"; |
||
55 | include_once $f; |
||
56 | $cl = new $name($xoopsModule, array('oldVersion' => $oldVersion)); |
||
57 | } |
||
58 | } |
||
59 | } |
||
60 | |||
61 | /* |
||
62 | //$db = Database::getInstance(); |
||
63 | $xoopsDB = XoopsDatabaseFactory::getDatabaseConnection(); |
||
64 | |||
65 | $sql = "ALTER TABLE `".$db->prefix('extcal_event')."` ADD `event_organisateur` varchar( 255 ) NOT NULL AFTER `event_desc` ;"; |
||
66 | $db->query($sql); |
||
67 | /////////// |
||
68 | // Create eXtcal upload directory |
||
69 | $dir = XOOPS_ROOT_PATH."/uploads/extcal/etablissement"; |
||
70 | if(!is_dir($dir)) |
||
71 | mkdir($dir, 0777); |
||
72 | chmod($dir, 0777); |
||
73 | |||
74 | // Copy index.html files on uploads folders |
||
75 | $indexFile = XOOPS_ROOT_PATH."/modules/extcal/include/index.html"; |
||
76 | copy($indexFile, XOOPS_ROOT_PATH."/uploads/extcal/etablissement/index.html"); |
||
77 | |||
78 | */ |
||
79 | |||
80 | return true; |
||
81 | } |
||
82 |
This check looks for functions that have already been defined in other files.
Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the
@ignore
annotation.See also the PhpDoc documentation for @ignore.