Passed
Pull Request — develop (#92)
by Felipe
04:47
created

SqleditController::doFind()   F

Complexity

Conditions 22
Paths > 20000

Size

Total Lines 53
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 37
nc 1064960
nop 0
dl 0
loc 53
rs 3.3278
c 0
b 0
f 0

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
2
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
/*
4
 * PHPPgAdmin v6.0.0-beta.30
5
 */
6
7
namespace PHPPgAdmin\Controller;
8
9
/**
10
 * Base controller class.
11
 */
5 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
12
class SqleditController extends BaseController
13
{
14
    public $controller_name = 'SqleditController';
15
    public $query           = '';
16
    public $subject         = '';
17
    public $start_time;
18
    public $duration;
19
20
    /**
21
     * Default method to render the controller according to the action parameter.
22
     */
23
    public function render()
24
    {
25
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
26
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
27
28
        $action = $this->action;
29
        $data   = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
30
31
        switch ($action) {
32
            case 'find':
33
                $title     = $this->lang['strfind'];
34
                $body_text = $this->doFind();
35
36
                break;
37
            case 'sql':
38
            default:
39
                $title     = $this->lang['strsql'];
40
                $body_text = $this->doDefault();
41
42
                break;
43
        }
44
45
        $this->setWindowName('sqledit');
46
47
        $this->scripts = '<script type="text/javascript">window.inPopUp=true;</script>';
48
49
        $this->printHeader($title, $this->scripts, true, 'header_sqledit.twig');
50
        $this->printBody(true, 'sql_edit');
51
        echo $body_text;
52
53
        $this->printFooter(true, 'footer_sqledit.twig');
54
    }
55
56
    /**
57
     * Allow execution of arbitrary SQL statements on a database.
58
     */
59
    public function doDefault()
60
    {
61
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
62
63
        $lang = $this->lang;
64
        $data = $this->misc->getDatabaseAccessor();
65
66
        if (!isset($_SESSION['sqlquery'])) {
67
            $_SESSION['sqlquery'] = '';
68
        }
69
70
        if (!isset($_REQUEST['search_path'])) {
71
            $_REQUEST['search_path'] = implode(',', $data->getSearchPath());
72
        }
73
        $search_path = htmlspecialchars($_REQUEST['search_path']);
74
        $sqlquery    = htmlspecialchars($_SESSION['sqlquery']);
75
76
        $default_html = $this->printTabs($this->misc->getNavTabs('popup'), 'sql', false);
77
78
        $default_html .= '<form action="'.\SUBFOLDER.'/src/views/sql" method="post" enctype="multipart/form-data" class="sqlform" id="sqlform" target="detail">';
79
        $default_html .= "\n";
80
        $default_html .= $this->_printConnection('sql');
81
82
        $default_html .= "\n";
83
84
        $default_html .= ' <div class="searchpath">';
85
        $default_html .= '<label>';
86
        $default_html .= $this->misc->printHelp($lang['strsearchpath'], 'pg.schema.search_path', false);
87
88
        $default_html .= ': <input type="text" name="search_path" size="45" value="'.$search_path.'" />';
89
        $default_html .= "</label>\n";
90
91
        $default_html .= "</div>\n";
92
93
        $default_html .= '<div id="queryedition" style="padding:1%;width:98%;float:left;">';
94
        $default_html .= "\n";
95
        $default_html .= '<textarea style="width:98%;" rows="10" cols="50" name="query" id="query" resizable="true">'.$sqlquery.'</textarea>';
96
        $default_html .= "\n";
97
        $default_html .= "</div>\n";
98
99
        $default_html .= '<div class="sqledit_bottom_inputs" >';
100
101
        if (ini_get('file_uploads')) {
102
            // Don't show upload option if max size of uploads is zero
103
            $max_size = $this->misc->inisizeToBytes(ini_get('upload_max_filesize'));
104
            if (is_double($max_size) && $max_size > 0) {
105
                $default_html .= '<p class="upload_sql_script">';
106
                $default_html .= '<input type="hidden" name="MAX_FILE_SIZE" value="'.$max_size.'" />';
107
                $default_html .= "\n";
108
                $default_html .= '<label for="script">'.$lang['struploadscript'].'</label>';
109
                $default_html .= '&nbsp;&nbsp; <input class="btn btn-small"  id="script" name="script" type="file" /></p>';
110
                $default_html .= "</p>\n";
111
            }
112
        }
113
114
        // Check that file uploads are enabled
115
        $checked = (isset($_REQUEST['paginate']) ? ' checked="checked"' : '');
116
117
        $default_html .= '<p><input type="submit" class="btn btn-small" name="execute" accesskey="r" value="'.$lang['strexecute'].'" />';
118
        $default_html .= "\n";
119
120
        $default_html .= '<input type="reset" class="btn btn-small"  accesskey="q" value="'.$lang['strreset'].'" /></p>';
121
        $default_html .= "\n";
122
123
        $default_html .= '<p>';
124
        $default_html .= '<label for="paginate">';
125
        $default_html .= '<input type="checkbox" id="paginate" name="paginate"'.$checked.' />&nbsp;'.$lang['strpaginate'].'&nbsp;';
126
        $default_html .= "</label>\n";
127
        $default_html .= "</p>\n";
128
129
        $default_html .= "</div>\n";
130
        $default_html .= '</form>';
131
        $default_html .= "\n";
132
133
        // Default focus
134
        //$this->setFocus('forms[0].query');
135
        return $default_html;
136
    }
137
138
    /**
139
     * Private function to display server and list of databases.
140
     *
141
     * @param mixed $action
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
142
     */
143
    public function _printConnection($action)
1 ignored issue
show
Coding Style introduced by
Public method name "SqleditController::_printConnection" must not be prefixed with an underscore
Loading history...
144
    {
145
        $conf = $this->conf;
0 ignored issues
show
Unused Code introduced by
The assignment to $conf is dead and can be removed.
Loading history...
146
147
        $lang = $this->lang;
0 ignored issues
show
Unused Code introduced by
The assignment to $lang is dead and can be removed.
Loading history...
148
        $data = $this->misc->getDatabaseAccessor();
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
149
150
        // The javascript action on the select box reloads the
151
        // popup whenever the server or database is changed.
152
        // This ensures that the correct page encoding is used.
153
        $onchange = "onchange=\"location.href='".\SUBFOLDER.'/sqledit/'.
154
        urlencode($action)."?server=' + encodeURI(server.options[server.selectedIndex].value) + '&amp;database=' + encodeURI(database.options[database.selectedIndex].value) + ";
155
156
        // The exact URL to reload to is different between SQL and Find mode, however.
157
        if ('find' == $action) {
158
            $onchange .= "'&amp;term=' + encodeURI(term.value) + '&amp;filter=' + encodeURI(filter.value) + '&amp;'\"";
159
        } else {
160
            $onchange .= "'&amp;query=' + encodeURI(query.value) + '&amp;search_path=' + encodeURI(search_path.value) + (paginate.checked ? '&amp;paginate=on' : '')  + '&amp;'\"";
161
        }
162
163
        return $this->misc->printConnection($onchange, false);
164
    }
165
166
    /**
167
     * Searches for a named database object.
168
     */
169
    public function doFind()
170
    {
171
        $conf = $this->conf;
172
173
        $lang = $this->lang;
174
        $data = $this->misc->getDatabaseAccessor();
175
176
        if (!isset($_REQUEST['term'])) {
177
            $_REQUEST['term'] = '';
178
        }
179
180
        if (!isset($_REQUEST['filter'])) {
181
            $_REQUEST['filter'] = '';
182
        }
183
184
        $default_html = $this->printTabs($this->misc->getNavTabs('popup'), 'find', false);
185
186
        $default_html .= "<form action=\"database.php\" method=\"post\" target=\"detail\">\n";
187
        $default_html .= $this->_printConnection('find');
188
        $default_html .= '<p><input class="focusme" name="term" value="'.htmlspecialchars($_REQUEST['term'])."\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" />\n";
189
190
        // Output list of filters.  This is complex due to all the 'has' and 'conf' feature possibilities
191
        $default_html .= "<select name=\"filter\">\n";
192
        $default_html .= "\t<option value=\"\"".('' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strallobjects']}</option>\n";
193
        $default_html .= "\t<option value=\"SCHEMA\"".('SCHEMA' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strschemas']}</option>\n";
194
        $default_html .= "\t<option value=\"TABLE\"".('TABLE' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strtables']}</option>\n";
195
        $default_html .= "\t<option value=\"VIEW\"".('VIEW' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strviews']}</option>\n";
196
        $default_html .= "\t<option value=\"SEQUENCE\"".('SEQUENCE' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strsequences']}</option>\n";
197
        $default_html .= "\t<option value=\"COLUMN\"".('COLUMN' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strcolumns']}</option>\n";
198
        $default_html .= "\t<option value=\"RULE\"".('RULE' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strrules']}</option>\n";
199
        $default_html .= "\t<option value=\"INDEX\"".('INDEX' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strindexes']}</option>\n";
200
        $default_html .= "\t<option value=\"TRIGGER\"".('TRIGGER' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strtriggers']}</option>\n";
201
        $default_html .= "\t<option value=\"CONSTRAINT\"".('CONSTRAINT' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strconstraints']}</option>\n";
202
        $default_html .= "\t<option value=\"FUNCTION\"".('FUNCTION' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strfunctions']}</option>\n";
203
        $default_html .= "\t<option value=\"DOMAIN\"".('DOMAIN' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strdomains']}</option>\n";
204
        if ($conf['show_advanced']) {
205
            $default_html .= "\t<option value=\"AGGREGATE\"".('AGGREGATE' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['straggregates']}</option>\n";
206
            $default_html .= "\t<option value=\"TYPE\"".('TYPE' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strtypes']}</option>\n";
207
            $default_html .= "\t<option value=\"OPERATOR\"".('OPERATOR' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['stroperators']}</option>\n";
208
            $default_html .= "\t<option value=\"OPCLASS\"".('OPCLASS' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['stropclasses']}</option>\n";
209
            $default_html .= "\t<option value=\"CONVERSION\"".('CONVERSION' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strconversions']}</option>\n";
210
            $default_html .= "\t<option value=\"LANGUAGE\"".('LANGUAGE' == $_REQUEST['filter'] ? ' selected="selected" ' : '').">{$lang['strlanguages']}</option>\n";
211
        }
212
        $default_html .= "</select>\n";
213
214
        $default_html .= "<input type=\"submit\" value=\"{$lang['strfind']}\" />\n";
215
        $default_html .= "<input type=\"hidden\" name=\"action\" value=\"find\" /></p>\n";
216
        $default_html .= "</form>\n";
217
218
        // Default focus
219
        $this->setFocus('forms[0].term');
220
221
        return $default_html;
222
    }
223
}
224