Conditions | 22 |
Paths | 88 |
Total Lines | 105 |
Code Lines | 80 |
Lines | 9 |
Ratio | 8.57 % |
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 |
||
53 | public function preparePage() |
||
54 | { |
||
55 | $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
||
56 | $this->P->cb_pagetype = 'content'; |
||
57 | $this->P->cb_subnav = 'admin'; |
||
58 | |||
59 | $this->P->cb_customcontenttemplate = 'shop/itemgroupadmin'; |
||
60 | |||
61 | $return = ''; |
||
62 | if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'insert_lang') { |
||
63 | $sql = 'SELECT itmg_id FROM itemgroups_base WHERE itmg_id = :gid'; |
||
64 | $hResult = $this->db->prepare($sql); |
||
65 | $hResult->bindValue(':gid', $_REQUEST['gid']); |
||
66 | $hResult->execute(); |
||
67 | $iNumRowsBasis = $hResult->rowCount(); |
||
68 | |||
69 | $sql = 'SELECT itmgt_id FROM itemgroups_text WHERE itmgt_pid = :gid AND itmgt_lang = :lang'; |
||
70 | $hResult = $this->db->prepare($sql); |
||
71 | $hResult->bindValue(':gid', $_REQUEST['gid']); |
||
72 | $hResult->bindValue(':lang', HelperConfig::$lang); |
||
73 | $hResult->execute(); |
||
74 | $iNumRowsLang = $hResult->rowCount(); |
||
75 | |||
76 | if ($iNumRowsBasis == 1 && $iNumRowsLang == 0) { |
||
77 | $iGID = filter_var($_REQUEST['gid'], FILTER_SANITIZE_NUMBER_INT); |
||
78 | $aData = [ |
||
79 | 'itmgt_pid' => $iGID, |
||
80 | 'itmgt_lang' => HelperConfig::$lang, |
||
81 | ]; |
||
82 | $sql = DBTools::buildPSInsertQuery($aData, 'itemgroups_text'); |
||
83 | $hResult = $this->db->prepare($sql); |
||
84 | foreach ($aData as $sKey => $sValue) { |
||
85 | $hResult->bindValue(':'.$sKey, $sValue); |
||
86 | } |
||
87 | $hResult->execute(); |
||
88 | \HaaseIT\HCSF\Helper::redirectToPage('/_admin/itemgroupadmin.html?gid='.$iGID.'&action=editgroup'); |
||
89 | } |
||
90 | } |
||
91 | |||
92 | if (isset($_REQUEST['action']) && $_REQUEST['action'] === 'editgroup') { |
||
93 | if (isset($_REQUEST['do']) && $_REQUEST['do'] === 'true') { |
||
94 | $this->P->cb_customdata['updatestatus'] = $this->admin_updateGroup(\HaaseIT\HCSF\Helper::getPurifier('itemgroup')); |
||
95 | } |
||
96 | |||
97 | $iGID = filter_var($_REQUEST['gid'], FILTER_SANITIZE_NUMBER_INT); |
||
98 | $aGroup = $this->admin_getItemgroups($iGID); |
||
99 | if (isset($_REQUEST['added'])) { |
||
100 | $this->P->cb_customdata['groupjustadded'] = true; |
||
101 | } |
||
102 | $this->P->cb_customdata['showform'] = 'edit'; |
||
103 | $this->P->cb_customdata['group'] = $this->admin_prepareGroup('edit', $aGroup[0]); |
||
104 | } elseif (isset($_REQUEST['action']) && $_REQUEST['action'] === 'addgroup') { |
||
105 | $aErr = []; |
||
106 | if (isset($_REQUEST['do']) && $_REQUEST['do'] === 'true') { |
||
107 | $sName = filter_var($_REQUEST['name'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
108 | $sGNo = filter_var($_REQUEST['no'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
109 | $sImg = filter_var($_REQUEST['img'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
||
110 | |||
111 | if (strlen($sName) < 3) { |
||
112 | $aErr['nametooshort'] = true; |
||
113 | } |
||
114 | if (strlen($sGNo) < 3) { |
||
115 | $aErr['grouptooshort'] = true; |
||
116 | } |
||
117 | if (count($aErr) == 0) { |
||
118 | $sql = 'SELECT itmg_no FROM itemgroups_base WHERE itmg_no = :no'; |
||
119 | $hResult = $this->db->prepare($sql); |
||
120 | $hResult->bindValue(':no', $sGNo); |
||
121 | $hResult->execute(); |
||
122 | if ($hResult->rowCount() > 0) { |
||
123 | $aErr['duplicateno'] = true; |
||
124 | } |
||
125 | } |
||
126 | if (count($aErr) == 0) { |
||
127 | $aData = [ |
||
128 | 'itmg_name' => $sName, |
||
129 | 'itmg_no' => $sGNo, |
||
130 | 'itmg_img' => $sImg, |
||
131 | ]; |
||
132 | $sql = DBTools::buildPSInsertQuery($aData, 'itemgroups_base'); |
||
133 | $hResult = $this->db->prepare($sql); |
||
134 | foreach ($aData as $sKey => $sValue) { |
||
135 | $hResult->bindValue(':'.$sKey, $sValue); |
||
136 | } |
||
137 | $hResult->execute(); |
||
138 | $iLastInsertID = $this->db->lastInsertId(); |
||
139 | \HaaseIT\HCSF\Helper::redirectToPage('/_admin/itemgroupadmin.html?action=editgroup&added&gid='.$iLastInsertID)); |
||
140 | } else { |
||
141 | $this->P->cb_customdata['err'] = $aErr; |
||
142 | $this->P->cb_customdata['showform'] = 'add'; |
||
143 | $this->P->cb_customdata['group'] = $this->admin_prepareGroup('add'); |
||
144 | } |
||
145 | } else { |
||
146 | $this->P->cb_customdata['showform'] = 'add'; |
||
147 | $this->P->cb_customdata['group'] = $this->admin_prepareGroup('add'); |
||
148 | } |
||
149 | } else { |
||
150 | if (!$return .= $this->admin_showItemgroups($this->admin_getItemgroups(''))) { |
||
151 | $this->P->cb_customdata['err']['nogroupsavaliable'] = true; |
||
152 | } |
||
153 | } |
||
154 | $this->P->oPayload->cl_html = $return; |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * @param $purifier |
||
291 | } |