| Conditions | 6 |
| Paths | 18 |
| Total Lines | 147 |
| Code Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 68 | public function doDefault($msg = '', $isTable = true) |
||
| 69 | { |
||
| 70 | $data = $this->misc->getDatabaseAccessor(); |
||
| 71 | |||
| 72 | $attPre = function (&$rowdata) use ($data) { |
||
| 73 | $rowdata->fields['+type'] = $data->formatType($rowdata->fields['type'], $rowdata->fields['atttypmod']); |
||
| 74 | }; |
||
| 75 | |||
| 76 | if (empty($_REQUEST['column'])) { |
||
| 77 | $msg .= "<br/>{$this->lang['strnoobjects']}"; |
||
| 78 | } |
||
| 79 | |||
| 80 | $this->printTrail('column'); |
||
| 81 | //$this->printTitle($this->lang['strcolprop']); |
||
| 82 | $this->printTabs('column', 'properties'); |
||
| 83 | $this->printMsg($msg); |
||
| 84 | |||
| 85 | if (!empty($_REQUEST['column'])) { |
||
| 86 | // Get table |
||
| 87 | $tdata = $data->getTable($this->tableName); |
||
| 88 | // Get columns |
||
| 89 | $attrs = $data->getTableAttributes($this->tableName, $_REQUEST['column']); |
||
| 90 | |||
| 91 | // Show comment if any |
||
| 92 | if (null !== $attrs->fields['comment']) { |
||
| 93 | echo '<p class="comment">', $this->misc->printVal($attrs->fields['comment']), "</p>\n"; |
||
| 94 | } |
||
| 95 | |||
| 96 | $column = [ |
||
| 97 | 'column' => [ |
||
| 98 | 'title' => $this->lang['strcolumn'], |
||
| 99 | 'field' => Decorator::field('attname'), |
||
| 100 | ], |
||
| 101 | 'type' => [ |
||
| 102 | 'title' => $this->lang['strtype'], |
||
| 103 | 'field' => Decorator::field('+type'), |
||
| 104 | ], |
||
| 105 | ]; |
||
| 106 | |||
| 107 | if ($isTable) { |
||
| 108 | $column['notnull'] = [ |
||
| 109 | 'title' => $this->lang['strnotnull'], |
||
| 110 | 'field' => Decorator::field('attnotnull'), |
||
| 111 | 'type' => 'bool', |
||
| 112 | 'params' => ['true' => 'NOT NULL', 'false' => ''], |
||
| 113 | ]; |
||
| 114 | $column['default'] = [ |
||
| 115 | 'title' => $this->lang['strdefault'], |
||
| 116 | 'field' => Decorator::field('adsrc'), |
||
| 117 | ]; |
||
| 118 | } |
||
| 119 | |||
| 120 | $actions = []; |
||
| 121 | echo $this->printTable($attrs, $column, $actions, $this->table_place, null, $attPre); |
||
| 122 | |||
| 123 | echo "<br />\n"; |
||
| 124 | |||
| 125 | $f_attname = $_REQUEST['column']; |
||
| 126 | $f_table = $this->tableName; |
||
| 127 | $f_schema = $data->_schema; |
||
| 128 | $data->fieldClean($f_attname); |
||
| 129 | $data->fieldClean($f_table); |
||
| 130 | $data->fieldClean($f_schema); |
||
| 131 | $query = "SELECT \"{$f_attname}\", count(*) AS \"count\" FROM \"{$f_schema}\".\"{$f_table}\" GROUP BY \"{$f_attname}\" ORDER BY \"{$f_attname}\""; |
||
| 132 | |||
| 133 | if ($isTable) { |
||
| 134 | // Browse link |
||
| 135 | /* FIXME browsing a col should somehow be a action so we don't |
||
| 136 | * send an ugly SQL in the URL */ |
||
| 137 | |||
| 138 | $navlinks = [ |
||
| 139 | 'browse' => [ |
||
| 140 | 'attr' => [ |
||
| 141 | 'href' => [ |
||
| 142 | 'url' => 'display', |
||
| 143 | 'urlvars' => [ |
||
| 144 | 'subject' => 'column', |
||
| 145 | 'server' => $_REQUEST['server'], |
||
| 146 | 'database' => $_REQUEST['database'], |
||
| 147 | 'schema' => $_REQUEST['schema'], |
||
| 148 | 'table' => $this->tableName, |
||
| 149 | 'column' => $_REQUEST['column'], |
||
| 150 | 'return' => 'column', |
||
| 151 | 'query' => $query, |
||
| 152 | ], |
||
| 153 | ], |
||
| 154 | ], |
||
| 155 | 'content' => $this->lang['strbrowse'], |
||
| 156 | ], |
||
| 157 | 'alter' => [ |
||
| 158 | 'attr' => [ |
||
| 159 | 'href' => [ |
||
| 160 | 'url' => 'colproperties', |
||
| 161 | 'urlvars' => [ |
||
| 162 | 'action' => 'properties', |
||
| 163 | 'server' => $_REQUEST['server'], |
||
| 164 | 'database' => $_REQUEST['database'], |
||
| 165 | 'schema' => $_REQUEST['schema'], |
||
| 166 | 'table' => $this->tableName, |
||
| 167 | 'column' => $_REQUEST['column'], |
||
| 168 | ], |
||
| 169 | ], |
||
| 170 | ], |
||
| 171 | 'content' => $this->lang['stralter'], |
||
| 172 | ], |
||
| 173 | 'drop' => [ |
||
| 174 | 'attr' => [ |
||
| 175 | 'href' => [ |
||
| 176 | 'url' => 'tblproperties', |
||
| 177 | 'urlvars' => [ |
||
| 178 | 'action' => 'confirm_drop', |
||
| 179 | 'server' => $_REQUEST['server'], |
||
| 180 | 'database' => $_REQUEST['database'], |
||
| 181 | 'schema' => $_REQUEST['schema'], |
||
| 182 | 'table' => $this->tableName, |
||
| 183 | 'column' => $_REQUEST['column'], |
||
| 184 | ], |
||
| 185 | ], |
||
| 186 | ], |
||
| 187 | 'content' => $this->lang['strdrop'], |
||
| 188 | ], |
||
| 189 | ]; |
||
| 190 | } else { |
||
| 191 | // Browse link |
||
| 192 | $navlinks = [ |
||
| 193 | 'browse' => [ |
||
| 194 | 'attr' => [ |
||
| 195 | 'href' => [ |
||
| 196 | 'url' => 'display', |
||
| 197 | 'urlvars' => [ |
||
| 198 | 'subject' => 'column', |
||
| 199 | 'server' => $_REQUEST['server'], |
||
| 200 | 'database' => $_REQUEST['database'], |
||
| 201 | 'schema' => $_REQUEST['schema'], |
||
| 202 | 'view' => $this->tableName, |
||
| 203 | 'column' => $_REQUEST['column'], |
||
| 204 | 'return' => 'column', |
||
| 205 | 'query' => $query, |
||
| 206 | ], |
||
| 207 | ], |
||
| 208 | ], |
||
| 209 | 'content' => $this->lang['strbrowse'], |
||
| 210 | ], |
||
| 211 | ]; |
||
| 212 | } |
||
| 213 | |||
| 214 | $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
||
| 215 | } |
||
| 401 |