| Conditions | 11 |
| Paths | 7 |
| Total Lines | 38 |
| Code Lines | 22 |
| Lines | 9 |
| Ratio | 23.68 % |
| 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 |
||
| 26 | function checkUpdate() |
||
| 27 | { |
||
| 28 | $oDB = &DB::getInstance(); |
||
| 29 | $oModuleModel = getModel('module'); |
||
| 30 | $oModuleController = getController('module'); |
||
| 31 | $version_update_id = implode('.', array(__CLASS__, __XE_VERSION__, 'updated')); |
||
| 32 | if($oModuleModel->needUpdate($version_update_id)) |
||
| 33 | { |
||
| 34 | // 2009. 02. 11 Add site_srl to layout table |
||
| 35 | if(!$oDB->isColumnExists('layouts', 'site_srl')) return true; |
||
| 36 | // 2009. 02. 26 Move the previous layout for faceoff |
||
| 37 | $files = FileHandler::readDir('./files/cache/layout'); |
||
| 38 | for($i=0,$c=count($files);$i<$c;$i++) |
||
| 39 | { |
||
| 40 | $filename = $files[$i]; |
||
| 41 | if(preg_match('/([0-9]+)\.html/i',$filename)) return true; |
||
| 42 | } |
||
| 43 | |||
| 44 | if(!$oDB->isColumnExists('layouts', 'layout_type')) return true; |
||
| 45 | |||
| 46 | $args = new stdClass(); |
||
| 47 | $args->layout = '.'; |
||
| 48 | $output = executeQueryArray('layout.getLayoutDotList', $args); |
||
| 49 | View Code Duplication | if($output->data && count($output->data) > 0) |
|
| 50 | { |
||
| 51 | foreach($output->data as $layout) |
||
| 52 | { |
||
| 53 | $layout_path = explode('.', $layout->layout); |
||
| 54 | if(count($layout_path) != 2) continue; |
||
| 55 | if(is_dir(sprintf(_XE_PATH_ . 'themes/%s/layouts/%s', $layout_path[0], $layout_path[1]))) return true; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | $oModuleController->insertUpdatedLog($version_update_id); |
||
| 60 | } |
||
| 61 | |||
| 62 | return false; |
||
| 63 | } |
||
| 64 | |||
| 139 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.