| Conditions | 42 |
| Paths | > 20000 |
| Total Lines | 184 |
| Code Lines | 117 |
| Lines | 16 |
| Ratio | 8.7 % |
| 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 |
||
| 27 | function rss($document_list = null, $rss_title = null, $add_description = null) |
||
| 28 | { |
||
| 29 | $oDocumentModel = getModel('document'); |
||
| 30 | $oModuleModel = getModel('module'); |
||
| 31 | $oModuleController = getController('module'); |
||
| 32 | // Get the content and information for the current requested module if the method is not called from another module |
||
| 33 | if(!$document_list) |
||
| 34 | { |
||
| 35 | $site_module_info = Context::get('site_module_info'); |
||
| 36 | $site_srl = $site_module_info->site_srl; |
||
| 37 | $mid = Context::get('mid'); // The target module id, if absent, then all |
||
| 38 | $start_date = (int)Context::get('start_date'); |
||
| 39 | $end_date = (int)Context::get('end_date'); |
||
| 40 | |||
| 41 | $module_srls = array(); |
||
| 42 | $rss_config = array(); |
||
|
|
|||
| 43 | $total_config = ''; |
||
| 44 | $total_config = $oModuleModel->getModuleConfig('rss'); |
||
| 45 | // If one is specified, extract only for this mid |
||
| 46 | if($mid) |
||
| 47 | { |
||
| 48 | $module_srl = $this->module_info->module_srl; |
||
| 49 | $config = $oModuleModel->getModulePartConfig('rss', $module_srl); |
||
| 50 | View Code Duplication | if($config->open_rss && $config->open_rss != 'N') |
|
| 51 | { |
||
| 52 | $module_srls[] = $module_srl; |
||
| 53 | $open_rss_config[$module_srl] = $config->open_rss; |
||
| 54 | } |
||
| 55 | // If mid is not selected, then get all |
||
| 56 | } |
||
| 57 | else |
||
| 58 | { |
||
| 59 | if($total_config->use_total_feed != 'N') |
||
| 60 | { |
||
| 61 | $rss_config = $oModuleModel->getModulePartConfigs('rss', $site_srl); |
||
| 62 | if($rss_config) |
||
| 63 | { |
||
| 64 | foreach($rss_config as $module_srl => $config) |
||
| 65 | { |
||
| 66 | View Code Duplication | if($config && $config->open_rss != 'N' && $config->open_total_feed != 'T_N') |
|
| 67 | { |
||
| 68 | $module_srls[] = $module_srl; |
||
| 69 | $open_rss_config[$module_srl] = $config->open_rss; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | if(!count($module_srls) && !$add_description) return $this->dispError(); |
||
| 77 | |||
| 78 | $info = new stdClass; |
||
| 79 | $args = new stdClass; |
||
| 80 | |||
| 81 | if($module_srls) |
||
| 82 | { |
||
| 83 | $args->module_srl = implode(',',$module_srls); |
||
| 84 | //$module_list = $oModuleModel->getMidList($args); //perhaps module_list varialbles not use |
||
| 85 | |||
| 86 | $args->search_target = 'is_secret'; |
||
| 87 | $args->search_keyword = 'N'; |
||
| 88 | $args->page = (int)Context::get('page'); |
||
| 89 | $args->list_count = 15; |
||
| 90 | if($total_config->feed_document_count) $args->list_count = $total_config->feed_document_count; |
||
| 91 | if(!$args->page || $args->page < 1) $args->page = 1; |
||
| 92 | if($start_date || $start_date != 0) $args->start_date = $start_date; |
||
| 93 | if($end_date || $end_date != 0) $args->end_date = $end_date; |
||
| 94 | if($start_date == 0) unset($start_date); |
||
| 95 | if($end_date == 0) unset($end_date); |
||
| 96 | |||
| 97 | $args->sort_index = 'list_order'; |
||
| 98 | $args->order_type = 'asc'; |
||
| 99 | $output = $oDocumentModel->getDocumentList($args); |
||
| 100 | $document_list = $output->data; |
||
| 101 | // Extract the feed title and information with Context::getBrowserTitle |
||
| 102 | if($mid) |
||
| 103 | { |
||
| 104 | $info->title = Context::getBrowserTitle(); |
||
| 105 | $oModuleController->replaceDefinedLangCode($info->title); |
||
| 106 | |||
| 107 | $info->title = str_replace('\'', ''',$info->title); |
||
| 108 | if($config->feed_description) |
||
| 109 | { |
||
| 110 | $info->description = str_replace('\'', ''', htmlspecialchars($config->feed_description, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 111 | } |
||
| 112 | else |
||
| 113 | { |
||
| 114 | $info->description = str_replace('\'', ''', htmlspecialchars($this->module_info->description, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 115 | } |
||
| 116 | $info->link = getUrl('','mid',$mid); |
||
| 117 | $info->feed_copyright = str_replace('\'', ''', htmlspecialchars($feed_config->feed_copyright, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 118 | View Code Duplication | if(!$info->feed_copyright) |
|
| 119 | { |
||
| 120 | $info->feed_copyright = str_replace('\'', ''', htmlspecialchars($total_config->feed_copyright, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 121 | } |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | if(!$info->title) |
||
| 127 | { |
||
| 128 | if($rss_title) $info->title = $rss_title; |
||
| 129 | else if($total_config->feed_title) $info->title = $total_config->feed_title; |
||
| 130 | else |
||
| 131 | { |
||
| 132 | $site_module_info = Context::get('site_module_info'); |
||
| 133 | $info->title = $site_module_info->browser_title; |
||
| 134 | } |
||
| 135 | |||
| 136 | $oModuleController->replaceDefinedLangCode($info->title); |
||
| 137 | $info->title = str_replace('\'', ''', htmlspecialchars($info->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 138 | $info->description = str_replace('\'', ''', htmlspecialchars($total_config->feed_description, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 139 | $info->link = Context::getRequestUri(); |
||
| 140 | $info->feed_copyright = str_replace('\'', ''', htmlspecialchars($total_config->feed_copyright, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
||
| 141 | } |
||
| 142 | if($add_description) $info->description .= "\r\n".$add_description; |
||
| 143 | |||
| 144 | View Code Duplication | if($total_config->image) $info->image = Context::getRequestUri().str_replace('\'', ''', htmlspecialchars($total_config->image, ENT_COMPAT | ENT_HTML401, 'UTF-8', false)); |
|
| 145 | switch(Context::get('format')) |
||
| 146 | { |
||
| 147 | case 'atom': |
||
| 148 | $info->date = date('Y-m-d\TH:i:sP'); |
||
| 149 | if($mid) { $info->id = getUrl('','mid',$mid,'act','atom','page',Context::get('page'),'start_date',Context::get('start_date'),'end_date',Context::get('end_date')); } |
||
| 150 | View Code Duplication | else { $info->id = getUrl('','module','rss','act','atom','page',Context::get('page'),'start_date',Context::get('start_date'),'end_date',Context::get('end_date')); } |
|
| 151 | break; |
||
| 152 | case 'rss1.0': |
||
| 153 | $info->date = date('Y-m-d\TH:i:sP'); |
||
| 154 | break; |
||
| 155 | default: |
||
| 156 | $info->date = date("D, d M Y H:i:s").' '.$GLOBALS['_time_zone']; |
||
| 157 | break; |
||
| 158 | } |
||
| 159 | |||
| 160 | if($_SERVER['HTTPS']=='on') $proctcl = 'https://'; |
||
| 161 | else $proctcl = 'http://'; |
||
| 162 | |||
| 163 | $temp_link = explode('/', $info->link); |
||
| 164 | if($temp_link[0]=='' && $info->link) |
||
| 165 | { |
||
| 166 | $info->link = $proctcl.$_SERVER['HTTP_HOST'].$info->link; |
||
| 167 | } |
||
| 168 | |||
| 169 | $temp_id = explode('/', $info->id); |
||
| 170 | if($temp_id[0]=='' && $info->id) |
||
| 171 | { |
||
| 172 | $info->id = $proctcl.$_SERVER['HTTP_HOST'].$info->id; |
||
| 173 | } |
||
| 174 | |||
| 175 | $info->language = str_replace('jp','ja',Context::getLangType()); |
||
| 176 | // Set the variables used in the RSS output |
||
| 177 | Context::set('info', $info); |
||
| 178 | Context::set('feed_config', $config); |
||
| 179 | Context::set('open_rss_config', $open_rss_config); |
||
| 180 | Context::set('document_list', $document_list); |
||
| 181 | // Force the result output to be of XMLRPC |
||
| 182 | Context::setResponseMethod("XMLRPC"); |
||
| 183 | // Perform the preprocessing function of the editor component as the results are obtained |
||
| 184 | $path = $this->module_path.'tpl/'; |
||
| 185 | //if($args->start_date || $args->end_date) $file = 'xe_rss'; |
||
| 186 | //else $file = 'rss20'; |
||
| 187 | switch (Context::get('format')) |
||
| 188 | { |
||
| 189 | case 'xe': |
||
| 190 | $file = 'xe_rss'; |
||
| 191 | break; |
||
| 192 | case 'atom': |
||
| 193 | $file = 'atom10'; |
||
| 194 | break; |
||
| 195 | case 'rss1.0': |
||
| 196 | $file = 'rss10'; |
||
| 197 | break; |
||
| 198 | default: |
||
| 199 | $file = 'rss20'; |
||
| 200 | break; |
||
| 201 | } |
||
| 202 | |||
| 203 | $oTemplate = new TemplateHandler(); |
||
| 204 | |||
| 205 | $content = $oTemplate->compile($path, $file); |
||
| 206 | Context::set('content', $content); |
||
| 207 | // Set the template file |
||
| 208 | $this->setTemplatePath($path); |
||
| 209 | $this->setTemplateFile('display'); |
||
| 210 | } |
||
| 211 | |||
| 267 |
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.