Total Complexity | 55 |
Total Lines | 548 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like ViewsController 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 ViewsController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
16 | class ViewsController extends BaseController |
||
17 | { |
||
18 | use \PHPPgAdmin\Traits\ViewsMatviewsTrait; |
||
19 | |||
20 | public $table_place = 'views-views'; |
||
21 | public $controller_title = 'strviews'; |
||
22 | |||
23 | // this member variable is view for views and matview for materialized views |
||
24 | public $keystring = 'view'; |
||
25 | |||
26 | /** |
||
27 | * Default method to render the controller according to the action parameter. |
||
28 | */ |
||
29 | public function render() |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Show default list of views in the database. |
||
109 | * |
||
110 | * @param mixed $msg |
||
111 | */ |
||
112 | public function doDefault($msg = '') |
||
113 | { |
||
114 | $data = $this->misc->getDatabaseAccessor(); |
||
115 | |||
116 | $this->printTrail('schema'); |
||
117 | $this->printTabs('schema', 'views'); |
||
118 | $this->printMsg($msg); |
||
119 | |||
120 | $views = $data->getViews(); |
||
121 | |||
122 | $columns = [ |
||
123 | $this->keystring => [ |
||
124 | 'title' => $this->lang['strview'], |
||
125 | 'field' => Decorator::field('relname'), |
||
126 | 'url' => \SUBFOLDER."/redirect/view?{$this->misc->href}&", |
||
127 | 'vars' => [$this->keystring => 'relname'], |
||
128 | ], |
||
129 | 'owner' => [ |
||
130 | 'title' => $this->lang['strowner'], |
||
131 | 'field' => Decorator::field('relowner'), |
||
132 | ], |
||
133 | 'actions' => [ |
||
134 | 'title' => $this->lang['stractions'], |
||
135 | ], |
||
136 | 'comment' => [ |
||
137 | 'title' => $this->lang['strcomment'], |
||
138 | 'field' => Decorator::field('relcomment'), |
||
139 | ], |
||
140 | ]; |
||
141 | |||
142 | $actions = [ |
||
143 | 'multiactions' => [ |
||
144 | 'keycols' => [$this->keystring => 'relname'], |
||
145 | 'url' => 'views', |
||
146 | ], |
||
147 | 'browse' => [ |
||
148 | 'content' => $this->lang['strbrowse'], |
||
149 | 'attr' => [ |
||
150 | 'href' => [ |
||
151 | 'url' => 'display', |
||
152 | 'urlvars' => [ |
||
153 | 'action' => 'confselectrows', |
||
154 | 'subject' => $this->keystring, |
||
155 | 'return' => 'schema', |
||
156 | $this->keystring => Decorator::field('relname'), |
||
157 | ], |
||
158 | ], |
||
159 | ], |
||
160 | ], |
||
161 | 'select' => [ |
||
162 | 'content' => $this->lang['strselect'], |
||
163 | 'attr' => [ |
||
164 | 'href' => [ |
||
165 | 'url' => 'views', |
||
166 | 'urlvars' => [ |
||
167 | 'action' => 'confselectrows', |
||
168 | $this->keystring => Decorator::field('relname'), |
||
169 | ], |
||
170 | ], |
||
171 | ], |
||
172 | ], |
||
173 | |||
174 | // Insert is possible if the relevant rule for the view has been created. |
||
175 | // 'insert' => array( |
||
176 | // 'title' => $this->lang['strinsert'], |
||
177 | // 'url' => "views?action=confinsertrow&{$this->misc->href}&", |
||
178 | // 'vars' => array($this->keystring => 'relname'), |
||
179 | // ), |
||
180 | |||
181 | 'alter' => [ |
||
182 | 'content' => $this->lang['stralter'], |
||
183 | 'attr' => [ |
||
184 | 'href' => [ |
||
185 | 'url' => 'viewproperties', |
||
186 | 'urlvars' => [ |
||
187 | 'action' => 'confirm_alter', |
||
188 | $this->keystring => Decorator::field('relname'), |
||
189 | ], |
||
190 | ], |
||
191 | ], |
||
192 | ], |
||
193 | 'drop' => [ |
||
194 | 'multiaction' => 'confirm_drop', |
||
195 | 'content' => $this->lang['strdrop'], |
||
196 | 'attr' => [ |
||
197 | 'href' => [ |
||
198 | 'url' => 'views', |
||
199 | 'urlvars' => [ |
||
200 | 'action' => 'confirm_drop', |
||
201 | $this->keystring => Decorator::field('relname'), |
||
202 | ], |
||
203 | ], |
||
204 | ], |
||
205 | ], |
||
206 | ]; |
||
207 | |||
208 | echo $this->printTable($views, $columns, $actions, $this->table_place, $this->lang['strnoviews']); |
||
209 | |||
210 | $navlinks = [ |
||
211 | 'create' => [ |
||
212 | 'attr' => [ |
||
213 | 'href' => [ |
||
214 | 'url' => 'views', |
||
215 | 'urlvars' => [ |
||
216 | 'action' => 'create', |
||
217 | 'server' => $_REQUEST['server'], |
||
218 | 'database' => $_REQUEST['database'], |
||
219 | 'schema' => $_REQUEST['schema'], |
||
220 | ], |
||
221 | ], |
||
222 | ], |
||
223 | 'content' => $this->lang['strcreateview'], |
||
224 | ], |
||
225 | 'createwiz' => [ |
||
226 | 'attr' => [ |
||
227 | 'href' => [ |
||
228 | 'url' => 'views', |
||
229 | 'urlvars' => [ |
||
230 | 'action' => 'wiz_create', |
||
231 | 'server' => $_REQUEST['server'], |
||
232 | 'database' => $_REQUEST['database'], |
||
233 | 'schema' => $_REQUEST['schema'], |
||
234 | ], |
||
235 | ], |
||
236 | ], |
||
237 | 'content' => $this->lang['strcreateviewwiz'], |
||
238 | ], |
||
239 | ]; |
||
240 | $this->printNavLinks($navlinks, $this->table_place, get_defined_vars()); |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * Generate XML for the browser tree. |
||
245 | */ |
||
246 | public function doTree() |
||
247 | { |
||
248 | $data = $this->misc->getDatabaseAccessor(); |
||
249 | |||
250 | $views = $data->getViews(); |
||
251 | |||
252 | $reqvars = $this->misc->getRequestVars($this->keystring); |
||
253 | |||
254 | $attrs = [ |
||
255 | 'text' => Decorator::field('relname'), |
||
256 | 'icon' => 'View', |
||
257 | 'iconAction' => Decorator::url('display', $reqvars, [$this->keystring => Decorator::field('relname')]), |
||
258 | 'toolTip' => Decorator::field('relcomment'), |
||
259 | 'action' => Decorator::redirecturl('redirect', $reqvars, [$this->keystring => Decorator::field('relname')]), |
||
260 | 'branch' => Decorator::url('views', $reqvars, ['action' => 'subtree', $this->keystring => Decorator::field('relname')]), |
||
261 | ]; |
||
262 | |||
263 | return $this->printTree($views, $attrs, 'views'); |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * Show confirmation of drop and perform actual drop. |
||
268 | * |
||
269 | * @param mixed $confirm |
||
270 | */ |
||
271 | public function doDrop($confirm) |
||
335 | } |
||
336 | } |
||
337 | } |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Sets up choices for table linkage, and which fields to select for the view we're creating. |
||
342 | * |
||
343 | * @param mixed $msg |
||
344 | */ |
||
345 | public function doSetParamsCreate($msg = '') |
||
485 | } |
||
486 | } |
||
487 | |||
488 | /** |
||
489 | * Display a wizard where they can enter a new view. |
||
490 | * |
||
491 | * @param mixed $msg |
||
492 | */ |
||
493 | public function doWizardCreate($msg = '') |
||
494 | { |
||
495 | $this->printTrail('schema'); |
||
496 | $this->printTitle($this->lang['strcreateviewwiz'], 'pg.view.create'); |
||
497 | $this->printMsg($msg); |
||
498 | |||
499 | $this->printWizardCreateForm(); |
||
500 | } |
||
501 | |||
502 | /** |
||
503 | * Displays a screen where they can enter a new view. |
||
504 | * |
||
505 | * @param mixed $msg |
||
506 | */ |
||
507 | public function doCreate($msg = '') |
||
543 | } |
||
544 | |||
545 | /** |
||
546 | * Actually creates the new view in the database. |
||
547 | */ |
||
548 | public function doSaveCreate() |
||
568 |