File search.php
has 265 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
// $Id: search.php 12313 2013-09-15 21:14:35Z skenow $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
Avoid deeply nested control flow statements. Open
if (!empty($results[$i]['uid'])) {
$uname = icms_member_user_Object::getUnameFromId($results[$i]['uid']);
$results[$i]['processed_user_name'] = $uname;
$results[$i]['processed_user_url'] = ICMS_URL . "/userinfo.php?uid=" . $results[$i]['uid'];
}
Avoid deeply nested control flow statements. Open
if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
$results[$i]['link'] = "modules/" . $moddir . "/" . $results[$i]['link'];
}
Reference to undeclared constant \_SR_SHOWING
Open
$xoopsTpl->assign("showing", sprintf(_SR_SHOWING, 1, $max_results_per_page));
- Exclude checks
Suspicious type null
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$results[$i]['processed_image_url'] = "modules/" . $moddir . "/" . $results[$i]['image'];
- Exclude checks
Argument 1 (time)
is int
but \formatTimestamp()
takes string
defined at /code/htdocs/include/functions.php:1428
Open
$results[$i]['processed_time'] = !empty($results[$i]['time']) ? " (" . formatTimestamp( (int) $results[$i]['time']) . ")" : "";
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
$search_limiter = (($icmsConfigSearch['enable_deep_search'] == FALSE) ? $icmsConfigSearch['num_shallow_search'] : FALSE);
- Exclude checks
Reference to undeclared constant \_SR_PLZENTER
Open
redirect_header("search.php", 1, _SR_PLZENTER);
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign('basic_search', FALSE);
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if ($icmsConfigSearch['search_user_date']) {
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("label_search_type", _SR_TYPE . ':');
- Exclude checks
Reference to undeclared constant \_SR_KEYTOOSHORT
Open
redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, icms_conv_nr2local($icmsConfigSearch['keyword_min'])));
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("ignored_keywords", $ignored_keywords);
- Exclude checks
Reference to undeclared constant \_CHARSET
Open
$xoopsTpl->assign('icms_pagetitle', _SR_SEARCHRESULTS . ' - ' . htmlspecialchars(implode(' ',$keywords), ENT_COMPAT, _CHARSET));
- Exclude checks
Call to method __construct
from undeclared class \icms_db_criteria_Item
Open
$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('hassearch', 1));
- Exclude checks
Call to method checkVar
from undeclared class \icms_core_DataFilter
Open
$results[$i]['processed_image_alt_text'] = icms_core_DataFilter::checkVar($modname, 'text', 'output') . ": ";
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign('basic_search', TRUE);
- Exclude checks
Reference to undeclared constant \_SR_KEYTOOSHORT
Open
redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, icms_conv_nr2local($icmsConfigSearch['keyword_min'])));
- Exclude checks
Reference to static property user
from undeclared class \icms
Open
$groups = is_object(icms::$user) ? icms::$user->getGroups() : XOOPS_GROUP_ANONYMOUS;
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if (strlen($q) >= $icmsConfigSearch['keyword_min']) {
- Exclude checks
Reference to undeclared constant \_CHARSET
Open
$ignored_keywords[] = htmlspecialchars(stripslashes($q), ENT_COMPAT, _CHARSET);
- Exclude checks
Reference to undeclared constant \_SR_SEARCHRESULTS
Open
$xoopsTpl->assign('icms_pagetitle', _SR_SEARCHRESULTS . ' - ' . htmlspecialchars(implode(' ',$keywords), ENT_COMPAT, _CHARSET));
- Exclude checks
Invalid offset "time"
of array type array{link:string}|array{processed_image_alt_text:string}|array{processed_image_url:'images/icons/posticon2.gif'}|array{processed_image_url:string}|array{processed_title:}|array{processed_user_name:}|array{processed_user_url:string}|array{uid:int}
Open
$results[$i]['processed_time'] = !empty($results[$i]['time']) ? " (" . formatTimestamp( (int) $results[$i]['time']) . ")" : "";
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if ($icmsConfigSearch['enable_deep_search'] == FALSE) {
- Exclude checks
Call to method checkVar
from undeclared class \icms_core_DataFilter
Open
$results[$i]['processed_image_alt_text'] = icms_core_DataFilter::checkVar($modname, 'text', 'output') . ": ";
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if ($icmsConfigSearch['search_user_date']) {
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("module_sort_order", $all_results_counts);
- Exclude checks
Reference to undeclared constant \_SR_TYPE
Open
$xoopsTpl->assign("label_search_type", _SR_TYPE . ':');
- Exclude checks
Reference to undeclared constant \_SR_ALL
Open
if ($andor == 'AND') $label_andor = _SR_ALL;
- Exclude checks
Call to method addSlashes
from undeclared class \icms_core_DataFilter
Open
$queries = array(icms_core_DataFilter::addSlashes($query));
- Exclude checks
Reference to undeclared constant \_SR_SEARCHRESULTS
Open
$xoopsTpl->assign("label_search_results", _SR_SEARCHRESULTS);
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("label_keywords", _SR_KEYWORDS . ':');
- Exclude checks
Call to method __construct
from undeclared class \icms_db_criteria_Item
Open
$criteria->add(new icms_db_criteria_Item('isactive', 1));
- Exclude checks
Invalid offset "link"
of array type array{processed_image_alt_text:string}|array{processed_image_url:'images/icons/posticon2.gif'}|array{processed_image_url:string}
Open
if (isset ($results[$i]['link']) && $results[$i]['link'] != '') {
- Exclude checks
Invalid offset "title"
of array type array{link:string}|array{processed_image_alt_text:string}|array{processed_image_url:'images/icons/posticon2.gif'}|array{processed_image_url:string}
Open
$results[$i]['processed_title'] = icms_core_DataFilter::checkVar($results[$i]['title'], 'text', 'output');
- Exclude checks
Suspicious type null
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$results[$i]['link'] = "modules/" . $moddir . "/" . $results[$i]['link'];
- Exclude checks
Invalid offset "uid"
of array type array{link:string}|array{processed_image_alt_text:string}|array{processed_image_url:'images/icons/posticon2.gif'}|array{processed_image_url:string}|array{processed_title:}|null
Open
$results[$i]['uid'] = @ (int) $results[$i]['uid'];
- Exclude checks
Call to method getUnameFromId
from undeclared class \icms_member_user_Object
Open
$uname = icms_member_user_Object::getUnameFromId($results[$i]['uid']);
- Exclude checks
Call to method handler
from undeclared class \icms
Open
$gperm_handler = icms::handler('icms_member_groupperm');
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign('search_form', $search_form);
- Exclude checks
Reference to undeclared constant \_SR_EXACT
Open
if ($andor == 'exact') $label_andor = _SR_EXACT;
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("label_search_results", _SR_SEARCHRESULTS);
- Exclude checks
Reference to undeclared constant \_CHARSET
Open
"search_more_url" => htmlspecialchars($search_url, ENT_COMPAT, _CHARSET),
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("search_results", $all_results);
- Exclude checks
Reference to undeclared constant \_SR_PLZENTER
Open
redirect_header("search.php", 1, _SR_PLZENTER);
- Exclude checks
Reference to undeclared constant \_SEARCH
Open
$xoopsTpl->assign('icms_pagetitle', _SEARCH);
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("search_type", $label_andor);
- Exclude checks
Call to method addSlashes
from undeclared class \icms_core_DataFilter
Open
$ignored_queries[] = icms_core_DataFilter::addSlashes($q);
- Exclude checks
Reference to undeclared constant \_SR_KEYWORDS
Open
$xoopsTpl->assign("label_keywords", _SR_KEYWORDS . ':');
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("searched_keywords", $keywords);
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign('icms_pagetitle', _SR_SEARCHRESULTS . ' - ' . htmlspecialchars(implode(' ',$keywords), ENT_COMPAT, _CHARSET));
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("showing", sprintf(_SR_SHOWING, 1, $max_results_per_page));
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
$max_results_per_page = (int) $icmsConfigSearch['search_per_page'];
- Exclude checks
Call to method handler
from undeclared class \icms
Open
$module_handler = icms::handler('icms_module');
- Exclude checks
Reference to undeclared constant \_SR_SHOWALLR
Open
$all_results[$modname] = array("search_more_title" => _SR_SHOWALLR,
- Exclude checks
Reference to undeclared constant \_SR_NOMATCH
Open
echo '<p>' . _SR_NOMATCH . '</p>';
- Exclude checks
Call to method handler
from undeclared class \icms
Open
$module_handler = icms::handler('icms_module');
- Exclude checks
Call to method __construct
from undeclared class \icms_db_criteria_Compo
Open
$criteria = new icms_db_criteria_Compo(new icms_db_criteria_Item('hassearch', 1));
- Exclude checks
Argument 2 (subject)
is null
but \preg_match()
takes string
Open
if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
- Exclude checks
Invalid offset "link"
of array type array{processed_image_alt_text:string}|array{processed_image_url:'images/icons/posticon2.gif'}|array{processed_image_url:string}
Open
$results[$i]['link'] = "modules/" . $moddir . "/" . $results[$i]['link'];
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign('search_form', $search_form);
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign('icms_pagetitle', _SEARCH);
- Exclude checks
Call to method addSlashes
from undeclared class \icms_core_DataFilter
Open
$queries[] = icms_core_DataFilter::addSlashes($q);
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("label_ignored_keywords", sprintf(_SR_IGNOREDWORDS, $icmsConfigSearch['keyword_min']));
- Exclude checks
Call to method add
from undeclared class \icms_db_criteria_Compo
Open
$criteria->add(new icms_db_criteria_Item('mid', "(" . implode(',', $available_modules) . ")", 'IN'));
- Exclude checks
Invalid offset "link"
of array type array{processed_image_alt_text:string}|array{processed_image_url:'images/icons/posticon2.gif'}|array{processed_image_url:string}
Open
if (!preg_match("/^http[s]*:\/\//i", $results[$i]['link'])) {
- Exclude checks
Call to method getUnameFromId
from undeclared class \icms_member_user_Object
Open
$uname = icms_member_user_Object::getUnameFromId($results[$i]['uid']);
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if (strlen($query) < $icmsConfigSearch['keyword_min']) {
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
$xoopsTpl->assign("label_ignored_keywords", sprintf(_SR_IGNOREDWORDS, $icmsConfigSearch['keyword_min']));
- Exclude checks
Call to method __construct
from undeclared class \icms_db_criteria_Item
Open
$criteria->add(new icms_db_criteria_Item('mid', "(" . implode(',', $available_modules) . ")", 'IN'));
- Exclude checks
Invalid offset "image"
of array type array{processed_image_alt_text:string}
Open
if (isset($results[$i]['image']) && $results[$i]['image'] != "") {
- Exclude checks
Argument 1 (time)
is int
but \formatTimestamp()
takes string
defined at /code/htdocs/include/functions.php:1428
Open
$results[$i]['processed_time'] = !empty($results[$i]['time']) ? " (". formatTimestamp((int) $results[$i]['time']) . ")" : "";
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if ($icmsConfigSearch['enable_search'] == FALSE) {
- Exclude checks
Reference to undeclared constant \_SR_PLZENTER
Open
redirect_header("search.php", 1, _SR_PLZENTER);
- Exclude checks
Reference to undeclared constant \_SR_IGNOREDWORDS
Open
$xoopsTpl->assign("label_ignored_keywords", sprintf(_SR_IGNOREDWORDS, $icmsConfigSearch['keyword_min']));
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
$max_results_per_page = (int) ($icmsConfigSearch['num_shallow_search']);
- Exclude checks
Call to method checkVar
from undeclared class \icms_core_DataFilter
Open
$results[$i]['processed_title'] = icms_core_DataFilter::checkVar($results[$i]['title'], 'text', 'output');
- Exclude checks
Variable $xoopsTpl
is undeclared Open
$xoopsTpl->assign("start", $start + 1);
- Exclude checks
Call to method renderNav
from undeclared class \icms_view_PageNav
Open
"page_nav" => $pagenav->renderNav());
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, icms_conv_nr2local($icmsConfigSearch['keyword_min'])));
- Exclude checks
Reference to undeclared constant \_CHARSET
Open
$keywords[] = htmlspecialchars(stripslashes($q), ENT_COMPAT, _CHARSET);
- Exclude checks
Call to method add
from undeclared class \icms_db_criteria_Compo
Open
$criteria->add(new icms_db_criteria_Item('isactive', 1));
- Exclude checks
Invalid offset "image"
of array type array{processed_image_alt_text:string}
Open
$results[$i]['processed_image_url'] = "modules/" . $moddir . "/" . $results[$i]['image'];
- Exclude checks
Call to method checkVar
from undeclared class \icms_core_DataFilter
Open
$results[$i]['processed_title'] = icms_core_DataFilter::checkVar($results[$i]['title'], 'text', 'output');
- Exclude checks
Call to method __construct
from undeclared class \icms_view_PageNav
Open
$pagenav = new icms_view_PageNav($count, $max_results_per_page, $start, "start", $search_url_get_params);
- Exclude checks
Reference to undeclared constant \_SR_ANY
Open
if ($andor == 'OR') $label_andor = _SR_ANY;
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
redirect_header('search.php', 2, sprintf(_SR_KEYTOOSHORT, icms_conv_nr2local($icmsConfigSearch['keyword_min'])));
- Exclude checks
Variable $icmsConfigSearch
is undeclared Open
if ($icmsConfigSearch['search_no_res_mod']) {
- Exclude checks
Reference to undeclared constant \_CHARSET
Open
$search_url_get_params = htmlspecialchars($search_url_get_params, ENT_COMPAT, _CHARSET);
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ($icmsConfigSearch['search_user_date']) {
$results[$i]['uid'] = @ (int) $results[$i]['uid'];
if (!empty($results[$i]['uid'])) {
$uname = icms_member_user_Object::getUnameFromId($results[$i]['uid']);
$results[$i]['processed_user_name'] = $uname;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 182.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
if ($icmsConfigSearch['search_user_date']) {
$results[$i]['uid'] = @ (int) $results[$i]['uid'];
if (!empty($results[$i]['uid'])) {
$uname = icms_member_user_Object::getUnameFromId($results[$i]['uid']);
$results[$i]['processed_user_name'] = $uname;
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 182.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
$search_limiter = (($icmsConfigSearch['enable_deep_search'] == FALSE) ? $icmsConfigSearch['num_shallow_search'] : FALSE);
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
if ($icmsConfigSearch['enable_search'] == FALSE) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
$xoopsTpl->assign('basic_search', FALSE);
- Exclude checks
Expected 1 space before "=>"; 0 found Open
foreach ($simples as $k=>$v) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
if ($icmsConfigSearch['enable_deep_search'] == FALSE) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
$xoopsTpl->assign('basic_search', TRUE);
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "FALSE" Open
$search_limiter = (($icmsConfigSearch['enable_deep_search'] == FALSE) ? $icmsConfigSearch['num_shallow_search'] : FALSE);
- Exclude checks
Expected 1 space after "=>"; 0 found Open
foreach ($simples as $k=>$v) {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "TRUE" Open
$modules =& $module_handler->getObjects($criteria, TRUE);
- Exclude checks
Inline control structures are not allowed Open
if ($andor == 'AND') $label_andor = _SR_ALL;
- Exclude checks
Inline control structures are not allowed Open
if ($andor == 'exact') $label_andor = _SR_EXACT;
- Exclude checks
Inline control structures are not allowed Open
if ($andor == 'OR') $label_andor = _SR_ANY;
- Exclude checks
No space found after comma in function call Open
$xoopsTpl->assign('icms_pagetitle', _SR_SEARCHRESULTS . ' - ' . htmlspecialchars(implode(' ',$keywords), ENT_COMPAT, _CHARSET));
- Exclude checks
Space before opening parenthesis of function call prohibited Open
if (isset ($results[$i]['link']) && $results[$i]['link'] != '') {
- Exclude checks
Space after opening parenthesis of function call prohibited Open
$results[$i]['processed_time'] = !empty($results[$i]['time']) ? " (" . formatTimestamp( (int) $results[$i]['time']) . ")" : "";
- Exclude checks