Conditions | 37 |
Paths | > 20000 |
Total Lines | 188 |
Code Lines | 135 |
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 |
||
291 | |||
292 | private function getHREFSubject($subject) |
||
1 ignored issue
–
show
|
|||
293 | { |
||
294 | $vars = $this->misc->getSubjectParams($subject); |
||
295 | ksort($vars['params']); |
||
296 | |||
297 | return "{$vars['url']}?" . http_build_query($vars['params'], '', '&'); |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Create a bread crumb trail of the object hierarchy. |
||
302 | * |
||
303 | * @param null|string $subject sunkect of the trail |
||
304 | */ |
||
305 | private function _getTrail($subject = null) |
||
306 | { |
||
307 | $lang = $this->lang; |
||
308 | |||
309 | $this->misc = $this->misc; |
||
310 | $appName = $this->misc->appName; |
||
311 | |||
312 | $data = $this->misc->getDatabaseAccessor(); |
||
313 | |||
314 | $trail = []; |
||
315 | $vars = ''; |
||
316 | $done = false; |
||
317 | |||
318 | $trail['root'] = [ |
||
319 | 'text' => $appName, |
||
320 | 'url' => SUBFOLDER . '/src/views/servers', |
||
321 | 'icon' => 'Introduction', |
||
322 | ]; |
||
323 | |||
324 | if ('root' == $subject) { |
||
325 | return $trail; |
||
326 | } |
||
327 | |||
328 | $server_info = $this->misc->getServerInfo(); |
||
329 | $trail['server'] = [ |
||
330 | 'title' => $lang['strserver'], |
||
331 | 'text' => $server_info['desc'], |
||
332 | 'url' => $this->getHREFSubject('server'), |
||
333 | 'help' => 'pg.server', |
||
334 | 'icon' => 'Server', |
||
335 | ]; |
||
336 | |||
337 | if ('server' == $subject) { |
||
338 | return $trail; |
||
339 | } |
||
340 | |||
341 | $database_rolename = [ |
||
342 | 'database' => [ |
||
343 | 'title' => $lang['strdatabase'], |
||
344 | 'subject' => 'database', |
||
345 | 'help' => 'pg.database', |
||
346 | 'icon' => 'Database', |
||
347 | ], |
||
348 | 'rolename' => [ |
||
349 | 'title' => $lang['strrole'], |
||
350 | 'subject' => 'role', |
||
351 | 'help' => 'pg.role', |
||
352 | 'icon' => 'Roles', |
||
353 | ], |
||
354 | ]; |
||
355 | |||
356 | $trail = $this->_getTrailsFromArray($trail, $database_rolename); |
||
357 | |||
358 | if (in_array($subject, ['database', 'role'])) { |
||
359 | return $trail; |
||
360 | } |
||
361 | |||
362 | $schema = [ |
||
363 | 'schema' => [ |
||
364 | 'title' => $lang['strschema'], |
||
365 | 'subject' => 'schema', |
||
366 | 'help' => 'pg.schema', |
||
367 | 'icon' => 'Schema', |
||
368 | ], |
||
369 | ]; |
||
370 | |||
371 | $trail = $this->_getTrailsFromArray($trail, $schema); |
||
372 | if ('schema' == $subject) { |
||
373 | return $trail; |
||
374 | } |
||
375 | |||
376 | $table_view_matview_fts = [ |
||
377 | 'table' => [ |
||
378 | 'title' => $lang['strtable'], |
||
379 | 'subject' => 'table', |
||
380 | 'help' => 'pg.table', |
||
381 | 'icon' => 'Table', |
||
382 | ], |
||
383 | 'view' => [ |
||
384 | 'title' => $lang['strview'], |
||
385 | 'subject' => 'view', |
||
386 | 'help' => 'pg.view', |
||
387 | 'icon' => 'View', |
||
388 | ], |
||
389 | 'matview' => [ |
||
390 | 'title' => 'M' . $lang['strview'], |
||
391 | 'subject' => 'matview', |
||
392 | 'help' => 'pg.matview', |
||
393 | 'icon' => 'MViews', |
||
394 | ], |
||
395 | 'ftscfg' => [ |
||
396 | 'title' => $lang['strftsconfig'], |
||
397 | 'subject' => 'ftscfg', |
||
398 | 'help' => 'pg.ftscfg.example', |
||
399 | 'icon' => 'Fts', |
||
400 | ], |
||
401 | ]; |
||
402 | |||
403 | $trail = $this->_getTrailsFromArray($trail, $table_view_matview_fts); |
||
404 | |||
405 | if (in_array($subject, ['table', 'view', 'matview', 'ftscfg'])) { |
||
406 | return $trail; |
||
407 | } |
||
408 | |||
409 | if (!is_null($subject)) { |
||
410 | $trail = $this->_getLastTrailPart($subject, $trail); |
||
411 | } |
||
412 | |||
413 | //$this->prtrace($trail); |
||
414 | |||
415 | return $trail; |
||
416 | } |
||
417 | |||
418 | private function _getTrailsFromArray($trail, $the_array) |
||
419 | { |
||
420 | foreach ($the_array as $key => $value) { |
||
421 | if (isset($_REQUEST[$key])) { |
||
422 | $trail[$key] = [ |
||
423 | 'title' => $value['title'], |
||
424 | 'text' => $_REQUEST[$key], |
||
425 | 'url' => $this->getHREFSubject($value['subject']), |
||
426 | 'help' => $value['help'], |
||
427 | 'icon' => $value['icon'], |
||
428 | ]; |
||
429 | break; |
||
430 | } |
||
431 | } |
||
432 | return $trail; |
||
433 | } |
||
434 | |||
435 | private function _getLastTrailPart($subject, $trail) |
||
436 | { |
||
437 | $lang = $this->lang; |
||
438 | |||
439 | switch ($subject) { |
||
440 | case 'function': |
||
441 | $trail[$subject] = [ |
||
442 | 'title' => $lang['str' . $subject], |
||
443 | 'text' => $_REQUEST[$subject], |
||
444 | 'url' => $this->getHREFSubject('function'), |
||
445 | 'help' => 'pg.function', |
||
446 | 'icon' => 'Function', |
||
447 | ]; |
||
448 | |||
449 | break; |
||
450 | case 'aggregate': |
||
451 | $trail[$subject] = [ |
||
452 | 'title' => $lang['straggregate'], |
||
453 | 'text' => $_REQUEST['aggrname'], |
||
454 | 'url' => $this->getHREFSubject('aggregate'), |
||
455 | 'help' => 'pg.aggregate', |
||
456 | 'icon' => 'Aggregate', |
||
457 | ]; |
||
458 | |||
459 | break; |
||
460 | case 'column': |
||
461 | $trail['column'] = [ |
||
462 | 'title' => $lang['strcolumn'], |
||
463 | 'text' => $_REQUEST['column'], |
||
464 | 'icon' => 'Column', |
||
465 | 'url' => $this->getHREFSubject('column'), |
||
466 | ]; |
||
467 | |||
468 | break; |
||
469 | default: |
||
470 | if (isset($_REQUEST[$subject])) { |
||
471 | switch ($subject) { |
||
472 | case 'domain': |
||
473 | $icon = 'Domain'; |
||
474 | |||
475 | break; |
||
476 | case 'sequence': |
||
477 | $icon = 'Sequence'; |
||
478 | |||
479 | break; |
||
508 |