| Total Complexity | 41 |
| Total Lines | 384 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TablespacesController 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 TablespacesController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class TablespacesController extends BaseController |
||
| 13 | { |
||
| 14 | public $controller_name = 'TablespacesController'; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Default method to render the controller according to the action parameter. |
||
| 18 | */ |
||
| 19 | public function render() |
||
| 20 | { |
||
| 21 | $conf = $this->conf; |
||
|
1 ignored issue
–
show
|
|||
| 22 | |||
| 23 | $lang = $this->lang; |
||
| 24 | $data = $this->misc->getDatabaseAccessor(); |
||
| 25 | $action = $this->action; |
||
| 26 | |||
| 27 | $this->printHeader($lang['strtablespaces']); |
||
| 28 | $this->printBody(); |
||
| 29 | |||
| 30 | switch ($action) { |
||
| 31 | case 'save_create': |
||
| 32 | if (isset($_REQUEST['cancel'])) { |
||
| 33 | $this->doDefault(); |
||
| 34 | } else { |
||
| 35 | $this->doSaveCreate(); |
||
| 36 | } |
||
| 37 | |||
| 38 | break; |
||
| 39 | case 'create': |
||
| 40 | $this->doCreate(); |
||
| 41 | |||
| 42 | break; |
||
| 43 | case 'drop': |
||
| 44 | if (isset($_REQUEST['cancel'])) { |
||
| 45 | $this->doDefault(); |
||
| 46 | } else { |
||
| 47 | $this->doDrop(false); |
||
| 48 | } |
||
| 49 | |||
| 50 | break; |
||
| 51 | case 'confirm_drop': |
||
| 52 | $this->doDrop(true); |
||
| 53 | |||
| 54 | break; |
||
| 55 | case 'save_edit': |
||
| 56 | if (isset($_REQUEST['cancel'])) { |
||
| 57 | $this->doDefault(); |
||
| 58 | } else { |
||
| 59 | $this->doSaveAlter(); |
||
| 60 | } |
||
| 61 | |||
| 62 | break; |
||
| 63 | case 'edit': |
||
| 64 | $this->doAlter(); |
||
| 65 | |||
| 66 | break; |
||
| 67 | default: |
||
| 68 | $this->doDefault(); |
||
| 69 | |||
| 70 | break; |
||
| 71 | } |
||
| 72 | |||
| 73 | $this->printFooter(); |
||
| 74 | } |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Show default list of tablespaces in the cluster. |
||
| 78 | * |
||
| 79 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 80 | */ |
||
| 81 | public function doDefault($msg = '') |
||
| 82 | { |
||
| 83 | $conf = $this->conf; |
||
| 84 | |||
| 85 | $lang = $this->lang; |
||
| 86 | $data = $this->misc->getDatabaseAccessor(); |
||
| 87 | |||
| 88 | $this->printTrail('server'); |
||
| 89 | $this->printTabs('server', 'tablespaces'); |
||
| 90 | $this->printMsg($msg); |
||
| 91 | |||
| 92 | $tablespaces = $data->getTablespaces(); |
||
| 93 | |||
| 94 | $columns = [ |
||
| 95 | 'database' => [ |
||
| 96 | 'title' => $lang['strname'], |
||
| 97 | 'field' => \PHPPgAdmin\Decorators\Decorator::field('spcname'), |
||
| 98 | ], |
||
| 99 | 'owner' => [ |
||
| 100 | 'title' => $lang['strowner'], |
||
| 101 | 'field' => \PHPPgAdmin\Decorators\Decorator::field('spcowner'), |
||
| 102 | ], |
||
| 103 | 'location' => [ |
||
| 104 | 'title' => $lang['strlocation'], |
||
| 105 | 'field' => \PHPPgAdmin\Decorators\Decorator::field('spclocation'), |
||
| 106 | ], |
||
| 107 | 'actions' => [ |
||
| 108 | 'title' => $lang['stractions'], |
||
| 109 | ], |
||
| 110 | ]; |
||
| 111 | |||
| 112 | if ($data->hasSharedComments()) { |
||
| 113 | $columns['comment'] = [ |
||
| 114 | 'title' => $lang['strcomment'], |
||
| 115 | 'field' => \PHPPgAdmin\Decorators\Decorator::field('spccomment'), |
||
| 116 | ]; |
||
| 117 | } |
||
| 118 | |||
| 119 | $actions = [ |
||
| 120 | 'alter' => [ |
||
| 121 | 'content' => $lang['stralter'], |
||
| 122 | 'attr' => [ |
||
| 123 | 'href' => [ |
||
| 124 | 'url' => 'tablespaces.php', |
||
| 125 | 'urlvars' => [ |
||
| 126 | 'action' => 'edit', |
||
| 127 | 'tablespace' => \PHPPgAdmin\Decorators\Decorator::field('spcname'), |
||
| 128 | ], |
||
| 129 | ], |
||
| 130 | ], |
||
| 131 | ], |
||
| 132 | 'drop' => [ |
||
| 133 | 'content' => $lang['strdrop'], |
||
| 134 | 'attr' => [ |
||
| 135 | 'href' => [ |
||
| 136 | 'url' => 'tablespaces.php', |
||
| 137 | 'urlvars' => [ |
||
| 138 | 'action' => 'confirm_drop', |
||
| 139 | 'tablespace' => \PHPPgAdmin\Decorators\Decorator::field('spcname'), |
||
| 140 | ], |
||
| 141 | ], |
||
| 142 | ], |
||
| 143 | ], |
||
| 144 | 'privileges' => [ |
||
| 145 | 'content' => $lang['strprivileges'], |
||
| 146 | 'attr' => [ |
||
| 147 | 'href' => [ |
||
| 148 | 'url' => 'privileges.php', |
||
| 149 | 'urlvars' => [ |
||
| 150 | 'subject' => 'tablespace', |
||
| 151 | 'tablespace' => \PHPPgAdmin\Decorators\Decorator::field('spcname'), |
||
| 152 | ], |
||
| 153 | ], |
||
| 154 | ], |
||
| 155 | ], |
||
| 156 | ]; |
||
| 157 | |||
| 158 | echo $this->printTable($tablespaces, $columns, $actions, 'tablespaces-tablespaces', $lang['strnotablespaces']); |
||
| 159 | |||
| 160 | $this->printNavLinks(['create' => [ |
||
|
1 ignored issue
–
show
|
|||
| 161 | 'attr' => [ |
||
| 162 | 'href' => [ |
||
| 163 | 'url' => 'tablespaces.php', |
||
| 164 | 'urlvars' => [ |
||
| 165 | 'action' => 'create', |
||
| 166 | 'server' => $_REQUEST['server'], |
||
| 167 | ], |
||
| 168 | ], |
||
| 169 | ], |
||
| 170 | 'content' => $lang['strcreatetablespace'], |
||
| 171 | ]], 'tablespaces-tablespaces', get_defined_vars()); |
||
|
1 ignored issue
–
show
|
|||
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Function to allow altering of a tablespace. |
||
| 176 | * |
||
| 177 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 178 | */ |
||
| 179 | public function doAlter($msg = '') |
||
| 238 | } |
||
| 239 | } |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Function to save after altering a tablespace. |
||
| 243 | */ |
||
| 244 | public function doSaveAlter() |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Show confirmation of drop and perform actual drop. |
||
| 271 | * |
||
| 272 | * @param mixed $confirm |
||
|
1 ignored issue
–
show
|
|||
| 273 | */ |
||
| 274 | public function doDrop($confirm) |
||
| 275 | { |
||
| 276 | $conf = $this->conf; |
||
| 277 | |||
| 278 | $lang = $this->lang; |
||
| 279 | $data = $this->misc->getDatabaseAccessor(); |
||
| 280 | |||
| 281 | if ($confirm) { |
||
| 282 | $this->printTrail('tablespace'); |
||
| 283 | $this->printTitle($lang['strdrop'], 'pg.tablespace.drop'); |
||
| 284 | |||
| 285 | echo '<p>', sprintf($lang['strconfdroptablespace'], $this->misc->printVal($_REQUEST['tablespace'])), "</p>\n"; |
||
| 286 | |||
| 287 | echo '<form action="'.\SUBFOLDER."/src/views/tablespaces.php\" method=\"post\">\n"; |
||
| 288 | echo $this->misc->form; |
||
| 289 | echo "<input type=\"hidden\" name=\"action\" value=\"drop\" />\n"; |
||
| 290 | echo '<input type="hidden" name="tablespace" value="', htmlspecialchars($_REQUEST['tablespace']), "\" />\n"; |
||
| 291 | echo "<input type=\"submit\" name=\"drop\" value=\"{$lang['strdrop']}\" />\n"; |
||
| 292 | echo "<input type=\"submit\" name=\"cancel\" value=\"{$lang['strcancel']}\" />\n"; |
||
| 293 | echo "</form>\n"; |
||
| 294 | } else { |
||
| 295 | $status = $data->droptablespace($_REQUEST['tablespace']); |
||
| 296 | if (0 == $status) { |
||
| 297 | $this->doDefault($lang['strtablespacedropped']); |
||
| 298 | } else { |
||
| 299 | $this->doDefault($lang['strtablespacedroppedbad']); |
||
| 300 | } |
||
| 301 | } |
||
| 302 | } |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Displays a screen where they can enter a new tablespace. |
||
| 306 | * |
||
| 307 | * @param mixed $msg |
||
|
1 ignored issue
–
show
|
|||
| 308 | */ |
||
| 309 | public function doCreate($msg = '') |
||
| 368 | } |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Actually creates the new tablespace in the cluster. |
||
| 372 | */ |
||
| 373 | public function doSaveCreate() |
||
| 396 | } |
||
| 397 | } |
||
| 398 | } |
||
| 400 |