| Conditions | 20 |
| Paths | 93 |
| Total Lines | 117 |
| Code Lines | 88 |
| Lines | 9 |
| Ratio | 7.69 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 66 | public function preparePage() |
||
|
|
|||
| 67 | { |
||
| 68 | $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
||
| 69 | $this->P->cb_pagetype = 'content'; |
||
| 70 | $this->P->cb_subnav = 'admin'; |
||
| 71 | |||
| 72 | $this->P->cb_customcontenttemplate = 'shop/itemgroupadmin'; |
||
| 73 | |||
| 74 | $return = ''; |
||
| 75 | if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'insert_lang') { |
||
| 76 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 77 | $querybuilder |
||
| 78 | ->select('itmg_id') |
||
| 79 | ->from('itemgroups_base') |
||
| 80 | ->where('itmg_id = ?') |
||
| 81 | ->setParameter(0, $_REQUEST['gid']) |
||
| 82 | ; |
||
| 83 | $stmt = $querybuilder->execute(); |
||
| 84 | |||
| 85 | $iNumRowsBasis = $stmt->rowCount(); |
||
| 86 | |||
| 87 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 88 | $querybuilder |
||
| 89 | ->select('itmgt_id') |
||
| 90 | ->from('itemgroups_text') |
||
| 91 | ->where('itmgt_pid = ? AND itmgt_lang = ?') |
||
| 92 | ->setParameter(0, $_REQUEST['gid']) |
||
| 93 | ->setParameter(1, HelperConfig::$lang) |
||
| 94 | ; |
||
| 95 | $stmt = $querybuilder->execute(); |
||
| 96 | |||
| 97 | $iNumRowsLang = $stmt->rowCount(); |
||
| 98 | |||
| 99 | if ($iNumRowsBasis === 1 && $iNumRowsLang === 0) { |
||
| 100 | $iGID = filter_var($_REQUEST['gid'], FILTER_SANITIZE_NUMBER_INT); |
||
| 101 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 102 | $querybuilder |
||
| 103 | ->insert('itemgroups_text') |
||
| 104 | ->setValue('itmgt_pid', '?') |
||
| 105 | ->setValue('itmgt_lang', '?') |
||
| 106 | ->setParameter(0, $iGID) |
||
| 107 | ->setParameter(1, HelperConfig::$lang) |
||
| 108 | ; |
||
| 109 | $querybuilder->execute(); |
||
| 110 | \HaaseIT\HCSF\Helper::redirectToPage('/_admin/itemgroupadmin.html?gid='.$iGID.'&action=editgroup'); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'editgroup') { |
||
| 115 | if (isset($_REQUEST['do']) && $_REQUEST['do'] === 'true') { |
||
| 116 | $this->P->cb_customdata['updatestatus'] = $this->updateGroup(); |
||
| 117 | } |
||
| 118 | |||
| 119 | $iGID = filter_var($_REQUEST['gid'], FILTER_SANITIZE_NUMBER_INT); |
||
| 120 | $aGroup = $this->getItemgroups($iGID); |
||
| 121 | if (isset($_REQUEST['added'])) { |
||
| 122 | $this->P->cb_customdata['groupjustadded'] = true; |
||
| 123 | } |
||
| 124 | $this->P->cb_customdata['showform'] = 'edit'; |
||
| 125 | $this->P->cb_customdata['group'] = $this->prepareGroup('edit', $aGroup[0]); |
||
| 126 | } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'addgroup') { |
||
| 127 | $aErr = []; |
||
| 128 | if (isset($_REQUEST['do']) && $_REQUEST['do'] === 'true') { |
||
| 129 | $sName = filter_var($_REQUEST['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
| 130 | $sGNo = filter_var($_REQUEST['no'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
| 131 | $sImg = filter_var($_REQUEST['img'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
| 132 | |||
| 133 | if (strlen($sName) < 3) { |
||
| 134 | $aErr['nametooshort'] = true; |
||
| 135 | } |
||
| 136 | if (strlen($sGNo) < 3) { |
||
| 137 | $aErr['grouptooshort'] = true; |
||
| 138 | } |
||
| 139 | if (count($aErr) == 0) { |
||
| 140 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 141 | $querybuilder |
||
| 142 | ->select('itmg_no') |
||
| 143 | ->from('itemgroups_base') |
||
| 144 | ->where('itmg_no = ?') |
||
| 145 | ->setParameter(0, $sGNo) |
||
| 146 | ; |
||
| 147 | $stmt = $querybuilder->execute(); |
||
| 148 | |||
| 149 | if ($stmt->rowCount() > 0) { |
||
| 150 | $aErr['duplicateno'] = true; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | if (count($aErr) === 0) { |
||
| 154 | $querybuilder = $this->dbal->createQueryBuilder(); |
||
| 155 | $querybuilder |
||
| 156 | ->insert('itemgroups_base') |
||
| 157 | ->setValue('itmg_name', '?') |
||
| 158 | ->setValue('itmg_no', '?') |
||
| 159 | ->setValue('itmg_img', '?') |
||
| 160 | ->setParameter(0, $sName) |
||
| 161 | ->setParameter(1, $sGNo) |
||
| 162 | ->setParameter(2, $sImg) |
||
| 163 | ; |
||
| 164 | $querybuilder->execute(); |
||
| 165 | $iLastInsertID = $this->dbal->lastInsertId(); |
||
| 166 | \HaaseIT\HCSF\Helper::redirectToPage('/_admin/itemgroupadmin.html?action=editgroup&added&gid='.$iLastInsertID); |
||
| 167 | View Code Duplication | } else { |
|
| 168 | $this->P->cb_customdata['err'] = $aErr; |
||
| 169 | $this->P->cb_customdata['showform'] = 'add'; |
||
| 170 | $this->P->cb_customdata['group'] = $this->prepareGroup('add'); |
||
| 171 | } |
||
| 172 | View Code Duplication | } else { |
|
| 173 | $this->P->cb_customdata['showform'] = 'add'; |
||
| 174 | $this->P->cb_customdata['group'] = $this->prepareGroup('add'); |
||
| 175 | } |
||
| 176 | } else { |
||
| 177 | if (!$return .= $this->showItemgroups($this->getItemgroups(''))) { |
||
| 178 | $this->P->cb_customdata['err']['nogroupsavaliable'] = true; |
||
| 179 | } |
||
| 180 | } |
||
| 181 | $this->P->oPayload->cl_html = $return; |
||
| 182 | } |
||
| 183 | |||
| 332 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: