| Conditions | 46 |
| Paths | 18835 |
| Total Lines | 269 |
| Code Lines | 172 |
| Lines | 15 |
| Ratio | 5.58 % |
| 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 |
||
| 102 | function getSyndicationList() { |
||
| 103 | $oModuleModel = getModel('module'); |
||
| 104 | $config = $oModuleModel->getModuleConfig('syndication'); |
||
| 105 | if(!$config->year || !$config->site_url || !$config->syndication_token) |
||
| 106 | { |
||
| 107 | return $this->makeObject(-1,'msg_check_syndication_config'); |
||
| 108 | } |
||
| 109 | |||
| 110 | $id = Context::get('id'); |
||
| 111 | $type = Context::get('type'); |
||
| 112 | |||
| 113 | $startTime = Context::get('start-time'); |
||
| 114 | $endTime = Context::get('end-time'); |
||
| 115 | |||
| 116 | $page = Context::get('page'); |
||
| 117 | if(!$page) |
||
| 118 | { |
||
| 119 | $page = 1; |
||
| 120 | } |
||
| 121 | $vars = Context::getRequestVars(); |
||
|
|
|||
| 122 | if(!$id || !$type) |
||
| 123 | { |
||
| 124 | return $this->makeObject(-1,'msg_invalid_request'); |
||
| 125 | } |
||
| 126 | |||
| 127 | if(!preg_match('/^tag:([^,]+),([0-9]+):(site|channel|article)(.*)$/i',$id,$matches)) |
||
| 128 | { |
||
| 129 | return $this->makeObject(-1,'msg_invalid_request'); |
||
| 130 | } |
||
| 131 | |||
| 132 | if($config->syndication_password != Context::get('syndication_password')) |
||
| 133 | { |
||
| 134 | return $this->makeObject(-1,'msg_invalid_request'); |
||
| 135 | } |
||
| 136 | |||
| 137 | $url = $matches[1]; |
||
| 138 | $year = $matches[2]; |
||
| 139 | $target = $matches[3]; |
||
| 140 | $id = $matches[4]; |
||
| 141 | if($id && $id{0}==':') |
||
| 142 | { |
||
| 143 | $id = substr($id, 1); |
||
| 144 | } |
||
| 145 | |||
| 146 | $module_srl = null; |
||
| 147 | $document_srl = null; |
||
| 148 | if($id && strpos($id,'-')!==false) |
||
| 149 | { |
||
| 150 | list($module_srl, $document_srl) = explode('-', $id); |
||
| 151 | } |
||
| 152 | elseif($id) |
||
| 153 | { |
||
| 154 | $module_srl = $id; |
||
| 155 | } |
||
| 156 | |||
| 157 | if(!$url || !$year || !$target) |
||
| 158 | { |
||
| 159 | return $this->makeObject(-1,'msg_invalid_request'); |
||
| 160 | } |
||
| 161 | |||
| 162 | $time_zone = substr($GLOBALS['_time_zone'], 0, 3).':'.substr($GLOBALS['_time_zone'], 3); |
||
| 163 | Context::set('time_zone', $time_zone); |
||
| 164 | |||
| 165 | $site_module_info = Context::get('site_module_info'); |
||
| 166 | |||
| 167 | if($target == 'channel' && !$module_srl) |
||
| 168 | { |
||
| 169 | $target = 'site'; |
||
| 170 | } |
||
| 171 | |||
| 172 | if($module_srl) |
||
| 173 | { |
||
| 174 | $args = new stdClass; |
||
| 175 | $args->module_srls = $module_srl; |
||
| 176 | $output = executeQuery('syndication.getModules', $args); |
||
| 177 | $module_info = $output->data; |
||
| 178 | self::$modules[$module_srl] = $output->data; |
||
| 179 | } |
||
| 180 | |||
| 181 | if($target == 'channel' && $module_srl) |
||
| 182 | { |
||
| 183 | if($module_info) |
||
| 184 | { |
||
| 185 | $args->module_srl = $module_srl; |
||
| 186 | $output = executeQuery('syndication.getExceptModules', $args); |
||
| 187 | if($output->data->count) |
||
| 188 | { |
||
| 189 | $error = 'target is not founded'; |
||
| 190 | } |
||
| 191 | } |
||
| 192 | else |
||
| 193 | { |
||
| 194 | $error = 'target is not founded'; |
||
| 195 | } |
||
| 196 | |||
| 197 | unset($args); |
||
| 198 | } |
||
| 199 | |||
| 200 | if(!$error) |
||
| 201 | { |
||
| 202 | Context::set('target', $target); |
||
| 203 | Context::set('type', $type); |
||
| 204 | |||
| 205 | $oMemberModel = getModel('member'); |
||
| 206 | $member_config = $oMemberModel->getMemberConfig(); |
||
| 207 | |||
| 208 | $oModuleModel = getModel('module'); |
||
| 209 | $site_config = $oModuleModel->getModuleConfig('module'); |
||
| 210 | |||
| 211 | switch($target) |
||
| 212 | { |
||
| 213 | case 'site' : |
||
| 214 | $site_info = new stdClass; |
||
| 215 | $site_info->id = $this->getID('site'); |
||
| 216 | $site_info->site_url = getFullSiteUrl($this->uri_scheme . $this->site_url, ''); |
||
| 217 | $site_info->site_title = $this->handleLang($site_module_info->browser_title, $site_module_info->site_srl); |
||
| 218 | $site_info->title = $site_info->site_title; |
||
| 219 | |||
| 220 | if($module_srl) |
||
| 221 | { |
||
| 222 | $args->module_srl = $module_srl; |
||
| 223 | $site_info->title = $this->handleLang($module_info->browser_title, $module_info->site_srl); |
||
| 224 | if(!$site_info->title) |
||
| 225 | { |
||
| 226 | $site_info->title = $site_info->site_title; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | else |
||
| 230 | { |
||
| 231 | $except_module_output = executeQueryArray('syndication.getExceptModuleSrls'); |
||
| 232 | if(is_array($except_module_output->data)) |
||
| 233 | { |
||
| 234 | $except_module_srls = array(); |
||
| 235 | foreach($except_module_output->data as $val) |
||
| 236 | { |
||
| 237 | $except_module_srls[] = $val->module_srl; |
||
| 238 | } |
||
| 239 | $args->except_modules = implode(',', $except_module_srls); |
||
| 240 | } |
||
| 241 | } |
||
| 242 | |||
| 243 | $output = executeQuery('syndication.getSiteUpdatedTime', $args); |
||
| 244 | |||
| 245 | View Code Duplication | if($output->data) |
|
| 246 | { |
||
| 247 | $site_info->updated = date("Y-m-d\\TH:i:s", ztime($output->data->last_update)).$time_zone; |
||
| 248 | } |
||
| 249 | |||
| 250 | $site_info->self_href = $this->getSelfHref($site_info->id,$type); |
||
| 251 | Context::set('site_info', $site_info); |
||
| 252 | |||
| 253 | $this->setTemplateFile('site'); |
||
| 254 | switch($type) { |
||
| 255 | case 'article' : |
||
| 256 | // 문서 전체를 신디케이션에 추가 |
||
| 257 | Context::set('articles', $this->getArticles($module_srl, $page, $startTime, $endTime, 'article',$site_info->id)); |
||
| 258 | $next_url = Context::get('articles')->next_url; |
||
| 259 | |||
| 260 | break; |
||
| 261 | case 'deleted' : |
||
| 262 | // 문서 전체를 신디케이션에서 삭제 |
||
| 263 | Context::set('deleted', $this->getArticles($module_srl, $page, $startTime, $endTime, 'deleted',$site_info->id)); |
||
| 264 | $next_url = Context::get('deleted')->next_url; |
||
| 265 | break; |
||
| 266 | default : |
||
| 267 | $this->setTemplateFile('site.info'); |
||
| 268 | break; |
||
| 269 | } |
||
| 270 | |||
| 271 | // 다음 페이지가 있다면 다시 신디케이션 호출 |
||
| 272 | if($next_url) |
||
| 273 | { |
||
| 274 | $oSyndicationController = getController('syndication'); |
||
| 275 | $oSyndicationController->ping(Context::get('id'), Context::get('type'), ++$page); |
||
| 276 | } |
||
| 277 | break; |
||
| 278 | case 'channel' : |
||
| 279 | $channel_info = new stdClass; |
||
| 280 | $channel_info->id = $this->getID('channel', $module_info->module_srl); |
||
| 281 | $channel_info->site_title = $this->handleLang($site_module_info->browser_title, $site_module_info->site_srl); |
||
| 282 | $channel_info->title = $this->handleLang($module_info->browser_title, $module_info->site_srl); |
||
| 283 | $channel_info->updated = date("Y-m-d\\TH:i:s").$time_zone; |
||
| 284 | $channel_info->self_href = $this->getSelfHref($channel_info->id, $type); |
||
| 285 | $channel_info->site_url = getFullSiteUrl($this->uri_scheme . $this->site_url, ''); |
||
| 286 | $channel_info->alternative_href = $this->getChannelAlternativeHref($module_info->module_srl); |
||
| 287 | $channel_info->summary = $module_info->description; |
||
| 288 | View Code Duplication | if($module_info->module == "textyle") |
|
| 289 | { |
||
| 290 | $channel_info->type = "blog"; |
||
| 291 | $channel_info->rss_href = getFullSiteUrl($module_info->domain, '', 'mid', $module_info->mid, 'act', 'rss'); |
||
| 292 | } |
||
| 293 | else |
||
| 294 | { |
||
| 295 | $channel_info->type = "web"; |
||
| 296 | } |
||
| 297 | $except_module_srls = $this->getExceptModuleSrls(); |
||
| 298 | if($except_module_srls) |
||
| 299 | { |
||
| 300 | $args->except_modules = implode(',',$except_module_srls); |
||
| 301 | } |
||
| 302 | |||
| 303 | $output = executeQuery('syndication.getSiteUpdatedTime', $args); |
||
| 304 | View Code Duplication | if($output->data) $channel_info->updated = date("Y-m-d\\TH:i:s", ztime($output->data->last_update)).$time_zone; |
|
| 305 | Context::set('channel_info', $channel_info); |
||
| 306 | |||
| 307 | $this->setTemplateFile('channel'); |
||
| 308 | switch($type) { |
||
| 309 | case 'article' : |
||
| 310 | Context::set('articles', $this->getArticles($module_srl, $page, $startTime, $endTime, 'article', $channel_info->id)); |
||
| 311 | break; |
||
| 312 | case 'deleted' : |
||
| 313 | Context::set('deleted', $this->getDeleted($module_srl, $page, $startTime, $endTime, 'deleted', $channel_info->id)); |
||
| 314 | break; |
||
| 315 | default : |
||
| 316 | $this->setTemplateFile('channel.info'); |
||
| 317 | break; |
||
| 318 | } |
||
| 319 | break; |
||
| 320 | |||
| 321 | case 'article': |
||
| 322 | $channel_info = new stdClass; |
||
| 323 | $channel_info->id = $this->getID('channel', $module_info->module_srl); |
||
| 324 | $channel_info->title = $this->handleLang($module_info->browser_title, $module_info->site_srl); |
||
| 325 | $channel_info->site_title = $site_config->siteTitle; |
||
| 326 | if(!$channel_info->site_title) { |
||
| 327 | $channel_info->site_title = $channel_info->title; |
||
| 328 | } |
||
| 329 | $channel_info->updated = date("Y-m-d\\TH:i:s").$time_zone; |
||
| 330 | $channel_info->self_href = $this->getSelfHref($channel_info->id, $type); |
||
| 331 | $channel_info->site_url = getFullSiteUrl($this->uri_scheme . $this->site_url, ''); |
||
| 332 | $channel_info->alternative_href = $this->getChannelAlternativeHref($module_info->module_srl); |
||
| 333 | $channel_info->webmaster_name = $member_config->webmaster_name; |
||
| 334 | $channel_info->webmaster_email = $member_config->webmaster_email; |
||
| 335 | |||
| 336 | $except_module_srls = $this->getExceptModuleSrls(); |
||
| 337 | if($except_module_srls) |
||
| 338 | { |
||
| 339 | $args->except_modules = implode(',',$except_module_srls); |
||
| 340 | } |
||
| 341 | |||
| 342 | $output = executeQuery('syndication.getSiteUpdatedTime', $args); |
||
| 343 | View Code Duplication | if($output->data) $channel_info->updated = date("Y-m-d\\TH:i:s", ztime($output->data->last_update)).$time_zone; |
|
| 344 | Context::set('channel_info', $channel_info); |
||
| 345 | Context::set('member_config', $member_config); |
||
| 346 | |||
| 347 | $this->setTemplateFile('channel'); |
||
| 348 | switch($type) { |
||
| 349 | case "article" : |
||
| 350 | $articles = new stdClass; |
||
| 351 | $articles->list = array($this->getArticle($document_srl)); |
||
| 352 | Context::set('articles', $articles); |
||
| 353 | break; |
||
| 354 | |||
| 355 | case "deleted" : |
||
| 356 | $deleted = new stdClass; |
||
| 357 | $deleted->list = $this->getDeletedByDocumentSrl($document_srl); |
||
| 358 | Context::set('deleted', $deleted); |
||
| 359 | break; |
||
| 360 | } |
||
| 361 | break; |
||
| 362 | } |
||
| 363 | } else { |
||
| 364 | Context::set('message', $error); |
||
| 365 | $this->setTemplateFile('error'); |
||
| 366 | } |
||
| 367 | |||
| 368 | $this->setTemplatePath($this->module_path.'tpl'); |
||
| 369 | Context::setResponseMethod('XMLRPC'); |
||
| 370 | } |
||
| 371 | |||
| 641 |
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.