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