| Conditions | 25 |
| Paths | 1826 |
| Total Lines | 109 |
| Code Lines | 62 |
| 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 |
||
| 263 | public function doSaveCreateWiz($is_materialized = false) |
||
| 264 | { |
||
| 265 | $data = $this->misc->getDatabaseAccessor(); |
||
| 266 | |||
| 267 | // Check that they've given a name and fields they want to select |
||
| 268 | |||
| 269 | if (!strlen($_POST['formView'])) { |
||
| 270 | return $this->doSetParamsCreate($this->lang['strviewneedsname']); |
||
| 271 | } |
||
| 272 | if (!isset($_POST['formFields']) || !count($_POST['formFields'])) { |
||
| 273 | return $this->doSetParamsCreate($this->lang['strviewneedsfields']); |
||
| 274 | } |
||
| 275 | $selFields = ''; |
||
| 276 | |||
| 277 | $tmpHsh = []; |
||
| 278 | |||
| 279 | foreach ($_POST['formFields'] as $curField) { |
||
| 280 | $arrTmp = unserialize($curField); |
||
| 281 | $data->fieldArrayClean($arrTmp); |
||
| 282 | |||
| 283 | $this->_appendToSelFields($arrTmp, $selFields, $tmpHsh); |
||
| 284 | } |
||
| 285 | |||
| 286 | $selFields = substr($selFields, 0, -2); |
||
| 287 | unset($arrTmp, $tmpHsh); |
||
| 288 | $linkFields = ''; |
||
| 289 | $arrJoined = []; |
||
| 290 | $arrUsedTbls = []; |
||
| 291 | |||
| 292 | list($arrLinks, $count) = $this->_getArrLinks(); |
||
| 293 | |||
| 294 | // If we have at least one join condition, output it |
||
| 295 | |||
| 296 | $j = 0; |
||
| 297 | |||
| 298 | while ($j < $count) { |
||
| 299 | foreach ($arrLinks as $curLink) { |
||
| 300 | $arrLeftLink = unserialize($curLink['leftlink']); |
||
| 301 | $arrRightLink = unserialize($curLink['rightlink']); |
||
| 302 | $data->fieldArrayClean($arrLeftLink); |
||
| 303 | $data->fieldArrayClean($arrRightLink); |
||
| 304 | |||
| 305 | $tbl1 = "\"{$arrLeftLink['schemaname']}\".\"{$arrLeftLink['tablename']}\""; |
||
| 306 | $tbl2 = "\"{$arrRightLink['schemaname']}\".\"{$arrRightLink['tablename']}\""; |
||
| 307 | |||
| 308 | if (!((!in_array($curLink, $arrJoined, true) && in_array($tbl1, $arrUsedTbls, true)) || !count($arrJoined))) { |
||
| 309 | continue; |
||
| 310 | } |
||
| 311 | // Make sure for multi-column foreign keys that we use a table alias tables joined to more than once |
||
| 312 | // This can (and should be) more optimized for multi-column foreign keys |
||
| 313 | $adj_tbl2 = in_array($tbl2, $arrUsedTbls, true) ? "${tbl2} AS alias_ppa_".time() : $tbl2; |
||
| 314 | |||
| 315 | $clause1 = "{$curLink['operator']} ${adj_tbl2} ON ({$tbl1}.\"{$arrLeftLink['fieldname']}\" = {$tbl2}.\"{$arrRightLink['fieldname']}\") "; |
||
| 316 | $clause2 = "${tbl1} {$curLink['operator']} ${adj_tbl2} ON ({$tbl1}.\"{$arrLeftLink['fieldname']}\" = {$tbl2}.\"{$arrRightLink['fieldname']}\") "; |
||
| 317 | |||
| 318 | $linkFields .= strlen($linkFields) ? $clause1 : $clause2; |
||
| 319 | |||
| 320 | $arrJoined[] = $curLink; |
||
| 321 | if (!in_array($tbl1, $arrUsedTbls, true)) { |
||
| 322 | $arrUsedTbls[] = $tbl1; |
||
| 323 | } |
||
| 324 | |||
| 325 | if (!in_array($tbl2, $arrUsedTbls, true)) { |
||
| 326 | $arrUsedTbls[] = $tbl2; |
||
| 327 | } |
||
| 328 | } |
||
| 329 | ++$j; |
||
| 330 | } |
||
| 331 | |||
| 332 | //if linkFields has no length then either _POST['formLink'] was not set, or there were no join conditions |
||
| 333 | //just select from all seleted tables - a cartesian join do a |
||
| 334 | if (!strlen($linkFields)) { |
||
| 335 | foreach ($_POST['formTables'] as $curTable) { |
||
| 336 | $arrTmp = unserialize($curTable); |
||
| 337 | $data->fieldArrayClean($arrTmp); |
||
| 338 | $linkFields .= (strlen($linkFields) ? ', ' : ' ')."\"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\""; |
||
| 339 | } |
||
| 340 | } |
||
| 341 | |||
| 342 | $addConditions = ''; |
||
| 343 | if (is_array($_POST['formCondition'])) { |
||
| 344 | foreach ($_POST['formCondition'] as $curCondition) { |
||
| 345 | if (strlen($curCondition['field']) && strlen($curCondition['txt'])) { |
||
| 346 | $arrTmp = unserialize($curCondition['field']); |
||
| 347 | $data->fieldArrayClean($arrTmp); |
||
| 348 | $condition = " \"{$arrTmp['schemaname']}\".\"{$arrTmp['tablename']}\".\"{$arrTmp['fieldname']}\" {$curCondition['operator']} '{$curCondition['txt']}' "; |
||
| 349 | $addConditions .= (strlen($addConditions) ? ' AND ' : ' ').$condition; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | } |
||
| 353 | |||
| 354 | $viewQuery = "SELECT ${selFields} FROM ${linkFields} "; |
||
| 355 | |||
| 356 | //add where from additional conditions |
||
| 357 | if (strlen($addConditions)) { |
||
| 358 | $viewQuery .= ' WHERE '.$addConditions; |
||
| 359 | } |
||
| 360 | |||
| 361 | try { |
||
| 362 | $status = $data->createView($_POST['formView'], $viewQuery, false, $_POST['formComment'], $is_materialized); |
||
| 363 | if (0 == $status) { |
||
| 364 | $this->misc->setReloadBrowser(true); |
||
| 365 | |||
| 366 | return $this->doDefault($this->lang['strviewcreated']); |
||
|
1 ignored issue
–
show
|
|||
| 367 | } |
||
| 368 | |||
| 369 | return $this->doSetParamsCreate($this->lang['strviewcreatedbad']); |
||
| 370 | } catch (\PHPPgAdmin\ADOdbException $e) { |
||
| 371 | return $this->halt($e->getMessage()); |
||
|
1 ignored issue
–
show
|
|||
| 372 | } |
||
| 375 |