| Conditions | 4 |
| Paths | 8 |
| Total Lines | 73 |
| Lines | 7 |
| Ratio | 9.59 % |
| 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 |
||
| 28 | function apcal_monthly_calendar_show($options) |
||
| 29 | { |
||
| 30 | global $xoopsConfig, $xoopsDB; |
||
| 31 | |||
| 32 | |||
| 33 | $moduleDirName = empty($options[0]) ? basename(dirname(__DIR__)) : $options[0]; |
||
| 34 | xoops_loadLanguage('main', $moduleDirName); |
||
| 35 | |||
| 36 | // setting physical & virtual paths |
||
| 37 | $mod_path = XOOPS_ROOT_PATH . "/modules/$moduleDirName"; |
||
| 38 | $mod_url = XOOPS_URL . "/modules/$moduleDirName"; |
||
| 39 | |||
| 40 | // defining class of APCal |
||
| 41 | if (!class_exists('APCal_xoops')) { |
||
| 42 | require_once "$mod_path/class/APCal.php"; |
||
| 43 | require_once "$mod_path/class/APCal_xoops.php"; |
||
| 44 | } |
||
| 45 | |||
| 46 | // creating an instance of APCal |
||
| 47 | $cal = new APCal_xoops('', $xoopsConfig['language'], true); |
||
| 48 | |||
| 49 | // ignoring cid from GET |
||
| 50 | $cal->now_cid = 0; |
||
| 51 | |||
| 52 | // setting properties of APCal |
||
| 53 | $cal->conn = $GLOBALS['xoopsDB']->conn; |
||
| 54 | include "$mod_path/include/read_configs.php"; |
||
| 55 | $cal->base_url = $mod_url; |
||
| 56 | $cal->base_path = $mod_path; |
||
| 57 | $cal->images_url = "$mod_url/assets/images/$skin_folder"; |
||
|
|
|||
| 58 | $cal->images_path = "$mod_path/assets/images/$skin_folder"; |
||
| 59 | |||
| 60 | $original_level = error_reporting(E_ALL ^ E_NOTICE); |
||
| 61 | |||
| 62 | require_once "$mod_path/include/patTemplate.php"; |
||
| 63 | $tmpl = new PatTemplate(); |
||
| 64 | $tmpl->readTemplatesFromFile("$cal->images_path/default/block_monthly.tmpl.html"); |
||
| 65 | |||
| 66 | // setting skin folder |
||
| 67 | $tmpl->addVar('WholeBoard', 'SKINPATH', $cal->images_url); |
||
| 68 | |||
| 69 | // setting language |
||
| 70 | $tmpl->addVar('WholeBoard', 'LANG_PREV_MONTH', _MB_APCAL_PREV_MONTH); |
||
| 71 | $tmpl->addVar('WholeBoard', 'LANG_NEXT_MONTH', _MB_APCAL_NEXT_MONTH); |
||
| 72 | $tmpl->addVar('WholeBoard', 'LANG_YEAR', _MB_APCAL_YEAR); |
||
| 73 | $tmpl->addVar('WholeBoard', 'LANG_MONTH', _MB_APCAL_MONTH); |
||
| 74 | $tmpl->addVar('WholeBoard', 'LANG_JUMP', _MB_APCAL_JUMP); |
||
| 75 | |||
| 76 | // Static parameter for the request |
||
| 77 | $tmpl->addVar('WholeBoard', 'GET_TARGET', "$mod_url/index.php"); |
||
| 78 | $tmpl->addVar('WholeBoard', 'QUERY_STRING', ''); |
||
| 79 | |||
| 80 | // Variables required in header part etc. |
||
| 81 | $tmpl->addVars('WholeBoard', $cal->get_calendar_information('M')); |
||
| 82 | |||
| 83 | // BODY of the calendar |
||
| 84 | $tmpl->addVar('WholeBoard', 'CALENDAR_BODY', $cal->get_monthly_html("$mod_url/index.php")); |
||
| 85 | |||
| 86 | // legends of long events |
||
| 87 | View Code Duplication | foreach ($cal->long_event_legends as $bit => $legend) { |
|
| 88 | $tmpl->addVar('LongEventLegends', 'BIT_MASK', 1 << ($bit - 1)); |
||
| 89 | $tmpl->addVar('LongEventLegends', 'LEGEND_ALT', _APCAL_MB_ALLDAY_EVENT . " $bit"); |
||
| 90 | $tmpl->addVar('LongEventLegends', 'LEGEND', $legend); |
||
| 91 | $tmpl->addVar('LongEventLegends', 'SKINPATH', $cal->images_url); |
||
| 92 | $tmpl->parseTemplate('LongEventLegends', 'a'); |
||
| 93 | } |
||
| 94 | |||
| 95 | // content generated from PatTemplate |
||
| 96 | $block['content'] = $tmpl->getParsedTemplate('WholeBoard'); |
||
| 97 | error_reporting($original_level); |
||
| 98 | |||
| 99 | return $block; |
||
| 100 | } |
||
| 101 | |||
| 111 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.