Total Complexity | 42 |
Total Lines | 556 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AggregatesController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AggregatesController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class AggregatesController extends BaseController |
||
15 | { |
||
16 | public $controller_name = 'AggregatesController'; |
||
17 | |||
18 | /** |
||
19 | * Default method to render the controller according to the action parameter. |
||
20 | */ |
||
21 | public function render() |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Show default list of aggregate functions in the database. |
||
87 | * |
||
88 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
89 | */ |
||
90 | public function doDefault($msg = '') |
||
91 | { |
||
92 | $conf = $this->conf; |
||
93 | |||
94 | $lang = $this->lang; |
||
95 | $data = $this->misc->getDatabaseAccessor(); |
||
96 | $this->printTrail('schema'); |
||
97 | $this->printTabs('schema', 'aggregates'); |
||
98 | $this->printMsg($msg); |
||
99 | |||
100 | $aggregates = $data->getAggregates(); |
||
101 | |||
102 | $columns = [ |
||
103 | 'aggrname' => [ |
||
104 | 'title' => $lang['strname'], |
||
105 | 'field' => Decorator::field('proname'), |
||
106 | 'url' => \SUBFOLDER."/redirect/aggregate?action=properties&{$this->misc->href}&", |
||
107 | 'vars' => ['aggrname' => 'proname', 'aggrtype' => 'proargtypes'], |
||
108 | ], |
||
109 | 'aggrtype' => [ |
||
110 | 'title' => $lang['strtype'], |
||
111 | 'field' => Decorator::field('proargtypes'), |
||
112 | ], |
||
113 | 'aggrtransfn' => [ |
||
114 | 'title' => $lang['straggrsfunc'], |
||
115 | 'field' => Decorator::field('aggtransfn'), |
||
116 | ], |
||
117 | 'owner' => [ |
||
118 | 'title' => $lang['strowner'], |
||
119 | 'field' => Decorator::field('usename'), |
||
120 | ], |
||
121 | 'actions' => [ |
||
122 | 'title' => $lang['stractions'], |
||
123 | ], |
||
124 | 'comment' => [ |
||
125 | 'title' => $lang['strcomment'], |
||
126 | 'field' => Decorator::field('aggrcomment'), |
||
127 | ], |
||
128 | ]; |
||
129 | |||
130 | $actions = [ |
||
131 | 'alter' => [ |
||
132 | 'content' => $lang['stralter'], |
||
133 | 'attr' => [ |
||
134 | 'href' => [ |
||
135 | 'url' => 'aggregates.php', |
||
136 | 'urlvars' => [ |
||
137 | 'action' => 'alter', |
||
138 | 'aggrname' => Decorator::field('proname'), |
||
139 | 'aggrtype' => Decorator::field('proargtypes'), |
||
140 | ], |
||
141 | ], |
||
142 | ], |
||
143 | ], |
||
144 | 'drop' => [ |
||
145 | 'content' => $lang['strdrop'], |
||
146 | 'attr' => [ |
||
147 | 'href' => [ |
||
148 | 'url' => 'aggregates.php', |
||
149 | 'urlvars' => [ |
||
150 | 'action' => 'confirm_drop', |
||
151 | 'aggrname' => Decorator::field('proname'), |
||
152 | 'aggrtype' => Decorator::field('proargtypes'), |
||
153 | ], |
||
154 | ], |
||
155 | ], |
||
156 | ], |
||
157 | ]; |
||
158 | |||
159 | if (!$data->hasAlterAggregate()) { |
||
160 | unset($actions['alter']); |
||
161 | } |
||
162 | |||
163 | echo $this->printTable($aggregates, $columns, $actions, 'aggregates-aggregates', $lang['strnoaggregates']); |
||
164 | |||
165 | $navlinks = [ |
||
166 | 'create' => [ |
||
167 | 'attr' => [ |
||
168 | 'href' => [ |
||
169 | 'url' => 'aggregates.php', |
||
170 | 'urlvars' => [ |
||
171 | 'action' => 'create', |
||
172 | 'server' => $_REQUEST['server'], |
||
173 | 'database' => $_REQUEST['database'], |
||
174 | 'schema' => $_REQUEST['schema'], |
||
175 | ], |
||
176 | ], |
||
177 | ], |
||
178 | 'content' => $lang['strcreateaggregate'], |
||
179 | ], |
||
180 | ]; |
||
181 | $this->printNavLinks($navlinks, 'aggregates-aggregates', get_defined_vars()); |
||
182 | } |
||
183 | |||
184 | public function doTree() |
||
1 ignored issue
–
show
|
|||
185 | { |
||
186 | $conf = $this->conf; |
||
187 | |||
188 | $lang = $this->lang; |
||
189 | $data = $this->misc->getDatabaseAccessor(); |
||
190 | |||
191 | $aggregates = $data->getAggregates(); |
||
192 | |||
193 | $proto = Decorator::concat(Decorator::field('proname'), ' (', Decorator::field('proargtypes'), ')'); |
||
194 | $reqvars = $this->misc->getRequestVars('aggregate'); |
||
195 | |||
196 | $attrs = [ |
||
197 | 'text' => $proto, |
||
198 | 'icon' => 'Aggregate', |
||
199 | 'toolTip' => Decorator::field('aggcomment'), |
||
200 | 'action' => Decorator::redirecturl( |
||
201 | 'redirect.php', |
||
202 | $reqvars, |
||
203 | [ |
||
204 | 'action' => 'properties', |
||
205 | 'aggrname' => Decorator::field('proname'), |
||
206 | 'aggrtype' => Decorator::field('proargtypes'), |
||
207 | ] |
||
208 | ), |
||
209 | ]; |
||
210 | |||
211 | return $this->printTree($aggregates, $attrs, 'aggregates'); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Actually creates the new aggregate in the database. |
||
216 | */ |
||
217 | public function doSaveCreate() |
||
218 | { |
||
219 | $conf = $this->conf; |
||
220 | |||
221 | $lang = $this->lang; |
||
222 | $data = $this->misc->getDatabaseAccessor(); |
||
223 | // Check inputs |
||
224 | if ('' == trim($_REQUEST['name'])) { |
||
225 | $this->doCreate($lang['straggrneedsname']); |
||
226 | |||
227 | return; |
||
228 | } |
||
229 | if ('' == trim($_REQUEST['basetype'])) { |
||
230 | $this->doCreate($lang['straggrneedsbasetype']); |
||
231 | |||
232 | return; |
||
233 | } |
||
234 | if ('' == trim($_REQUEST['sfunc'])) { |
||
235 | $this->doCreate($lang['straggrneedssfunc']); |
||
236 | |||
237 | return; |
||
238 | } |
||
239 | if ('' == trim($_REQUEST['stype'])) { |
||
240 | $this->doCreate($lang['straggrneedsstype']); |
||
241 | |||
242 | return; |
||
243 | } |
||
244 | |||
245 | $status = $data->createAggregate( |
||
246 | $_REQUEST['name'], |
||
247 | $_REQUEST['basetype'], |
||
248 | $_REQUEST['sfunc'], |
||
249 | $_REQUEST['stype'], |
||
250 | $_REQUEST['ffunc'], |
||
251 | $_REQUEST['initcond'], |
||
252 | $_REQUEST['sortop'], |
||
253 | $_REQUEST['aggrcomment'] |
||
254 | ); |
||
255 | |||
256 | if (0 == $status) { |
||
257 | $this->misc->setReloadBrowser(true); |
||
258 | $this->doDefault($lang['straggrcreated']); |
||
259 | } else { |
||
260 | $this->doCreate($lang['straggrcreatedbad']); |
||
261 | } |
||
262 | } |
||
263 | |||
264 | /** |
||
265 | * Displays a screen for create a new aggregate function. |
||
266 | * |
||
267 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
268 | */ |
||
269 | public function doCreate($msg = '') |
||
270 | { |
||
271 | $conf = $this->conf; |
||
272 | |||
273 | $lang = $this->lang; |
||
274 | $data = $this->misc->getDatabaseAccessor(); |
||
275 | |||
276 | if (!isset($_REQUEST['name'])) { |
||
277 | $_REQUEST['name'] = ''; |
||
278 | } |
||
279 | |||
280 | if (!isset($_REQUEST['basetype'])) { |
||
281 | $_REQUEST['basetype'] = ''; |
||
282 | } |
||
283 | |||
284 | if (!isset($_REQUEST['sfunc'])) { |
||
285 | $_REQUEST['sfunc'] = ''; |
||
286 | } |
||
287 | |||
288 | if (!isset($_REQUEST['stype'])) { |
||
289 | $_REQUEST['stype'] = ''; |
||
290 | } |
||
291 | |||
292 | if (!isset($_REQUEST['ffunc'])) { |
||
293 | $_REQUEST['ffunc'] = ''; |
||
294 | } |
||
295 | |||
296 | if (!isset($_REQUEST['initcond'])) { |
||
297 | $_REQUEST['initcond'] = ''; |
||
298 | } |
||
299 | |||
300 | if (!isset($_REQUEST['sortop'])) { |
||
301 | $_REQUEST['sortop'] = ''; |
||
302 | } |
||
303 | |||
304 | if (!isset($_REQUEST['aggrcomment'])) { |
||
305 | $_REQUEST['aggrcomment'] = ''; |
||
306 | } |
||
307 | |||
308 | $this->printTrail('schema'); |
||
309 | $this->printTitle($lang['strcreateaggregate'], 'pg.aggregate.create'); |
||
310 | $this->printMsg($msg); |
||
311 | |||
312 | echo '<form action="'.\SUBFOLDER."/src/views/aggregates.php\" method=\"post\">\n"; |
||
313 | echo "<table>\n"; |
||
314 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['strname']}</th>\n"; |
||
315 | echo "\t\t<td class=\"data\"><input name=\"name\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
316 | htmlspecialchars($_REQUEST['name']), "\" /></td>\n\t</tr>\n"; |
||
317 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['straggrbasetype']}</th>\n"; |
||
318 | echo "\t\t<td class=\"data\"><input name=\"basetype\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
319 | htmlspecialchars($_REQUEST['basetype']), "\" /></td>\n\t</tr>\n"; |
||
320 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['straggrsfunc']}</th>\n"; |
||
321 | echo "\t\t<td class=\"data\"><input name=\"sfunc\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
322 | htmlspecialchars($_REQUEST['sfunc']), "\" /></td>\n\t</tr>\n"; |
||
323 | echo "\t<tr>\n\t\t<th class=\"data left required\">{$lang['straggrstype']}</th>\n"; |
||
324 | echo "\t\t<td class=\"data\"><input name=\"stype\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
325 | htmlspecialchars($_REQUEST['stype']), "\" /></td>\n\t</tr>\n"; |
||
326 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['straggrffunc']}</th>\n"; |
||
327 | echo "\t\t<td class=\"data\"><input name=\"ffunc\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
328 | htmlspecialchars($_REQUEST['ffunc']), "\" /></td>\n\t</tr>\n"; |
||
329 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['straggrinitcond']}</th>\n"; |
||
330 | echo "\t\t<td class=\"data\"><input name=\"initcond\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
331 | htmlspecialchars($_REQUEST['initcond']), "\" /></td>\n\t</tr>\n"; |
||
332 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['straggrsortop']}</th>\n"; |
||
333 | echo "\t\t<td class=\"data\"><input name=\"sortop\" size=\"32\" maxlength=\"{$data->_maxNameLen}\" value=\"", |
||
334 | htmlspecialchars($_REQUEST['sortop']), "\" /></td>\n\t</tr>\n"; |
||
335 | echo "\t<tr>\n\t\t<th class=\"data left\">{$lang['strcomment']}</th>\n"; |
||
336 | echo "\t\t<td><textarea name=\"aggrcomment\" rows=\"3\" cols=\"32\">", |
||
337 | htmlspecialchars($_REQUEST['aggrcomment']), "</textarea></td>\n\t</tr>\n"; |
||
338 | |||
339 | echo "</table>\n"; |
||
340 | echo "<p><input type=\"hidden\" name=\"action\" value=\"save_create\" />\n"; |
||
341 | echo $this->misc->form; |
||
342 | echo "<input type=\"submit\" value=\"{$lang['strcreate']}\" />\n"; |
||
343 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" /></p>\n"; |
||
344 | echo "</form>\n"; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * Function to save after altering an aggregate. |
||
349 | */ |
||
350 | public function doSaveAlter() |
||
351 | { |
||
352 | $conf = $this->conf; |
||
353 | |||
354 | $lang = $this->lang; |
||
355 | $data = $this->misc->getDatabaseAccessor(); |
||
356 | |||
357 | // Check inputs |
||
358 | if ('' == trim($_REQUEST['aggrname'])) { |
||
359 | $this->doAlter($lang['straggrneedsname']); |
||
360 | |||
361 | return; |
||
362 | } |
||
363 | |||
364 | $status = $data->alterAggregate( |
||
365 | $_REQUEST['aggrname'], |
||
366 | $_REQUEST['aggrtype'], |
||
367 | $_REQUEST['aggrowner'], |
||
368 | $_REQUEST['aggrschema'], |
||
369 | $_REQUEST['aggrcomment'], |
||
370 | $_REQUEST['newaggrname'], |
||
371 | $_REQUEST['newaggrowner'], |
||
372 | $_REQUEST['newaggrschema'], |
||
373 | $_REQUEST['newaggrcomment'] |
||
374 | ); |
||
375 | if (0 == $status) { |
||
376 | $this->doDefault($lang['straggraltered']); |
||
377 | } else { |
||
378 | $this->doAlter($lang['straggralteredbad']); |
||
379 | |||
380 | return; |
||
381 | } |
||
382 | } |
||
383 | |||
384 | /** |
||
385 | * Function to allow editing an aggregate function. |
||
386 | * |
||
387 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
388 | */ |
||
389 | public function doAlter($msg = '') |
||
431 | } |
||
432 | |||
433 | /** |
||
434 | * Show confirmation of drop and perform actual drop of the aggregate function selected. |
||
435 | * |
||
436 | * @param mixed $confirm |
||
1 ignored issue
–
show
|
|||
437 | */ |
||
438 | public function doDrop($confirm) |
||
467 | } |
||
468 | } |
||
469 | } |
||
470 | |||
471 | /** |
||
472 | * Show the properties of an aggregate. |
||
473 | * |
||
474 | * @param mixed $msg |
||
1 ignored issue
–
show
|
|||
475 | */ |
||
476 | public function doProperties($msg = '') |
||
570 | } |
||
571 | } |
||
572 |