Completed
Push — master ( 53ea58...16270d )
by Michael
04:51
created

search.php ➔ publisher_search_show()   F

Complexity

Conditions 36
Paths > 20000

Size

Total Lines 141
Code Lines 100

Duplication

Lines 13
Ratio 9.22 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
cc 36
eloc 100
c 4
b 0
f 0
nc 3538945
nop 1
dl 13
loc 141
rs 2

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 24.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
14
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @package         Publisher
16
 * @subpackage      Blocks
17
 * @since           1.0
18
 * @author          trabis <[email protected]>
19
 * @author          phppp
20
 */
21
22
// defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
24
include_once dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * @param $options
28
 *
29
 * @return array
30
 */
31
function publisher_search_show($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
{
33
    $block      = array();
34
    $publisher  = PublisherPublisher::getInstance();
35
    $categories = $publisher->getHandler('category')->getCategoriesForSearch();
36
    if (count($categories) == 0) {
37
        return $block;
38
    }
39
40
    xoops_loadLanguage('search');
41
42
    $andor    = XoopsRequest::getString('andor', XoopsRequest::getString('andor', '', 'GET'), 'POST');
43
    $username = XoopsRequest::getString('uname', XoopsRequest::getString('uname', null, 'GET'), 'POST');
44
    //  $searchin = isset($_POST["searchin"]) ? $_POST["searchin"] : (isset($_GET["searchin"]) ? explode("|", $_GET["searchin"]) : array());
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
    //  $searchin = XoopsRequest::getArray('searchin', (explode("|", XoopsRequest::getString('searchin', array(), 'GET'))), 'POST');
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
47
    $searchin = XoopsRequest::getArray('searchin', '', 'POST');
48
    if (!isset($searchin)) {
49
        $searchin = XoopsRequest::getString('searchin', array(), 'GET');
50
        $searchin = isset($searchin) ? explode('|', $searchin) : array();
51
    }
52
53
    $sortby = XoopsRequest::getString('sortby', XoopsRequest::getString('sortby', null, 'GET'), 'POST');
54
    $term   = XoopsRequest::getString('term', XoopsRequest::getString('term', '', 'GET'));
55
56
    //mb TODO simplify next lines with category
57
    $category = XoopsRequest::getArray('category', array(), 'POST') ?: XoopsRequest::getArray('category', null, 'GET');
58 View Code Duplication
    if (empty($category) || (is_array($category) && in_array('all', $category))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
        $category = array();
60
    } else {
61
        $category = (!is_array($category)) ? explode(',', $category) : $category;
62
        $category = array_map('intval', $category);
63
    }
64
65
    $andor  = in_array(strtoupper($andor), array('OR', 'AND', 'EXACT')) ? strtoupper($andor) : 'OR';
66
    $sortby = in_array(strtolower($sortby), array('itemid', 'datesub', 'title', 'categoryid')) ? strtolower($sortby) : 'itemid';
67
68
    /* type */
69
    $typeSelect = "<select name=\"andor\">";
70
    $typeSelect .= "<option value=\"OR\"";
71
    if ('OR' === $andor) {
72
        $typeSelect .= " selected=\"selected\"";
73
    }
74
    $typeSelect .= '>' . _SR_ANY . '</option>';
75
    $typeSelect .= "<option value=\"AND\"";
76
    if ('AND' === $andor) {
77
        $typeSelect .= " selected=\"selected\"";
78
    }
79
    $typeSelect .= '>' . _SR_ALL . '</option>';
80
    $typeSelect .= "<option value=\"EXACT\"";
81
    if ('exact' === $andor) {
82
        $typeSelect .= " selected=\"selected\"";
83
    }
84
    $typeSelect .= '>' . _SR_EXACT . '</option>';
85
    $typeSelect .= '</select>';
86
87
    /* category */
88
89
    $categorySelect = "<select name=\"category[]\" size=\"5\" multiple=\"multiple\" width=\"150\" style=\"width:150px;\">";
90
    $categorySelect .= "<option value=\"all\"";
91
    if (empty($category) || count($category) == 0) {
92
        $categorySelect .= "selected=\"selected\"";
93
    }
94
    $categorySelect .= '>' . _ALL . '</option>';
95 View Code Duplication
    foreach ($categories as $id => $cat) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
        $categorySelect .= "<option value=\"" . $id . "\"";
97
        if (in_array($id, $category)) {
98
            $categorySelect .= "selected=\"selected\"";
99
        }
100
        $categorySelect .= '>' . $cat . '</option>';
101
    }
102
    unset($id, $cat);
103
    $categorySelect .= '</select>';
104
105
    /* scope */
106
    $searchSelect = '';
107
    $searchSelect .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"title\"";
108
    if (is_array($searchin) && in_array('title', $searchin)) {
109
        $searchSelect .= ' checked';
110
    }
111
    $searchSelect .= ' />' . _CO_PUBLISHER_TITLE . '&nbsp;&nbsp;';
112
    $searchSelect .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"subtitle\"";
113
    if (is_array($searchin) && in_array('subtitle', $searchin)) {
114
        $searchSelect .= ' checked';
115
    }
116
    $searchSelect .= ' />' . _CO_PUBLISHER_SUBTITLE . '&nbsp;&nbsp;';
117
    $searchSelect .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"summary\"";
118
    if (is_array($searchin) && in_array('summary', $searchin)) {
119
        $searchSelect .= ' checked';
120
    }
121
    $searchSelect .= ' />' . _CO_PUBLISHER_SUMMARY . '&nbsp;&nbsp;';
122
    $searchSelect .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"text\"";
123
    if (is_array($searchin) && in_array('body', $searchin)) {
124
        $searchSelect .= ' checked';
125
    }
126
    $searchSelect .= ' />' . _CO_PUBLISHER_BODY . '&nbsp;&nbsp;';
127
    $searchSelect .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"keywords\"";
128
    if (is_array($searchin) && in_array('meta_keywords', $searchin)) {
129
        $searchSelect .= ' checked';
130
    }
131
    $searchSelect .= ' />' . _CO_PUBLISHER_ITEM_META_KEYWORDS . '&nbsp;&nbsp;';
132
    $searchSelect .= "<input type=\"checkbox\" name=\"searchin[]\" value=\"all\"";
133
    if (empty($searchin) || (is_array($searchin) && in_array('all', $searchin))) {
134
        $searchSelect .= ' checked';
135
    }
136
    $searchSelect .= ' />' . _ALL . '&nbsp;&nbsp;';
137
138
    /* sortby */
139
    $sortbySelect = "<select name=\"sortby\">";
140
    $sortbySelect .= "<option value=\"itemid\"";
141
    if ('itemid' === $sortby || empty($sortby)) {
142
        $sortbySelect .= " selected=\"selected\"";
143
    }
144
    $sortbySelect .= '>' . _NONE . '</option>';
145
    $sortbySelect .= "<option value=\"datesub\"";
146
    if ('datesub' === $sortby) {
147
        $sortbySelect .= " selected=\"selected\"";
148
    }
149
    $sortbySelect .= '>' . _CO_PUBLISHER_DATESUB . '</option>';
150
    $sortbySelect .= "<option value=\"title\"";
151
    if ('title' === $sortby) {
152
        $sortbySelect .= " selected=\"selected\"";
153
    }
154
    $sortbySelect .= '>' . _CO_PUBLISHER_TITLE . '</option>';
155
    $sortbySelect .= "<option value=\"categoryid\"";
156
    if ('categoryid' === $sortby) {
157
        $sortbySelect .= " selected=\"selected\"";
158
    }
159
    $sortbySelect .= '>' . _CO_PUBLISHER_CATEGORY . '</option>';
160
    $sortbySelect .= '</select>';
161
162
    $block['typeSelect']     = $typeSelect;
163
    $block['searchSelect']   = $searchSelect;
164
    $block['categorySelect'] = $categorySelect;
165
    $block['sortbySelect']   = $sortbySelect;
166
    $block['search_term']    = $term;
167
    $block['search_user']    = $username;
168
    $block['moduleUrl']      = PUBLISHER_URL;
169
170
    return $block;
171
}
172