| Conditions | 27 |
| Paths | > 20000 |
| Total Lines | 222 |
| Lines | 5 |
| Ratio | 2.25 % |
| 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 |
||
| 147 | public function display($dummy1 = null, $dummy2 = null, $dummy3 = null): void |
||
| 148 | { |
||
| 149 | global $opt, $db, $cookie, $login, $menu, $sqldebugger, $translate, $useragent_msie; |
||
| 150 | $cookie->close(); |
||
| 151 | |||
| 152 | // if the user is an admin, don't cache the content |
||
| 153 | if (isset($login)) { |
||
| 154 | if ($login->admin) { |
||
| 155 | $this->caching = 0; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | //Give Smarty access to the whole options array. |
||
| 160 | $this->assign('siteSettings', $opt); |
||
| 161 | $this->assign('GeoCacheTypeEvent', GeoCacheType::EVENT); |
||
| 162 | |||
| 163 | //Should we remove this whole block since we now have |
||
| 164 | //access using the siteSettings above? |
||
| 165 | // assign main template vars |
||
| 166 | // ... and some of the $opt |
||
| 167 | $locale = $opt['template']['locale']; |
||
| 168 | |||
| 169 | $optn = []; |
||
| 170 | $optn['debug'] = $opt['debug']; |
||
| 171 | $optn['template']['locales'] = $opt['template']['locales']; |
||
| 172 | $optn['template']['locale'] = $opt['template']['locale']; |
||
| 173 | $optn['template']['style'] = $opt['template']['style']; |
||
| 174 | $optn['template']['country'] = $login->getUserCountry(); |
||
| 175 | $optn['page']['subtitle1'] = isset($opt['locale'][$locale]['page']['subtitle1']) ? $opt['locale'][$locale]['page']['subtitle1'] : $opt['page']['subtitle1']; |
||
| 176 | $optn['page']['subtitle2'] = isset($opt['locale'][$locale]['page']['subtitle2']) ? $opt['locale'][$locale]['page']['subtitle2'] : $opt['page']['subtitle2']; |
||
| 177 | $optn['page']['sitename'] = $opt['page']['sitename']; |
||
| 178 | $optn['page']['headimagepath'] = $opt['page']['headimagepath']; |
||
| 179 | $optn['page']['headoverlay'] = $opt['page']['headoverlay']; |
||
| 180 | $optn['page']['max_logins_per_hour'] = $opt['page']['max_logins_per_hour']; |
||
| 181 | $optn['page']['absolute_url'] = $opt['page']['absolute_url']; |
||
| 182 | $optn['page']['absolute_urlpath'] = parse_url($opt['page']['absolute_url'], PHP_URL_PATH); |
||
| 183 | $optn['page']['absolute_http_url'] = $opt['page']['absolute_http_url']; |
||
| 184 | $optn['page']['default_absolute_url'] = $opt['page']['default_absolute_url']; |
||
| 185 | $optn['page']['login_url'] = ($opt['page']['https']['force_login'] ? $opt['page']['absolute_https_url'] : '') . 'login.php'; |
||
| 186 | $optn['page']['target'] = $this->target; |
||
| 187 | $optn['page']['showdonations'] = $opt['page']['showdonations']; |
||
| 188 | $optn['page']['title'] = $opt['page']['title']; |
||
| 189 | $optn['page']['nowpsearch'] = $this->nowpsearch; |
||
| 190 | $optn['page']['header_javascript'] = $this->header_javascript; |
||
| 191 | $optn['page']['body_load'] = $this->body_load; |
||
| 192 | $optn['page']['body_unload'] = $this->body_unload; |
||
| 193 | $optn['page']['sponsor'] = $opt['page']['sponsor']; |
||
| 194 | $optn['page']['showsocialmedia'] = $opt['page']['showsocialmedia']; |
||
| 195 | $optn['page']['main_country'] = $opt['page']['main_country']; |
||
| 196 | $optn['page']['main_locale'] = $opt['page']['main_locale']; |
||
| 197 | $optn['page']['meta'] = $opt['page']['meta']; |
||
| 198 | $optn['page']['teampic_url'] = $opt['page']['teampic_url']; |
||
| 199 | $optn['page']['teammember_url'] = $opt['page']['teammember_url']; |
||
| 200 | $optn['template']['title'] = $this->title; |
||
| 201 | $optn['template']['caching'] = $this->caching; |
||
| 202 | $optn['template']['popup'] = $this->popup; |
||
| 203 | $optn['template']['popupmargin'] = $this->popupmargin; |
||
| 204 | $optn['format'] = $opt['locale'][$opt['template']['locale']]['format']; |
||
| 205 | $optn['mail'] = $opt['mail']; |
||
| 206 | $optn['lib'] = $opt['lib']; |
||
| 207 | $optn['tracking'] = $opt['tracking']; |
||
| 208 | $optn['geokrety'] = $opt['geokrety']; |
||
| 209 | $optn['template']['usercountrieslist'] = labels::getLabels('usercountrieslist'); |
||
| 210 | $optn['help']['oconly'] = helppagelink('oconly', 'OConly'); |
||
| 211 | $optn['msie'] = $useragent_msie; |
||
| 212 | |||
| 213 | $loginn = [ |
||
| 214 | 'username' => '', |
||
| 215 | 'userid' => '', |
||
| 216 | 'admin' => '', |
||
| 217 | ]; |
||
| 218 | |||
| 219 | if (isset($login)) { |
||
| 220 | $loginn['username'] = $login->username; |
||
| 221 | $loginn['userid'] = $login->userid; |
||
| 222 | $loginn['admin'] = $login->admin; |
||
| 223 | } |
||
| 224 | |||
| 225 | // build menu |
||
| 226 | if ($this->menuitem == null) { |
||
| 227 | $menu->SetSelectItem(MNU_ROOT); |
||
| 228 | } else { |
||
| 229 | $menu->SetSelectItem($this->menuitem); |
||
| 230 | } |
||
| 231 | |||
| 232 | $this->assign('topmenu', $menu->getTopMenu()); |
||
| 233 | $this->assign('submenu', $menu->getSubMenu()); |
||
| 234 | $this->assign('breadcrumb', $menu->getBreadcrumb()); |
||
| 235 | $this->assign('menucolor', $menu->getMenuColor()); |
||
| 236 | $this->assign('helplink', helppagelink($this->name)); |
||
| 237 | $this->assign('change_country_inpage', $this->change_country_inpage); |
||
| 238 | |||
| 239 | if ($this->title == '') { |
||
| 240 | $optn['template']['title'] = $menu->GetMenuTitle(); |
||
| 241 | } |
||
| 242 | |||
| 243 | // build address for switching locales and countries |
||
| 244 | $base_pageadr = $_SERVER['REQUEST_URI']; |
||
| 245 | |||
| 246 | // workaround for http://redmine.opencaching.de/issues/703 |
||
| 247 | $strange_things_pos = strpos($base_pageadr, '.php/'); |
||
| 248 | if ($strange_things_pos) { |
||
| 249 | $base_pageadr = substr($base_pageadr, 0, $strange_things_pos + 4); |
||
| 250 | } |
||
| 251 | $lpos = strpos($base_pageadr, 'locale='); |
||
| 252 | if ($this->change_country_inpage) { |
||
| 253 | if (!$lpos) { |
||
| 254 | $lpos = strpos($base_pageadr, 'usercountry='); |
||
| 255 | } |
||
| 256 | if (!$lpos) { |
||
| 257 | $lpos = strpos($base_pageadr, 'country='); |
||
| 258 | } |
||
| 259 | } |
||
| 260 | if ($lpos) { |
||
| 261 | $base_pageadr = substr($base_pageadr, 0, $lpos); |
||
| 262 | } else { |
||
| 263 | $urx = explode('#', $base_pageadr); |
||
| 264 | $base_pageadr = $urx[0]; |
||
| 265 | if (strpos($base_pageadr, '?') == 0) { |
||
| 266 | $base_pageadr .= '?'; |
||
| 267 | } else { |
||
| 268 | $base_pageadr .= '&'; |
||
| 269 | } |
||
| 270 | } |
||
| 271 | $this->assign('base_pageadr', $base_pageadr); |
||
| 272 | |||
| 273 | if ($opt['logic']['license']['disclaimer']) { |
||
| 274 | View Code Duplication | if (isset($opt['locale'][$locale]['page']['license_url'])) { |
|
| 275 | $lurl = $opt['locale'][$locale]['page']['license_url']; |
||
| 276 | } else { |
||
| 277 | $lurl = $opt['locale']['EN']['page']['license_url']; |
||
| 278 | } |
||
| 279 | |||
| 280 | if (isset($opt['locale'][$locale]['page']['license'])) { |
||
| 281 | $ltext = mb_ereg_replace( |
||
| 282 | '{site}', |
||
| 283 | $opt['page']['sitename'], |
||
| 284 | $opt['locale'][$locale]['page']['license'] |
||
| 285 | ); |
||
| 286 | } else { |
||
| 287 | $ltext = $opt['locale']['EN']['page']['license']; |
||
| 288 | } |
||
| 289 | |||
| 290 | $this->assign('license_disclaimer', mb_ereg_replace('%1', $lurl, $ltext)); |
||
| 291 | } else { |
||
| 292 | $this->assign('license_disclaimer', ''); |
||
| 293 | } |
||
| 294 | |||
| 295 | $this->assign('opt', $optn); |
||
| 296 | $this->assign('login', $loginn); |
||
| 297 | |||
| 298 | if ($db['connected'] == true) { |
||
| 299 | $this->assign('sys_dbconnected', true); |
||
| 300 | } else { |
||
| 301 | $this->assign('sys_dbconnected', false); |
||
| 302 | } |
||
| 303 | $this->assign('sys_dbslave', ($db['slave_id'] != -1)); |
||
| 304 | |||
| 305 | if ($this->template_exists($this->name . '.tpl')) { |
||
| 306 | $this->assign('template', $this->name); |
||
| 307 | } elseif ($this->name != 'sys_error') { |
||
| 308 | $this->error(ERROR_TEMPLATE_NOT_FOUND); |
||
| 309 | } |
||
| 310 | |||
| 311 | $this->bench->stop(); |
||
| 312 | $this->assign('sys_runtime', $this->bench->diff()); |
||
| 313 | |||
| 314 | $this->assign( |
||
| 315 | 'screen_css_time', |
||
| 316 | filemtime(__DIR__ . '/../resource2/' . $opt['template']['style'] . '/css/style_screen.css') |
||
| 317 | ); |
||
| 318 | $this->assign( |
||
| 319 | 'screen_msie_css_time', |
||
| 320 | filemtime(__DIR__ . '/../resource2/' . $opt['template']['style'] . '/css/style_screen_msie.css') |
||
| 321 | ); |
||
| 322 | $this->assign( |
||
| 323 | 'print_css_time', |
||
| 324 | filemtime(__DIR__ . '/../resource2/' . $opt['template']['style'] . '/css/style_print.css') |
||
| 325 | ); |
||
| 326 | |||
| 327 | // check if the template is compiled |
||
| 328 | // if not, check if translation works correct |
||
| 329 | $_smarty_compile_path = $this->_get_compile_path($this->name); |
||
| 330 | if (!$this->_is_compiled($this->name, $_smarty_compile_path) && $this->name != 'error') { |
||
| 331 | $internal_lang = $translate->t('INTERNAL_LANG', 'all', 'OcSmarty.class.php', ''); |
||
| 332 | if (($internal_lang != $opt['template']['locale']) && ($internal_lang != 'INTERNAL_LANG')) { |
||
| 333 | $this->error(ERROR_COMPILATION_FAILED); |
||
| 334 | } |
||
| 335 | } |
||
| 336 | |||
| 337 | if ($this->is_cached() == true) { |
||
| 338 | $this->assign('sys_cached', true); |
||
| 339 | } else { |
||
| 340 | $this->assign('sys_cached', false); |
||
| 341 | } |
||
| 342 | |||
| 343 | if ($db['debug'] === true) { |
||
| 344 | parent::fetch($this->main_template . '.tpl', $this->get_cache_id(), $this->get_compile_id()); |
||
| 345 | |||
| 346 | $this->clear_all_assign(); |
||
| 347 | $this->main_template = 'sys_sqldebugger'; |
||
| 348 | $this->assign('commands', $sqldebugger->getCommands()); |
||
| 349 | $this->assign('cancel', $sqldebugger->getCancel()); |
||
| 350 | unset($sqldebugger); |
||
| 351 | |||
| 352 | $this->assign('opt', $optn); |
||
| 353 | $this->assign('login', $loginn); |
||
| 354 | |||
| 355 | $this->caching = 0; |
||
| 356 | |||
| 357 | // unset sqldebugger to allow proper translation of sqldebugger template |
||
| 358 | $opt['debug'] = $opt['debug'] & ~DEBUG_SQLDEBUGGER; |
||
| 359 | |||
| 360 | $this->header(); |
||
| 361 | parent::display($this->main_template . '.tpl'); |
||
| 362 | } else { |
||
| 363 | $this->header(); |
||
| 364 | parent::display($this->main_template . '.tpl', $this->get_cache_id(), $this->get_compile_id()); |
||
| 365 | } |
||
| 366 | |||
| 367 | exit; |
||
| 368 | } |
||
| 369 | |||
| 591 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.